Welcome to Robot Dialogs. This is a place where I will record my progress, mistakes, errors, failures, lessons learned and hopefully occasional success in my designs and implementations of robots and other technical endeavors. I will try to make it as educational, informative and entertaining as I can...

Wednesday, June 23, 2010

Day 23 + Week 3 of 30 Days of Creativity

Day 23:
#include <stdio.h>
//Have fun figuring it out :)
int main(){
   int i,j;
   int starts[] = {22,17,13,10,8,6,5,4,3,2,1,1,1,1,1,2,3,4,5,6,8,10,13,17,22};
   int stops[] = {33,38,42,46,48,46,43,41,39,36,33,31,29,31,33,36,39,41,43,46,48,46,42,38,33};

   for( i = 0; i < 25; i++ ){
      while(j++<50) (j<starts[i]||j>=stops[i])?printf(" "):printf("o");
      printf("\n"); j=0;
   }
   return 0;
}
Give Up?

The rest, through today:

Day 15: Floating Sprial Bookshelf StaircaseDay 16: Work in Progress
Day 16
Day 17: Infinity
Day 15Day 17
Day 18: Cartoon Gravity
Day 18*
Days 19-21 were used to chip away at a work in progress.
Day 22 : Logic Gates
Day 22

*Featured at 30daysofcreativity.com

Tuesday, June 1, 2010

Day 1 : 30 Days Of Creativity

Okay, to attempt to get out of the lull I've been in lately with no projects getting worked on, I've taken the plunged and joined the community of folks that have pledged to do something creative every day of the month of June. More on that can be found at 30 Days of Creativity. I highly recommend joining the movement, I do hope they find something better than twitter to deliver their highlighted articles though...140 characters isn't my favorite medium.

Part of the reason for my lull in projects is the fact that I've spent the last week or so organizing my giant collection of music, movies and documents. So really there's nothing to show of that except to myself...or so I thought.

As my first piece of creativity I bring you a snippet of one of the programs I used to organize my music collection. The creative bit is that I actually documented it and it's a very simple example of a programming concept called recursion. This program recursively checks directories for files that have numbers in their names. I've listed the code below (full code available at bottom). I hope that it is a good example of recursion and self documenting code for novices to understand. I'm not going to explain recursion, there are much better teachers on the web for that sort of thing.

Tiny back story: I'm really picky about file names in my music collection. I hate files that start with a track numbers or contain any other garbage characters.

You can easily see the usefulness if you consider how long it would take to manually navigate say 1000 folders each having 10 files...
/**
 * Simple recursive method that searches every file within the 
 * parent directory (and all sub-directories) for file names 
 * with numbers in them. 
 * 
 * @param parentDirectory The directory to check.
 */
private void checkChildrenForNumbers(File parentDirectory) {

//Get a list of this directory's children (file and folders inside it).
   File []  children = parentDirectory.listFiles();
   //Go through each child (in plain English "for every child in children")
   for(File child : children){
      //if this is another directory within the parent directory
      if(child.isDirectory()){
         //recursively check folder (this is the magic)
         checkChildrenForNumbers(child);
      }else{//child isn't a directory
         //check if there is a number in the file name
         if(containsNumber(child)){
            //open the parent folder so I can fix the file name.
            openParentFolder(parentDirectory);
            //stop this program while I fix it.
            waitForInput();
            //when I'm done fixing the file this will exit this method. 
            return;
         }
      }
   }
}
* If the code is all foobar'd here's a picture, and the full code is below. 
Obviously the goal of this code can be achieved by searching for numbers with the standard windows (or whatever OS) search mechanism. Again this is a simplified version, in the real version it can check for any garbage characters and has some improvements to limit files like "Mahler - Symphony No. 5 - Adagietto.mp3" from showing up as a false positive.

Full Source Code File: NumberedFileFinder.java

p.s. I'm not going to do a full post for each day of the month. Instead I will shoot a picture or something out on my Twitter and then make a recap post here each week. If I come up with something awesome (certainly more awesome than today's) I'll make a full post.