Programming


Over the last few days I have been Tweeting photos with location but I am unhappy with how the maps are displayed.  So I made a bookmarklet to extract the map links.

Grab the GPSCoords bookmarklet by following the link then dragging and dropping it from there.

Today I wanted to see all the URLs I had visited in Firefox. I tell it keep my history for a very long time. I grow tired of bookmarking and managing those bookmars. I want to be able to do something like say: “What was that site I visited a few days ago that sold Widget X”.

Firefox3 stores its history in a file called places.sqlite which is in sqlite3 format. So with sqlite3 installed this is the command I used to export my history to a text file.

echo "SELECT datetime(moz_historyvisits.visit_date/1000000,'unixepoch'), moz_places.url,moz_places.title,moz_places.visit_count FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER by moz_historyvisits.visit_date; " | sqlite3 ./places.sqlite

Now I can add a grep to the end of that and find what I was looking for.

Why not just use the built in search for finding stuff? Well the simple reason is that I can add more complex searches easily using regex.

Plus I wanted to be able to export and save my history to a file where I can search it later. Without having to install some firefox extension.

If you wanted to get really adventurous you could do some php like this:


<table>
<?
$todo=”SELECT datetime(moz_historyvisits.visit_date/1000000,’unixepoch’), moz_places.url,moz_places.title,moz_places.visit_count FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER by moz_historyvisits.visit_date;”;
$dbh = new PDO(‘sqlite:places.sqlite’);
foreach ($dbh->query($todo) as $row)
{
//print_r($row);
echo “<tr>\n”;
echo “<td>”.$row[0].”</td>\n”;
echo “<td><a href=\””.$row[‘url’].”\”>”.$row[‘title’].”</a></td>\n”;
echo “</tr>\n”;
}
?>
</table>

Since most of the projects I work on with Atmel are USB based the first thing I do is load AVRUSBBoot on a chip. Once the bootloader is on the chip you can re-program it by setting a jumper on your circuit and using the avrusbboot command line interface. (Example: avrusbboot ./filename.hex)

But how to get the bootloader on the chip in the first place? Easy. Buy a AVRISPMkII from an Atmel distributor. It comes with the necessary hardware and software to program chips. Then the question becomes: If I have a programmer why would I need a bootloader? I guess the answer is: convenience. Once a circuit is built with usb support, which is only 4 wires, it is easy enough to put a jumper on and use the bootloader. When I order a new batch of chips I could put them all on the programmer and load the bootloader all at once.

The downside to the usb bootloader is that it requires a 12Mhz crystal to be attached to the chip. (I primarily use Atmega8 chips.)

Although I have never used one there is a possibility of using a serial port or parallel port programmer built out of very few, cheap components.

There is a good overview of all the methods of programming an avr at ladyada.net.

One of the greatest beginning tutorials I have found for Atmel programming is the I Make Projects article called “A Quickstart Tutorial for ATMEL AVR Microcontrollers.” If you are just starting buy a couple Attiny45 chips and follow that.

Warning: To get a bootloader to work with usb you have to change fuse settings. It is easy to “brick” a chip if you give it the wrong fuse settings. Especially changing the clock and re-assigning the reset line. (Reset is needed to activate the In Circuit Programming.) Read, re-read, and triple read before reprogramming fuses. Look at RSTDISBL, SPIEN, and CKSEL.

When I prep an Atmega8 for use with the avrusbboot program I use Hight fuse @ C0 Low Fuse @ 9F and locks set to EF. As soon as you hit the button to program these fuses it will absoulutely need that 12Mhz crystal on pins 9 and 10 with the 27pf capacitors. Or you wont be able to talk to the chip again.

An online fuse calculator for avr chips.

Now that I have my quick protoboard together it allows me to take other people’s projects and put them together really quickly. Today I built the USB-LED-Fader. Since the hard parts were already done it took about 5 minutes to add the 4 resistors and LEDs to a breadboard. Then another 5 minutes to compile and upload the firmware using the bootloader.

