My Homebuilt HeNe Laser Lamp

June 20th, 2009

When I was in middle school, I read all about Light Amplification by Stimulated Emissions of Radiation (lasers). I saved up almost $100 for a crappy laser pointer (now they are practically giveaways). One book, the Laser Cookbook, was all about projects you could do with lasers. One, which every middle-schooler would love, is making a laser gun (a harmless one, but cool nonetheless). But it required a Helium Neon laser tube, and some fancy circuitry for a power supply and a big-ole hip holstered battery pack. But after spending all my lawn mowing money on that crappy laser pointer I couldn’t afford to build the laser gun. Thus the interest slowly faded away…

Many years later, I found a Desktop Helium Neon Laser Lamp Build tutorial on Hack N Mod, and BAM! I got so excited! I new where to get most of the parts, but not the laser. After searching the webs, I found Meredith Instruments which had good information and the parts I needed. But the everything there new, and more money than I wanted to spend. Searching the internets some more, I kept seeings “Sam’s Laser FAQ.” So I read that to learn how to actually put a laser and power supply together. Then I found his HeNe Laser Kit 2 and saw the price! It was just what I needed, and it had those brackets I could not find anywhere.

So I bought one of those kits, went to Hastings Plastics Co. and got my acrylic mirror sheets cut so I could mount the laser. I also got acyclic solvent from them to glue the pieces together. I lined up the laser on the acrylic and drilled some holes to mount the brackets. Glued the pieces together. Soldered the switch to the power supply. Connected the project box base to the mirrored stand. Done.

I made a complete parts list of all the parts I used and where I got them. I pretty much copied the Hank N Mod tutorial. Though my wall power adapter came already connected to the power supply. Finally, here is the pic of my HeNe Laser Lamp:

HeNe Laser Lamp

Now where the heck do I put it?

AIR/Flex URLRequest: Sending Authentication Headers

June 17th, 2009

If the request requires authentication and URLRequest.authenticate is set to true (the default) the operating systems login window will popup asking for credentials. These will be automatically sent in the request. To manually set the username and password there are a few ways:

URL Request Defaults:

URLRequestDefaults.setLoginCredentialsForHost("www.domain.com",username,password);

Headers:

var encAuth:Base64Encoder = new Base64Encoder();
encAuth.encode(username+":"+password);
var header:URLRequestHeader = new URLRequestHeader("Authorization","Basic "+ encAuth.toString() );
var request:URLRequest = new URLRequest(url);
request.requestHeaders.push(header);

Under both ways, once a successful login occurs the credentials are remembered while the application is open and the user is not asked for username and password again.

Tamiya Bull Dozer Kit

June 9th, 2009

So a friend sent me a link to a NY Time article about working with your hands and how sweet it is. And I totally agree.  Growing up I used to build model cars, planes, robots, X-Wings, TIE fighter’s, etc.  Lego’s too.  We had nice garage full of tools, and I would play back there.  During college I managed to rewire a 1966 Ford Mustang.  Got it running.  That was so awesome.

After I got my engineering degree, I got a job and sit in front of a computer and program all day.  Its almost, but not quite, entirely unlike working with your hands.  You type out code with your hands to create a virtual machine.  I miss making real machines.  Though, after I make the models or robot kits, I never did anything with it.  Usually just threw it away, because the process of putting real physical objects together to form another physical object was the most fun.  So over the weekend I went to Fry’s and got a Tamiya Bull Dozer kit.  Its a very easy, basic kit.  There is a wired remote control that sends power to three little motors. Moves the arm up and down and the tracks forward or backward.  Here’s a little video of it in action for my Pop.

Get the Flash Player to see this content.

Mac OS X Leopard and Windows XP File Sharing

June 6th, 2009

I have a Windows XP Media Center 2005 computer, a MacBook Pro and a few other Windows and Mac computers stroll through my network from time to time. I have my Media Center PC streaming media to the XBOX 360, file server, printer etc. I had the Media Center machine before the MacBook Pro. So when I got my MacBook Pro, and hooked it into my network I was suprised that all my file shares were automatically picked up and I could read my movies and print, all as a Guest. Which is exactly how I wanted it. Login to change, but anyone can view a movie, listen to music, and print.

Then the Media Center PC mother board failed! So I got a new AMD Athlon 64 LE (45w cool-and-quiet, and yeah, it runs very cool and very quiet) and reinstalled. I setup my shares again, but this time I turned OFF simple file sharing.

I go to my MBP and connect to the MC PC. I try as guest. But I got this message:

“The file server does not allow Guest access.”

