Pro-Am Shuffling
If you don’t know what shuffling is, I’m not going to take the time to explain. Just watch the videos below. LMFAO’s lyrics are not…to put it lightly…acceptible, but the music is some of the most popular electronic dance music around today and the dance moves are almost magical (video #1). Outside of that, many folks will be familiar with the old man from the Six Flags commercials (video #2). Obviously, the young and fit have no problem doing this (videos #3 through #6), but it’s the grandpa shuffling at the fiddling fastival (video #7, @ 0:56) that prompted me to post this. If you are interested in learning how to do this, Mr. Nick Martin has created http://howtoshuffledance.com just for you.
January 31, 2012
January 31, 2012: Shuffling
January 30, 2012
Getting Google Maps
So, I’d like to have a current traffic map delivered to my e-mail at the precise moment I’m leaving work for the day. Call me lazy, but this is the sort of thing that can be automated pretty easily and I don’t want to go look it up, I want it delivered. Someday, I’ll get around to setting this up, but as they say, a journey begins with a single step. In this case, the step is to find a way a good to download Google Maps with a script. For now, that is the scope of this post.
Here’s some initial research to plow through:
Mapki: Google Map Parameters Best reference so far!
Google Static Maps API*
A PERL/Wget solution
A Python script
MapTileCacher in PERL
In Bash
Discussion on Google blocking tile downloads
* On 2/7/2012, I tried using the Google Static Maps API and received Error 400 (malformed or illegal request) when using the URL described therein. I have had more luck using Google Maps directly to frame the map, getting the (perma)link, and tweaking the parameters.
January 13, 2012
Single Keystroke Menu Using Term::ReadKey
Using Term::ReadKey, you can implement a console menu/prompt that accepts a single keystroke. There are many similar implementations of ReadKey available on the Web. This one is in the form of a reusable subroutine. Only valid options are accepted and the choice is returned to the calling script for futher use. It does not convert the choice to upper- or lower-case, because sometimes it is nice to have both options available.
The Subroutine
This code can be placed in a script or in a separate module.
1: use Term::ReadKey;
2:
3: sub getPromptOption ($$)
4: {
5: my $prompt = shift;
6: my $options = shift;
7: my $choice;
8:
9: ReadMode 'cbreak';
10: print $prompt;
11: $choice = ReadKey(0) until $choice =~ m/[$options]/;
12: ReadMode 'normal';
13: return $choice;
14: }
Obviously, the Term::ReadKey must be loaded first (line 1). The getPromptOption() subroutine accepts two mandatory parameters as indicated by the declared prototype (line 3). Additional field-validation logic may be desired, but is omitted here for brevity. The terminal’s “read” mode is changed to cbreak, which accepts a single character as input (line 9). The prompt that was passed into the subroutine is printed on the screen (line 10) and then the program enters a loop that reads characters from keyboard input until one of the valid options is entered (line 11). Once a valid key has been pressed, the read mode is returned to normal mode (input accepted until the Enter key is pressed; line 12) and the chosen option is returned to the calling logic (line 13).
Usage
This is a very contrived routine that illustrates the use of the subroutine described above. It allows the user to increment or decrement a current value.
1. my $i = 0;
2. my $action = '';
3. print "Current value: $i\n\n";
4. until ( $action =~ m/[Xx]/ ) {
5. $action = getPromptOption(
6. "Select Action: [I]ncr, [D]ecr, or E[X]it",
7. "IiDdXx"
8. );
9. $i++ if ( $action =~ m/[Ii]/ );
10. $i-- if ( $action =~ m/[Dd]/ );
11. print "\n\nCurrent value: $i\n\n";
12. }
The iterator (“$i”) is set to an initial value of zero (line 1) and the next action flag (“$action”) set to null (line 2). The current value is printed on the screen (line 3) so that the user knows what it is. Next, the user is prompted to increment or decrement the value, or to exit the program (lines 5-8). If the user chooses to change the value by pressing the “i” key (line 9) or the “d” key (line 10), then the value is printed again on the screen for the benefit of the user (line 11). If the user presses the “x” key, the loop ends (line 4) and process control flows out to the end of the script. Please notice that both the upper- and lower-cases are valid options (line 7), but that the program is indifferent to which is used (lines 4, 9, 10).
TiddlyWiki: Cookbooks
Home > My Lists > Technical Notes > TiddlyWiki > TiddlyWiki: Cookbooks
If anything, TiddlyWiki reminds me of a set of index cards (well, more so of Cardfile and HyperCard I suppose), and index cards make me think of two things: term papers and recipes. I’ve noted elsewhere how I’ve used TiddlyWiki for educational purposes, so here’s my list of TW-powered recipe boxes.
Disclaimer: I’m sure the recipes on the sites below are great. I can’t say that I’ve ever actually made any of them. I’m showing off TiddlyWiki, not endorsing recipes.
Jackson Boyle’s Kitchen. Mr. Boyle’s blog includes a TiddlyWiki recipe book. The site is no longer around, but the recipes are still available here on the Wayback Machine.
Philosophical Gourmet Cookbook. The Philosophy department of the University of Florida once published a gourmet cookbook online. The link is now dead, but a copy can be found here on the Wayback Machine.
January 12, 2012
January 12, 2012: DHTML, Hacking, Polymer Balls
Dynamic Drive
I was looking for some site navigation options and found Dynamic Drive: DHTML Scripts for the Real World. They have some really slick stuff. I was particularly interested in the Drill Down Menu before my attention was diverted elsewhere. I may come back to it some day.
Hackers Handbook
Wow! A reference manual on how to hack! It’s an Android app and costs $6.99. One reviewer gave it a 3.4-star rating and explained that all of the material was available online for free.
How To Make Bouncing Polymer Balls
This three-part series explains how to make polymer bouncy balls using household products.
TiddlyWiki: My Experience
Home > My Lists > Technical Notes > TiddlyWiki > TiddlyWiki: My Experience
I have fallen in and out of love with TiddlyWiki several times since August 2006. It started with this ‘blog post by “euicho” written almost exactly one year earlier. I’ve used it successfully for several small projects, though more often than not, what began with a TiddlyWiki blossomed into a ‘blog, a website, or a full-blown application. So, if anything, it’s good for working out a design for what I really want to do. It’s extremely versatile and addictive too! Here are some highlights from my TiddlyWiki experience.
Notepad. Believe it or not, this ‘blog began as a TiddlyWiki…sort of. I wanted to publish my notes on a number of topics on a free “personal” page. Cobbling pages together by hand was too labor-intensive, especially when I wanted to change the look-and-feel of the whole site at one time. I wasn’t learned in CSS at the time and I tried automating the compilation of a site using flat data files, HTML templates, make, and a few other scripting utilities. All of it was taking up way too much time. TiddlyWiki was the answer. For a very good reason (which now escapes me), I decided to use ‘blog technology instead, which has worked out far better in the long run; however, I might not have made that leap without TiddlyWiki in the middle.
School Notes. I finally broke down and bought a laptop while I was in graduate school. This allowed me to take all of my notes electronically, at least for the last couple of years in the program. I really wanted to go paperless, so I relied on scans, downloads, and other methods for keeping it all digital. I even recorded lectures on occasion. TiddlyWiki was my notebook of choice. With a wiki mindset, I would create Tiddlers for topics and then referenced them from Tiddlers containing basic outlines of both textbook chapters and lectures. Doing most of the work before hand allowed me to take minimal notes during class, which meant that I could pay more attention to the professor and participate in the discussion more fully.
Big Finish. The proverbial icing on the cake came in my capstone course. The professor (who happened to be the department chair) believed heavily in the power of organization. A student who keeps an organized and complete notebook will always do well, he would tell us often. As such, we had to turn in our class notebooks to the professor at the end of the semester – for a grade! I hadn’t done that since, oh let’s see, high school! It was degrading, but admittedly, a very wise requirement on his part. I had one little problem. I told him that I could print out the contents of my “notebook”, but with his permission I’d rather turn in a 100%-electonic copy. He agreed, so long as it was easily viewed on his PC with little effort. Everything was linked in the TiddlyWiki. I just burned the CD and wrote the instrucitons on the label: “insert into CD-ROM drive and open notebook.html”. I guess it worked, because I aced the course. He retired the next year.
January 10, 2012
Tie::File Examples
Using Tie::File, you can operate directly on a text file as an array. This provides random access to lines in a file and allows for speedy manipulation of very large files since the file itself is not loaded into memory. The following are some examples with explanation as to how they work. (Yes, these examples are extremely rudimentary and a bit redundant at that; this is because I like to have complete examples at my fingertips to use as base templates when I need them for real programming work.)
The Data File
Any ASCII text file can be used with the following examples. I use “myfile.txt” for illustrative purposes, and for me, it is a twenty-line file that contains consecutive numbers on each line (line 1 is “1″, line 2 is “2″, etc.). The following code creates this data file and quickly resets it as needed.
1: open (OUT,">myfile.txt");
2: print OUT join("\n",1..20);
3: close OUT;
Basic Example
This is a very basic example for using Tie::File. It just prints the contents of an array on the screen.
1: use Tie::File; 2: my @records; 3: tie @records, 'Tie::File', "myfile.txt"; 4: print join ( "\n", @records ); 5: untie @records;
The module must first be loaded using the use function (line 1). Next, an array is defined that will be tied to the file (line 2). The tie command is where the magic happens (line 3). Now the lines in the file can be operated upon as though they were just elements in an array. The print/join function is a common way to print an array tot he screen (line 4). The untie function releases the file (line 5), though this is often omitted due to laziness.
Direct Access
Reading a file and printing records is only so much fun. Here’s an example of how to change a single line in the file directly.
1: use Tie::File; 2: my @records; 3: tie @records, 'Tie::File', "myfile.txt"; 4: $records[9] = "foo"; 5: print join ( "\n", @records ); 6: untie @records;
This is the same code as before, except that line 4 has been injected. It is a simple assignment that changes the tenth line of the file to “foo”. Remember that PERL arrays are zero-based, so $records[9] is actually the tenth element in the array.
Autochomp
Notice that newlines must either be chomped on input or readded for output. This is handled automatically.
Windows Newlines
Here’s an interesting trick if you are using PERL on Windows. Consider the following code.
1: use Tie::File; 2: my @records; 3: tie @records, 'Tie::File', "myfile.txt"; 4: $records[9] = "foo\nbar"; 5: print join ( "\n", @records ); 6: untie @records;
Adding a newline character (“\n”) to the array element value will only embed it in the string. Inspect the file afterward, and find that no new line has been created in the file, even though it appears from the screen output that one had been added. Since line endings in Windows are two characters instead of one, carriage-return and linefeed, you must prepend the other character (“\r”).
1: use Tie::File; 2: my @records; 3: tie @records, 'Tie::File', "myfile.txt"; 4: $records[9] = "foo\r\nbar"; 5: print join ( "\n", @records ); 6: untie @records;
Now the file does show an additional line. Of course, there are much better ways of doing this.
Changing Record Separators
Much like the RS and ORS variables in AWK, the record separator can be changed to any text string. This is done when the file is tied. Only this line is presented here.
1: tie @records, 'Tie::File', "myfile.txt", recsep => 'zap';
Now, the file will be separated into records on every occurence of the string ‘zap’. I don’t want to spend the time to write and test a working example for this, as the need for this sort of thing may never arise in my work. It was just interesting to note.
Splicing
To remove one or more lines from a tied file, use the splice command.
1: use Tie::File; 2: my ( @records, @removed ); 3: tie @records, 'Tie::File', "myfile.txt"; 4: @removed = splice(@records,1,3); 5: print join ( "\n", @records ); 6: untie @records;
Again, this is the same code we’ve been using, except an additional array has been declared (line 2) and the splice command has been introduced to remove the second, third, and fourth lines from the file (line 4). The first parameter of the splice function is the array, the second is the offset from the beginning of the array (one element), and the third is the length of the slice to be removed (three elements).
Here’s how elements can be replaced.
1: use Tie::File; 2: my ( @records, @removed ); 3: tie @records, 'Tie::File', "myfile.txt"; 4: @removed = splice(@records,1,3,26); 5: print join ( "\n", @records ); 6: untie @records;
The same records are removed as above, but one new element has been inserted in their place with a value of 26.
Push, Pop, Shift, Unshift
All of these functions have splice equivalents, but they can be used as they normally would to manipulate the tied file.
Iteration
Random access is nice, but sometimes it is necessary to iterate through the records in a file. The following illustrates how to print the contents of the array to the screen by iteration instead of using print/join.
1. use Tie::File;
2. my ( @records, $record );
3. tie @records, 'Tie::File', "myfile.txt";
4. foreach $record ( @records ) { print "$record\n"; }
5: untie @records;
In addition to declaring the array, a record scalar is defined (line 2). The foreach iterator is used as one would expect to traverse through the array from beginning to end. A for loop could have been used just as easily.
January 5, 2012
January 5, 2012: Athos
Mount Athos
A friend sent me a link to the CBS 60 Minutes story that aired on Christmas 2011 about this most-fascinating part of the world.
Part 1: http://www.cbsnews.com/video/watch/?id=7392864n
Part 2: http://www.cbsnews.com/video/watch/?id=7392862n
Wiki: http://en.wikipedia.org/wiki/Mount_Athos
January 4, 2012
Tea 2012
Home > My Lists > Food & Drink > Tea > 2012
The teas I tasted in A.D. 2012 and what I thought about them. Prices are per pound.
I had so much tea left over from the past two years, that I felt compelled to cut down on the number of new teas in 2012. So, this year included a focus on blends, including combinations of tea with Yerba Mate.
Wulu (Jade Green) Organic Green Tea. [World Market; ~$49.95] Originally, I thought that this tea would be similar to the Dragon Well loose tea from 2011 and the “Imperial” tea from Hangzhou gifted to me the year before. The taste is the same, but it’s not as mellow. I also didn’t realize it was slightly more expensive until I calculated the price per pound above. As long as it is available and reasonably priced, I think I’ll stick with the Dragon Well.
Passion Fruit Orange Infusion + Mate. Last year, I wrote that I might try blending the Cuida Te Passion Fruit Orange Infusion with a more basic tea to make it less pungent. The most interesting blend was with yerba mate. I was inspired to create something similar to Teavana’s Samurai Chai Mate. I used equal parts tea and mate. The chunky bits of dried fruit in the tea made the visual balance tilt in the direction of the mate, with far more green than orange and black, commensurate with the Samurai. The result was not stellar, but it made the tea much more tolerable.
Passion Fruit Orange Infusion + Pu-Erh. This combination deserves mention. Since both teas are very strong, I assumed (correctly) that they would play well together; however, the fruit flavors could only be detected when the tea had cooled some. Before that, the Pu-Erh and the heat were overpowering.
Black Tea + Mate. Since I was experimenting with my own blends, I figured why not cut the mate with some good ole black tea. I mixed a teaspoon of the Russian MTF Ceylon black tea from last year with two teaspoons of mate. It turned out to be a good balance. I have taken to sifting the mate dust out with a kitchen strainer, resulting in a very clear brew.