Thursday, February 28, 2008

Tip of the Day - Toss Free Batteries

And by toss, I mean place carefully in your battery recycling bin.

By free batteries, I mean the generic brand AA and AAA batteries you get prepackaged with products. The number of times I've had those cheapo batteries leak inside my tools/toys/etc is ridiculous.

Go buy a megapack of Duracells or good brand rechargeables. It's worth it.

Tuesday, February 26, 2008

Joule Thief

Here's a circuit I put together Sunday night. It's real simple and is designed to drain the last remains of power out of dead batteries.

It's impressive because you can run a 3V LED off of a battery giving something more along the lines of 1V. (I'm measuring 0.91V right now)

• The cell is a dead battery, in my case a AAA.
• The pair of inductors are oppositely wound 20 turn magnet wire on a toroid I pulled from a power supply.
• The transistor is a 2N2222. The documentation I read said to use a BC547, but they're both NPN AF small signal transistors, so since I have 2N2222s, those are what I use.
• The LED is a 3V high intensity red that I picked up at a local bulk electronics store last year for \$10 for 40.

I've been trying to get some readings from the circuit, but my volt-ohm meter can only give me so much. I really need to figure out who to be friends with to get access to an oscilloscope.
• The input voltage has run from 0.4V - 1.0V and runs fairly bright.
• The output voltage measures the same as the input voltage, probably due to the duty-cycle. The volt meter measures the average voltage of a length of time, but this circuit probably runs a higher voltage a fraction of the time (50% duty cycle would be 1/2 the time). This does indicate that the output voltage and duty cycle are inversely proportional, which makes sense. (Shouldn't be able to make power out of nothing!)
• The frequency measured on the output voltage was anywhere from 300 to 80,000 hertz, which pretty much means it doesn't mean anything.
So now that I've failed to make any meaningful measurements, other than that V(output)*DutyCycle(output) = V(input) * 100%, I'm going to venture a guess as to what is going on.

DISCLAIMER: I'm a freshmen level Mechanical Engineer. I've spent some time studying electrical circuits, but not enough to really make any kind of analysis of this. Everything from here on is total guesswork.

So I think the battery charges the inductor from the positive terminal, generating a magnetic field around the windings. Once the charge travels through the left winding and the 1k resistor, it will open the transistor and ground the right winding. This will cause the right field to collapse, which will in turn pull the left field down with it, creating the higher voltage (V(out) = V(right) + V(left)). As the collapsing right field pulls down the left field, this closes the transistor and shunts this energy into the LED instead, so it lights. As the right winding drains, the battery charges the left winding again and the cycle repeats.

Monday, February 25, 2008

Ninja Warrior

Did anyone else see the episode of the new season of Ninja Warrior tonight? The new stages are intense.

For those who don't know, Ninja Warrior is just an obstacle course show with 4 stages of increasing difficulty and has had only one winner in the last 7 years. It's entertaining just from the shear ridiculousness of some of the challenges.

Sunday, February 17, 2008

Prime Sieve

A prime sieve is a way to find prime numbers faster than just testing every number to see if it is divisible.

This is done by remembering all the prime numbers found already, and only testing those, since if a number is divisible by 4, it's divisible by 2. Furthermore, you only need to test numbers up to the square root of the number you're testing.

Example:
2 is prime.
sqrt(3) is less than 2, it's prime too.
sqrt(4) = 2, not prime
sqrt(5) < 3; 5 is not divisible by 2, prime (2 3 5)
sqrt(6) < 3; divisible by 2, not prime.
sqrt(7) < 3; 7 not divisible by 2, prime.

So now you can see that testing if 7 is prime only takes a square root function and one division by 2, instead of testing 7 vs 2, 3, 4, 5, and 6. This technique really starts paying off once you get into larger numbers and really start skipping more numbers.

I've used this approach multiple times in Project Euler, since many of the problems deal with prime numbers.

Cows in Davis

Here is some pictures I finally loaded off my camera. It just wouldn't be Davis without some cows...

Finally got around to taking some pictures of my new aquarium setup. I took these with my MP3 player so the quality isn't great, but you get the idea.

Nice ~1.5 Gallon Teardrop vase I got at Target last week. There's two pieces of Elodea, one floating and one anchored to complement the plastic plants I already have.

Tolstoy the Betta
Shostakovitch the Gold Inca Apple Snail

Only one not pictured is my new Ghost Shrimp, Stalin, which understandably, doesn't photograph well (Being transparent and all).

I'll try and take a picture of Shostakovitch again when he's up and moving around. It's a real kick to watch him dig around in the rocks eating debris.

Saturday, February 16, 2008

Offline Cache Proxy

Here's a random idea from my notebook that I don't see myself implementing any time soon due to a lack of free time and energy, so I'll just throw it out there:

I want a small program that runs on your laptop, that you can then setup as the proxy for your browser, and saves all the web pages you visit when you're online. Each time you visit it while online, it will download it and present it to you, saving the new version.

This proxy wouldn't try and save you any bandwidth, but instead would let you visit all of the websites you've visited online offline. Then when I'm sitting in some lecture hall without wifi or on the train or in a car, I can browser through Wikipedia, assuming I'd visited the page before.

Misc extensions:
• Visit a special URL to edit the settings - ie proxy.settings
• You'll probably never access 98% of the cache, so as it is writing pages to disk, it can compress the crap out of them. (Along the lines of Mailinator)
• Limit the cache size to a preset number (ie 10GB). Phase out older pages based on size, last time visited, and visit frequency.
• Maybe try and have it save some bandwidth by not redownloading pictures for a day or something. I wouldn't want much more than this, I never want to have to worry about what the proxy is showing me is out-of-date.
• Prefetch links on certain domains like Wikipedia, so when you're offline you can visit more pages than you did online.

Friday, February 15, 2008

Project Euler

Project Euler is a fun way to kill an amazing amount of time, assuming that you're a computer programmer and enjoy challenging programming challenges.

As of now, there are 182 problems posted, with a new one posted every few weeks. Each problem is designed to be able to run in under a minute on average hardware, assuming you have a clever solution. One example of this is Problem 67. If you just do an exhaustive search of all the possible paths, it will take you longer than the age of the Earth, but with a smart algorithm I was able to solve it in three seconds.

Once you solve the problem, you gain access to a forum for each problem to trade tricks with everyone else who has solved the problem.

I've already solved problems 1 2 7 9 14 15 18 67 92
All of my solutions are in C, but some people solve them just using pencil and paper. Let me know in the comments if you've solved any PE problems.

Edit: I've started posting my solutions to the problems here.

Thursday, February 14, 2008

Tip of the Day - Press * to Skip the Wait

We all know the lovely lady who tells you that "you have reached the voice mailbox of ____, please leave a message." The secret is that you can press * and you'll be forwarded right to the beep to leave your message.

Now you'll have that much more time to talk to the girl ignoring your phone calls begging for her to call you back. (Not that I know that feeling...)

Duct Tape Roses

So it's Valentines Day. I even remembered to buy my girlfriend something nice. The thing that really surprised me was the traffic that Valentines day drove to my duct tape website.

The average visits per day was 21.3 visits/day. Over the last two days I've gotten more than a 100 hits, most of them to the page on making roses. I guess putting ads in last week was good timing on my part...

Tuesday, February 12, 2008

Tip of the Day - Do Your Homework on Colored Paper

This is a very clever little hack I use in math class all the time. During discussion when the TA is returning homework for the fortysomething people in the section, he just plops the stack of papers on the desk at the front of the room.

So if you do your homework on distinctive paper, be it green engineering paper or Hello Kitty, all you have to do is call out "Hey, someone grab the _____ paper for me!" and your homework magically floats out above the giant mass of people around the desk to you. Problem solved.

Convert ppm to jpeg

EDIT: So this solution is really really bad. Thanks to commenter Manuel, I've posted a much better solution here.

So last summer I bought a crazy cheapo camera at Rite Aid for \$20 to take with me to high risk locations like gallivanting down a creek or hanging out at the beach. The pictures from it are along the lines of low quality camera phone, but that's really about what I was looking for.

Long story short, support for it in Windows sucks. You have to install its own crappy little import utility and it doesn't work all right in Windows Vista, so I gave up on it for awhile. About a month ago, just for kicks I plugged it into my computer running Ubuntu Linux, and would you believe the standard photo manager program recognized it and imported all the pictures for me? Yay Linux.

The downside is that it saves pictures as .ppm files, which don't do me any good when trying to upload to Facebook since FB only takes .jpg, .png, and .gif. I found a utility pnmtojpeg that converts a .ppm file feed into its stdin into a jpeg put out its stdout. Example usage:
cat foo.ppm | pnmtojpeg > foo.jpg

That's all good and well, except I want to handle a dozen or two of these at a time. So I hacked together a pair of scripts to do it for me.
convert.sh:
#!/bin/bash
find \$1 -name *.ppm | xargs ./helper.sh

helper.sh:
#!/bin/bash
cat \$1 | pnmtojpeg > \$1.jpg

Usage:
./convert.sh /path/to/folder/of/pictures/

How this works is the find command in the first script lists every file in the path (given as argument number 1 to the script (\$1)) that matches the patter *.ppm. * is a wildcard which means any number of any characters. Which makes sense since any filename which ends with .ppm is going to be a .ppm, regardless of what the filename is before that. The xargs command reads in this list of .ppm files and calls helper.sh for each one.

The one thing that I didn't see an easy solution to was that the filenames came out as foo.ppm.jpg, which works, but isn't pretty.
Does anyone have any input on a more elegant way to do this? Both for doing it in one script and for trimming off the .ppm?

Sunday, February 10, 2008

Tip of the Day - Never Return Disposable Cameras

Unlike normal film cameras, disposables start with the film unwound and as you take pictures, they wind back into the cartridge. Once all the pictures are taken, the film is rolled up in a light safe case; there is no way you can ruin your pictures without trying.

There is tabs on the side of the camera, pop it open and take the film cartridge to the drug store. Drop it in a normal film development envelope and they process it like any other film.

Inside the camera is a PCB board with a really nice little 1.5V to 300V transformer buffered with a capacitor. I've had quite a bit of fun playing with these, either hooked up to the original xenon flash tube that came with the camera, or in other applications of 300V low amperage (thank god, I'd be dead by now if there was much umph behind these). Lighting up steel wool with 300V is pretty fun.

