Saving Code snippets

If you want to save some code snippets for future use or for sharing to someone, use Gist from GitHub. Looks like a pretty useful tool, I can’t believe I’ve never used it. Think of it as an instant version control.

All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.

Its like pastebin, but does way more. You could write articles and people can comment on it.

BTW, I read about Gist from this page http://corner.squareup.com/2013/03/puzzle-square-root.html. It is a Java puzzle to find the square root of a number without even looking at it. I am not sure if I am going to attempt it.

Posted in Code Snippets, Programming, Tips & Tricks | Tagged , , | Leave a comment

Internet Explorer HTTPS download issue

In a recent Spring Webflow project, I encountered an issue where an exported file (PDF, Excel, CSV) was not getting downloaded in IE8, but was working fine in other standard browsers.

Problem :

When a document is downloaded from an HTTPS url, it fails in IE8 and below, with the following message or similar.

Internet Explorer was unable to open this site. The requested site is either unavailable or cannot be found. Please try again later.

Cause :

The server sends header parameters to prevent caching, like "Cache-control:no-store" or "Cache-control:no-cache" or "Pragma:no-cache". A bug in IE prevents the file from being downloaded.

Spring MVC sets these headers by default for all dynamic content.

Other causes and workarounds: http://support.microsoft.com/kb/812935, http://support.microsoft.com/kb/812935

Fix :

Remove the headers specified above. If you are not able to remove those headers, change to alternate values. These are the changes I did.

response.setHeader(“Pragma”, “public”);
response.setHeader(“Cache-control”, “private”);

other options…

1) Add an Filter in Tomcat or the Application to look for a predefined set of content-types and remove the cache headers. This wasn’t a good solution because the content-types could change later.  At this point, the headers are already set and cannot be modified, requiring a wrapper for the ServletResponse object.

2) Update to IE9 or apply Hotfix.

3) Some Spring wizardry to disable cache headers for the required Views or Flows.

Note: In Spring(3.X), the cache headers are set in WebContentGenerator based on useCacheControlHeader and useCacheControlNoStore properties. However, Pragma header is set if cacheSeconds is zero regardless of other properties. WebFlow FlowHandlerAdapter sets cacheSeconds to zero by default.

Posted in Java, Programming, Tips & Tricks | Tagged , , , , , , , , , , , , , , , | Leave a comment

Auto submit form on page load

This is a jsp page which auto submits a POST request to the given url.

<body onload="javascript:document.form.submit();">
<form name="form" action="<%=request.getAttribute("url") %>" method="post">
<input type="hidden" name="username" value="<%=request.getAttribute("user") %>">
<input type="hidden" name="password" value="<%=request.getAttribute("password") %>">
</form>
</body>

The servlet code for forwarding to this jsp.

req.setAttribute("user", user);
req.setAttribute("password", password);
req.setAttribute("url", url);
req.getServletContext().getRequestDispatcher("/redirect.jsp").forward(req, resp);

Posted in Code Snippets, Java, Programming, Tips & Tricks | Tagged , , , , , , | Leave a comment

El-cheapo Softbox.

I’ve always wanted to buy build a softbox for my macros and portraits.

Here is what I ended up with.

Here is what I started with.

1. Some kind of Umbrella from the dollar store

2. Car sunshade again from dollar store.

3. Old polaroid camera

4. Broken camera flash.

5. Strobe tube.

Horseshoe Xenon Strobe Tube from http://www.goldmine-elec-products.com/prodinfo.asp?number=G1034

and of course a lot of hot-glue and tape.

I was planning to use the old camera flash and use its guts to power the soft-box. Things didn’t go well with the part where I tried to hook up the hot-shoe to the flash PCB. Somehow I managed to fry the circuit by short-circuiting the capacitor. What I’d left with was the old Polaroid camera which I knew had a pretty powerful flash. Disassembling the camera was not easy. I had to break it with a hammer at one point. Amazingly, most of the camera was low tech except for the strobe circuit. Actually that was the only part of the camera with a PCB.

The painful part was figuring out the pinout of the flash circuit. It took me a few days to get it right. In the process, I had to disable the auto exposure feature, making it a fixed power strobe. I would like to figure out hacking the auto mode one day.

The Polaroid 600 camera is powered by a battery built into the film cartridge. I used a 6v NiCad battery to power the circuit.

In an attempt to power the light output, I replaced the stock xenon tube with a much bigger U shaped tube I had bought earlier for a similar project.

All worked fine and it was time to mod the umbrella. The sunshade was cut into pieces to fit the umbrella and hot glued into place. Then it was a matter of putting everything together. You can see I used a piece of wooden stick to hold the tube in place. wood is reasonably non-conductive :)

I used paper towels as diffuser.

The strobe is hooked up to the camera using the hot shoe piece from the broken camera flash. I need to get a better wire for it or make it wireless(I’ve a bunch of 433mhz transmitters and receivers somewhere). Good thing the trigger circuit is low voltage.

Some of the pictures were taken using the softbox. I’ll add more if I actually use this.

Posted in Hacks, Photography | Leave a comment

Rigol DS1052E – 50MHz Digital Oscilloscope

Nothing much to say about this, Dave already said everything you ever wanted to know in the video below. This scope seems to be well built and is well worth the price. What I found most interesting about this scope is that it manages to get 1GS/s by running 10 ADCs sequentially (Don’t know if this is common in DSOs).

http://www.eevblog.com/2009/04/05/full-review-of-the-rigol-ds1052e/

Actually watching the above video helped me decide. I wanted to write a review about it but haven’t used it enough to make any useful comments. Its still the best DSO I have ever used.

Apparently this can be modified to 100mhz scope, but I don’t have the need or guts to do it yet. http://www.eevblog.com/2010/03/31/eevblog-70-turn-your-rigol-ds1052e-oscilloscope-into-a-100mhz-ds1102e/

Posted in Toys | Leave a comment