Then I spent about an hour playing with the different LED patterns. This is a really fun project. I can see tons of potential for different status lights. Tie a cpu meter to one of the lights… the faster it flashes the more cpu is being used. One LED for email status. One for network traffic. And finally one for server status.

(The photo from the atmega8 development board shows this project on the breadboard.)

Last night I stared building a atmega8 development board. Tonight I finished it.

I got tired of building the same circuit over and over; so I made a generic board that I could slap onto a breadboard and quickly try out projects. It also allows me to rapidly prototype something new.

I based the board on AVRUSBBoot. The only thing I changed was the programming pin. I moved it to PD7. This allowed me to put PB* and PC* on the plug side of the board.

On the right hand side of the board I brought all the PortC and PortB pins as well as + and GND to a row of header pins.

The important thing about this board to me is that it is USB powered and based. I don’t need to hook up a programmer, I just use the bootloader and usb to update the software on the chip.

My header looks like this:

  1. PC5
  2. PC4
  3. PC3
  4. PC2
  5. PC1
  6. PC0
  7. GND
  8. PB0
  9. VCC
  10. PB5
  11. PB4
  12. PB3
  13. PB2
  14. PB1

Introducing the Unfocused Brain Hallucination Generation device. A Trance Machine based on visual stimulation.

In ancient times people used what is known as the Psychomantium to talk with the spirits. Nostradamus used one to tell the future. In the 1960’s Brian Gysin and Ian Sommerville created the Dreammachine. Recently pioneer Mitch Altman gave us the Brain Machine in Make: Volume 10.

All of these devices try to bring us to a heightened state of consciousness where we can achieve our full potential commune with the universe and see the future.

My device does one thing and one thing only. Makes you see trippy stuff.

I’ve built a Psychomantium. I built the Brain Machine. What I learned was that playing with your visual processing can make you see stuff.

The Brain Machine makes you see really neat stuff. Stuff like I used to see in the old days staring into a Circle K cup held over a strobe light. I tried the Brain Machine without the sound and it seemed to make me have hallucinations as well as with the sound. Plus certain transitions, like from theta to delta, made really neat visuals.

Getting bored quickly and wanting to just have the transition visual effects I made my own. This one has buttons. It allows you to switch from one state to another at will. It allowed me to find out what worked best for me.

This is just the start of my path down the visual stimulator trance machine path. I plan on making one that I can tune to which ever frequencies in each range work best for me. Then I plan on making one where I can easily store programs of different patterns and play them back. Possibly as a USB device. I have even thought about making one that will fill a whole room with light so that the patterns can be given to me while sleeping.

This is going to be fun. 8)

Like I said in my last post I have been working on some tools for writer brainstorming. The first one was the “article title writer” at TheWritersSecret.com. Next is a one for brainstorming movie titles. I call it “Movie Brain”.

The tech behind it:

It is written in JavaScript. That way the work of sorting through the data is done by the client machine instead of the server. JavaScript also has some pretty decent string handling abilities.

I collected over 11,000 titles from the WikiPedia list of movies. These are stored by category and are processed into usable data using a combination of awk, grep, and php scripting. For example:

cat horror_words.txt | awk '1==1 {printf("\"%s\",\n",tolower($2));}' | sort | uniq >movies_all.js

The engine uses a very simple template technique. Examples:
“() meets (2).” The parenthesis would be replaced by two different random words. “Boy meets Bacon.”
“The {} and the ()” The brackets would be replaced by a random amount of random words and the parenthesis would be replaced by a single word. “The egg substitute and the curmudgeon.”
“[]: {}” Here the [] means a year. “2012: Pirates Invade”

The last piece of tech was a fun part. When you generate the random list of movies you can see what they would look like with your standard coming soon movie title over a black screen. Just click on one and see what I mean. It uses JavaScript and CSS to generate and animated the title. For a time I had added zooming in on the title but I didn’t like how much processor it hogged.