Huh? So I enable the guest account, which I do not remember having to enable before. Reboot. Try to connect again. Same error message: “The file server does not allow Guest access.” WTF?! And the other Windows machine (Windows Vista) could not print without loging in. Gah!

So I googled around, played with my Mac samba settings. Deleted my networking settings on my Mac. Tripple checked my shared settings on my PC. So I went back to the basics. Reading one Microsoft KB how to setup Windows XP file sharing. There it was, simple file sharing. A light bulb came on. So I re-enabled simple file sharing (My Computer->Tools->Folder Options…->View->Advanced settings:->User simple file sharing (Recommended)).

And it all worked!  Reading my media shares, printing as guest! Even from the Vista machine! I know there is some security risks leaving it so open, but I keep my private data separate.

Yosemite – El Capitan Swinging Climber

May 24th, 2009

Just got back from Yosemite, and took some pictures of climbers headed up El Capitan. It has a 10 second intro, with a red circle showing how high the swinging climber is. After the intro is a zoomed sequence of 10 pictures showing the climber swinging across the face of the mountain trying to grab a ledge. The climber did make it after at least 1 hour of swinging. Click the link for the video.

El Cap Swinging Climber

Or if you prefer, the image sequence.

BreakTimer v2.0 – Update

May 13th, 2009

I made some major updates to BreakTimer. It now minimizes to the dock/system tray, with a nice icon that counts down. Also has icon menu options so BreakTimer can be started, or stopped from the dock/system tray, and well as toggle the repeat. O, I added a stop feature so you can stop the timer rather than close the application. I don’t see a point in pause, since if you pause it, you are most likely taking a break so just restart it.

Also fixed a few bugs with the break window not grabbing focus and moving to the front on a Mac. Also a little instruction slides down to let you know Escape closes the break window. Hope you enjoy!

Download at the BreaTimer Page.

BreakTimer – an AIR app to remind you to take a break from the computer

May 4th, 2009

My current career path has me sittign on my ass infront of a computer for most of the daylight hours. I have back issues, and sometimes I get too involved in my work and forget to move.  Combine that with years of volleyball and tight muscles I got a herniated disc.  So I made a simple AIR application that will block out the screen and tell you to take a break after a proscribed period of time (30 minutes).  This can be set from 0 to 180 minutes (no person should be sitting for 180 minutes straight though!).  If you have multiple monitores it will block all your monitors.

The source is there for you to tweak, right click on the app and view source.

Google App Engine and dynamic Django Forms

January 28th, 2009

Let me define dynamic form: a form that can have 0 to x number of entries for a field. For example a form that contains a list of items, like a grocery list. Its part of the same form but can have more than one entry. In PHP, they can be grouped by appending “[]” to their name attribute, and PHP stores them the $_POST variable as array (i.e. $_POST['list'][0]). I am working a project using Google App Engine, which uses Django forms, and I needed a dynamic form (list).  I found this can be done using the get_all() function of the self.request object (i.e. self.request.get_all(‘list’)) will return a list object.

Cool! But how do I use that with the Django form model with this list?  Make a list of form models. Loop through the posted list, create a form object with that data, append it to the form list, check if its valid and repeat.  If there was an error, just send the form list to the template, and loop through the forms displaying them with error messages. Else, the entire form is valid, save it to the data object.  Here is some code:

#main.py

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.db import djangoforms

class Groceries(db.Model):
	quantity = db.IntegerProperty()
	name = db.StringProperty(required=True)

class GroceryForm(djangoforms.ModelForm):
	class Meta:
		model = Groceries

class MainHandler(webapp.RequestHandler):
	def get(self):
		groceryform = GroceryForm()
		values = {'groceriesformlist': [groceryform]}
		self.response.out.write(template.render('main.html',values))
	def post(self):
		postedQuantities = self.request.get_all('quantity')
		postedNames = self.request.get_all('name')
		groceriesList = []
		allGroceriesValid = True;
		n = 0;
		for i in self.request.get_all('quantity'):
			groc = GroceryForm(data={'quantity':postedQuantities[n],'name':postedNames[n]})
			allIngredientsValid = allIngredientsValid and groc.is_valid()
			groceriesList.append(groc)
			n += 1
		if allGroceriesValid:
			for grocerydata in groceriesList:
				grocery = grocerydata.save(commit=False)
				#do something with data
				grocery.put()
			self.redirect('/')
		else:
			values = {'groceriesformlist': groceriesList}
			self.response.out.write(template.render('main.html',values))
def main():
	application = webapp.WSGIApplication([('/', MainHandler)],debug=True)
	wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
	main()