Saturday, February 9, 2008

Tip of the Day - Cloth Napkins

Over Winter break I was sitting in the living room working on my laptop while the rest of the family was watching Opera, and that day they happened to be talking about a bunch of small ways we can help save the environment.

One of the things they said was that if everyone used one less paper napkin a day, we'd save such and such million trees a year. My first reflex was to scoff: "I never use paper napkins!" Then I realized that at college, I use paper napkins every day with my meals in the Dinning Commons...

So at the beginning of this quarter, I brought a cloth napkin with me from home, and have been bring it to the DC with me for meals when I remember it. I haven't been perfect about it, but I'd say I've reduced my paper napkin consumption by 30%.

Bittorrent is not Illegal

This is a big pet-peeve of mine because of all of the (mis)information being spread by everyone and their mom. Time after time UC Davis staff told us about all the terrors of using Limewire and Bittorrent, from orientation to welcome week. Telling us about how the music industry is targeting University IP addresses and that X number of students got sued last year.

Then enter me, someone who actually uses Bittorrent for what it is designed for: content distribution.

Content distribution. Not file sharing, content distribution. Bittorrent requires that you goto a website a download a small .torrent file, then load it in your BT client and then it'll download the file. When used for file sharing, these websites where you download the .torrent become the point of failure, which is a feature. Content distribution means that indie content producers can distribute their content at significantly less cost.

If I make a movie, and then post the .torrent for it, there is nothing illegal about it. I created my own content, I own the copyright to it, and I choose to give it away to others using Bittorrent. Granted, I've never created a movie worth distributing on Bittorrent, but others do, and I download them.

Friday, February 8, 2008

Tip of the Day - Get Free Drinks

Last summer, my father and I went to a nice restaurant with some of our buddies. For once we had finally be together enough to call ahead and make reservations. When we got there though, they were swamped (partly why we made reservations) and didn't have a table ready for half an hour after when we had made our reservation for.

My dad jokingly asked for free drinks since we had to wait half an hour to get seated, and would you believe it, we got them. It probably helped that we still had a \$150 tab, but remember: it never hurts to ask.