I also used a technique for the coming soon generator, to keep it all client side, that I had never used before. A couple days ago a friend asked if it were possible to do forms without a server. Apparently it is possible if you are using method GET. You can just have JavaScript parse the URL to read the data.

While writing the JavaScript I found a wonderful resource JavaScript equivalents for PHP functions.

I am a huge fan of TiddlyWiki and use it all the time. This morning I wrote a quick utility in JavaScript to convert CSV to TiddlyWiki Table format.

I am releasing this code into the public domain. The main reason I am doing this is because I had problems finding a JavaScript CSV interpreter that was already public domain. Mine is quick easy and kinda bug free. //smile

Sure there are over 6 million places on the internet to check your IP Address. I’m sure I’ve written this app at least 7-8 times.

But this one is different. No mission creep. Just a plain minimalist way to find out: What is My IP Address?

For some reason I got the idea that importing my Firefox bookmarks.html into a TiddlyWiki would be a good idea. I know its just a .html file and that I could just open it in a text editor and paste it inside a TiddlyWiki tiddler and be done with it.

Deciding against the easy option, I decided to have the bookmarks.html file process its self by adding some JavaScript to it. After making a copy of my bookmarks.html file I added this code to the top of the file:



<SCRIPT LANGUAGE="JavaScript">

var theOutput="";

function run_me()

{

    myDiv=document.getElementById("my_div");

    theOutput="";

    theDL=document.getElementsByTagName('dl')[0];

    theOutput="";

    walkBookmarks(theDL);

    myDiv.innerHTML="<textarea cols=\"80\" rows=\"20\">"+theOutput+"</textarea>";

}

function walkBookmarks(node)

{

    if (node.nodeName =="H3")

    {

        theOutput +="!"+node.firstChild.nodeValue+"<br>\n";

    }

    if (node.nodeName =="A")

    {

        theURL = node.href;

        theText=node.firstChild.nodeValue;

        theOutput += "[["+theText+"|"+theURL+"]]<br>\n";

    }

    if (node.childNodes != null)

    {

        for (var i=0; i < node.childNodes.length; i++)

        {

            walkBookmarks(node.childNodes.item(i));

        }

    }

}

</SCRIPT>

<div id="my_div">Working....</div>

And this code to the end of the file:



<script language="JavaScript">

run_me();

</script>

Which will give wiki formatted text like this:



!Bookmarks Toolbar Folder<br>

[[UnfocusedBrain.com -|http://www.unfocusedbrain.com/]]<br>

[[[Yahoo!]|http://www.yahoo.com/]]<br>

Works pretty nice.

My second attempt was to try using “rdf:bookmarks” as described in the RDF in Mozilla FAQ on the developer website. I really didn’t make much headway with this method. If I were to develop a plug-in for TiddlyWiki that works w/ Firefox’s built in bookmarks this would definitely be the way to go.

My third attempt was to use the ExternalTiddlersPlugin by Eric Shulman. Which allowed me to just put one line in a tiddler and have the bookmarks show up:

<<tiddler "file:///home/username/.mozilla/firefox/l3qbefb3.default/bookmarks.html">>

It almost worked. Since the bookmarks isn’t a really well formed html file it doesn’t come through the tiddly process very well. So I just added a couple lines of code to add around the file and it worked perfectly.



function my_textprocess(text)

{

    text = "<html>" + text + "</html>";

    return text;

}

With this method the links reflect the non editable nature of the real bookmarks from the TiddlyWiki.

In the end I’m not entirely satisfied with any of these methods. What I would like to make would be a plug-in to TiddlyWiki that will open the “rdf:bookmarks” interface. For each folder in the bookmarks it would create a new tiddler and under each tiddler would be the links. In addition to this I would like to add a Bookmarklet to add links to the wiki instead of the real bookmarks.

Tiddly.

« Previous PageNext Page »