Friday, March 05, 2010

March Madness Challenge - Day 5

For tonight's March madness I will be demonstrating a variation on the theme of storing your private key locally. This program will up the ante and store your username and password as a QRCode. This way only a few machines can compromise your accounts when you take a picture of your username/password for decryption. Inspired by the following super high security tech technology: SafeBerg Technology

A bit of preparation is required. I'm using the python library huBarcode. You will need to run some flavor of "git clone git://github.com/hudora/huBarcode.git" followed by python setup.py install. Last option: sudo easy_install huBarcode

This code would have worked brilliantly if not for this error:
IOError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/huBarcode-0.56p5-py2.4.egg/qrcode/qrcode_data/qrv1_0.dat'

And here is the code:



#
# Turn a username/password into a QRCode
#
#
import getopt
import sys
import getpass
import qrcode

#Describe usage
def usage():
print "-h, --help\n -v, --verbose\n -u, --username\n -p, --password\n -f, --filename\n"

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h:u:pvf:", ["help", "username=", "password", "filename"])
except getopt.GetoptError, err:
#print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
username = None
password = None
verbose = False
filename = "default.png"

for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-u", "--username"):
username = a
if verbose:
print "username: " + username
elif o in ("-p", "--password"):
password = getpass.getpass("Enter password: ")
if verbose:
print "password: " + password
elif o in ("-f", "--filename"):
filename = a;
if verbose:
print "filename: " + filename
else:
assert False, "unhandled option"
if username is None:
print "-u, --username was not given"
usage()
sys.exit(2)
if password is None:
print "-p, --password was not given"
usage()
sys.exit(2)


encoder = qrcode.QRCodeEncoder( username + "\n" + password)
print encoder.get_ascii()
encoder.save(filename, 3)

if __name__ == "__main__":
main()

Thursday, March 04, 2010

March Madness Challenge - Day 4

Kept thinking about yesterday's setTimeout and how to chain it into a a color show. Inspired the by the Trippy RGB Waves kit. I wanted to create a Javascript simulation of the rgb color show. The Trippy RGB Waves kit uses an array called lightTab to hold information about the hold time, fade time, and the rgb color values. So I took that array an implemented in Javascript. In order to display values I built a test page, test css, test Javascript. I ran out of time to write the fader. So I have a color show based on the lightTab array. setTimeout is used in a recursive fashion. The issues run into were needing to make sure the lightTab was global, and that an anonymous function was used to call the function in the site time out. Here's the example:

setTimeout("runShow(" + (i + 1) + ")", holdTime);
setTimeout(function () {runShow(i + 1);}, holdTime);

If I was executing more code or had more values in my function then anonymous function route is much easier to type, and less error prone. Other thing, I love jQuery, but none of my Javascript entries have used it. Sort of just checking out the plain old DOM and seeing what can be done.

Without further ado here is the html, css, and js.

test.html
====

====

rgb.css
====

====

rgb.js
====

====

Wednesday, March 03, 2010

March Madness Challenge - Day 3

Another long day, but I did come. up with something that I needed for another project. It turns out the closest thing Javascript has to sleep(ms) or delay(ms) is setTimeout. Which is nice but is tricky to use in a synchronous environment. So in terms of matching what happens on an AVR chip or an Arduino. It's time for a delay(ms) script.

setTimeout("showColor(red,green,blue)",holdTime);


function showColor(red, green, blue)
{
document.getElementById("leddisplay").style.backgroundColor="rgb(" + red + "," + green + "," + blue + ")";
}


Well not really. I wrote the delay function, but it's not the recommended technique. Why block all actions on a page waiting for one thing to happen. The above code is closer. But doesn't solve the key issues. The setTimeout needs to have values assigned for red, green, and blue for the showColor function. Additionally, this code requires a web page. I needed to upload that. I needed to assign an event listener, and lastly had to resolve an issue about setTimeout being inside a loop. The issue being the loop sets all the "setTimeout"s as quickly as possible, so all time outs occur almost in parallel. I could be wrong about that, but I did have some kind of issue. I needed to examine Javascript fader examples more closely, and I would have figured it out, but ran out of time.

Ok. I wrote a super quick brute force demonstration of the problem. This requires Firebug in order to run. Paste the following code into the Firebug console. Warning whatever web page you are viewing in firebug will go through some awful color contortions.