The commit=False is useful when you do not want to save the data right away, like some other variable manipulation. Then there is the template file. There are numerous ways to output the form, it even has a built in table or paragraph method. If you wanted to just use the default table method to output the form, with errors, simple use <table>{{groceryform}}</table> (the output omits the table declartions, just the rows and columns) and your are done. I like a little more control, so to output the erros: {{ groceryform.quanity.errors }} and then output the input tag: {{groceryform.quantity}. Here is the template file, main.html:

<h3 class="form_headers">Groceries</h3>
<ol id="directions_form">
	{% for groceryform in groceriesformlist %}
		<li>{{ groceryform.quanity.errors }}{{groceryform.quantity}}{{ groceryform.name.errors }}{{groceryform.name}}</li>
	{% endfor %}
</ol>
<input type="button" value="+" id="add_btn" onclick="AddLi(this.previousSibling.previousSibling)" />

You also need to toss in some javascript for adding new grocery items:

function AddDirLi(ol)
{
	var li = ol.firstChild.nextSibling.cloneNode(true);
	ol.appendChild(li);
}

There are many ways to accomplish this, with AJAX or just posting items one at a time. But my project actually had a few sections of this nature and it this method seemed to work the best. I hope that made sense. The next post will cover Using Relationships with the Google App Engine Datastore. Creating and storing multiple grocery lists. The grocery list would be the the parent to many grocery items.

Reading and Writing Files in AIR – using a simple text editor

January 26th, 2009

Monstagon asked me if I ever saved or opened files in Adobe AIR. Yes. I have. I made a simple text editor to demonstrate the basics of reading files in (letting the user browse for a file on their machine) and writing a save (also letting the user specify where to save the new file).

Some issues I encountered with making the text editor were the different FileModes (READ, WRITE, UPDATE, and APPEND). UPDATE and APPEND basically just add whatever you write to the FileStream to the end of the file. WRITE deletes the destination and writes only what is sent to the FileStream. READ only opens the file for reading. After erasing some files accidentally by opening it with WRITE, I realized for the text editor to work, first READ the file in, close the FileStream. When the user hits Save, open the file in WRITE mode, and send the contents of the editor to the FileStream.

I also had to removeEventListener from the FileStream because it was listening for two Event.SELECT’s: user selects which file to open, and user selects where to save. This was throwing errors when the user selects where to save and the program tries to open a file that doesn’t exist.

If you just want to know how to read a file, look at private function Open() and follow the code. For writing, private function Save(). Note that in ActionScript, its all about event listeners. So reading the file contents into the TextArea is 3 function, because we have to wait until each step is ready. Else, if you don’t setup the Event Listeners nothing will happen.

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.events.FileEvent;
private var stream:FileStream;
private var file:File = File.documentsDirectory;
private var newFile:Boolean = true;
private function New():void
{
	newFile = true;
	editor.text = '';
}
private function Open():void
{
	try
	{
	    file.browseForOpen("Open");
	    file.addEventListener(Event.SELECT, LoadFile);
	}
	catch (error:Error)
	{
	    trace("Failed:", error.message);
	}
}
private function LoadFile(evt:Event):void
{
	file.removeEventListener(Event.SELECT, LoadFile);
	file = evt.currentTarget as File;
	stream = new FileStream();
	stream.addEventListener(Event.COMPLETE, ReadFile);
	stream.openAsync(file,FileMode.READ);
}
private function ReadFile(evt:Event):void
{
	stream.removeEventListener(Event.COMPLETE,ReadFile);
	var str:String = stream.readUTFBytes(stream.bytesAvailable);
	editor.text = str;
	newFile = false;
	stream.close();
}
private function Save():void
{
	if(!newFile)
	{
		stream = new FileStream();
		stream.openAsync(file,FileMode.WRITE);
		stream.writeUTFBytes(editor.text);
		stream.close();
	}else
	{
		file.browseForSave("Save");
		file.addEventListener(Event.SELECT, SaveFile);
	}
}
private function SaveFile(evt:Event):void
{
	file.removeEventListener(Event.SELECT, SaveFile);
	var file:File = evt.currentTarget as File;
	stream = new FileStream();
	stream.openAsync(file,FileMode.WRITE);
	stream.writeUTFBytes(editor.text);
	stream.close();
	newFile = false;
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:HBox>
	<mx:Button label="New" click="New();" />
	<mx:Button label="Open" click="Open();" />
	<mx:Button label="Save" click="Save();" />
</mx:HBox>
	<mx:TextArea id="editor" width="100%" height="100%" />
</mx:VBox>
</mx:WindowedApplication>