function showColor(red, green, blue)
{ document.body.style.backgroundColor="rgb(" + red + "," + green + "," + blue + ")";
console.log("Color set");
}
console.log("Start");
console.log('setTimeout("showColor(0,0,0)",10000);');
setTimeout("showColor(0,0,0)",10000);
console.log('setTimeout("showColor(10,10,10)",9000);');
setTimeout("showColor(10,10,10)",9000);
console.log('setTimeout("showColor(100,100,100)",8000);');
setTimeout("showColor(100,100,100)",8000);
console.log('setTimeout("showColor(200,200,200)",7000);');
setTimeout("showColor(200,200,200)",7000);
console.log('setTimeout("showColor(200,0,0)",6000);');
setTimeout("showColor(200,0,0)",6000);
console.log('setTimeout("showColor(100,0,0)",5000);');
setTimeout("showColor(100,0,0)",5000);
console.log('setTimeout("showColor(0,100,0)",4000);');
setTimeout("showColor(0,100,0)",4000);
console.log('setTimeout("showColor(0,100,100)",3000);');
setTimeout("showColor(0,100,100)",3000);
console.log("Done")


So nesting the setTimeout inside SetTimeout should be interesting. Onto the next challenge.

Tuesday, March 02, 2010

March Madness Challenge - Day 2

Ok. Time was a bit of challenge today. I wanted to learn more about getopt, and figure out how it differed from optparse. I definitely learned about some of those differences. So tonights program uses getpass to collect a username, password combination. This is pretty unoriginal, but it did help me learn about getopt. I would like to try variation on determining mandatory fields, optional fields, and fields in combination.


#
# Hello World Get Opt for Python
#
#
import getopt
import sys
import getpass

#Describe usage
def usage():
print "-h, --help\n -v, --verbose\n -u, --username\n -p, --password\n"

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h:u:pv", ["help", "username=", "password"])
except getopt.GetoptError, err:
#print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
username = None
password = None
verbose = False

for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-u", "--username"):
username = a
print "username: " + username
elif o in ("-p", "--password"):
password = getpass.getpass("Enter password: ")
print "password: " + password
else:
assert False, "unhandled option"

if __name__ == "__main__":
main()

Monday, March 01, 2010

March Madness Challenge - Day 1

Several of my partners in craziness at FUBAR Labs, the local New Jersey Hackerpsace. Have taken on March Madness. Write a program a day for a month. Well I'm jumping in on day one with a piece of code that solves one of PIAs I experience when trying to get the emails off of Google Calendar Events. Wish there was a feature that allowed you to make a group based off of an event. Anyway, the following code is how to get a list of guests from a Google Calendar event. Pop the list into an alert box, then cut and paste for your own use.
---
/*
* Get list of emails address from the guests invited to a Google event
*/
(function () {
var guests, emails;
//Handily there is class associated to each guest
guests = document.getElementsByClassName("guest");
emails = "";
//iterate the guests
for (var i in guests)
{
if (guests.hasOwnProperty(i))
{
//each guest name/email is the first child textContent of guest element
emails = emails + guests[i].childNodes[0].textContent + ",\n";
}
}
alert(emails);
})();
---
In order to run this you need to can run it in the Firebug console. Testing this, you need to create a Google Calendar Event add a few people to it. Find an old event with people in the guest list.

Another way to run this would be as a Greasemonkey script. Hey, that might be a good project for tomorrow.

I did discover the source code for Google Hosted applications is not quite the same as it's standard gmail offerings. To run this in a hosted environment you would need to use the following to select the guests:

(function () {
var guests, emails, guest, tmp;
guests = document.getElementsByClassName("ep-gl-guest");
emails = "";
guest = "";
tmp = "";

for ( var i in guests)
{
if (guests.hasOwnProperty(i))
{
guest = guests[i].id;
tmp = guest.split(":i");
emails = emails + tmp[1] + ",\n";
}
}
alert(emails);
})();
//Final Note: Not Happy with editor at Blogger.com

Sunday, December 20, 2009

Bug in the fire


Bug in the fire
Originally uploaded by flirianders.

Played around with a glue gun, and an led at the Fubarlabs Hackathon. Ended up with atmega168 powered LED that lit up chilled hot glue, and formed a fire breathing bug.

Monday, June 04, 2007

Iron Man Kills Dr. Lucky's dog


Iron Man Kills Dr. Lucky's dog
Originally uploaded by flirianders.

Kill Dr. Lucky is a great Cheapass game. We scavenged both the Marvel Monopoly and the classic Monopoly pieces for this game. The variation we played was Kill Dr. Lucky and his dog. I as Iron man finally killed Dr. Lucky's dog. I was so satisfied with the moment, it had to have a photo. I no longer remember the final outcome, but that pesky dog was finally eliminated.