Category Archives: Development

HTPC Wakeup!

Hey All,

I apologize for not having any updates. I’ve been busy with work and haven’t really done any personal projects or coding =(

However, I finally got some free time and I’ve been wanting to fix something that has bugged me for a while now. I have my wonderful HTPC and it’s setup up to use XBMC to play all the media that stored on my fileserver. In the past I’ve always had to press the button on my case to turn the darn thing on. Well I got tired of that and I figured there had to be a way to turn on my computer with the remote. It’s got a USB dongle that stays lit up, so that means it’s powered and the OS is waiting for commands. (BTW I made sure to enable wake on USB in my bios for this to work!)

As the old saying goes, necessity is the mother of all invention, well I needed to become more lazy so I wrote this little script that finds a gyration remote dongle on your USB subsystem and allows for it to be used as a device to wake the system from the S3 (suspend) state. This init script runs on boot to keep the settings persistent after a reboot.

#!/bin/bash
# gyrationWakeFromS3.sh

#
# Author: Robert Navarro 9/11/10
# Contact: crshman[at]gmail.com
#
# This init script finds a usb device by 'device' and makes it so it can be used to wake up a system from the S3 state

# Set /proc/acpi/wakeup to allow USB devices to wake the system
# sudo sh -c "echo USB3 > /proc/acpi/wakeup"

device='Gyration'

# Grab the pci ID for our device
pciID=$(cat /proc/bus/input/devices |grep -A2 -m1 $device |grep S\: |awk -F'/' '{ print $4 }')
#echo $pciID

usbID=$(cat /proc/acpi/wakeup |grep $pciID |awk -F' ' '{ print $1 }')
#echo $usbID

echo $usbID > /proc/acpi/wakeup

Just drop that script into your /etc/init.d/ folder and run the following:

#sudo update-rc.d gyrationWakeFromS3.sh defaults

Whala! You should now have resume support from your Gyration device. A little note here, in the init.d file you can certainly change which device wakes your system by changing the value of the ‘device’ variable.

Drop me a line if you have any questions about this!

Spring Cleaning! Er…Organizing

Hey All,

I REALLY REALLY apologize for not updating this thing. School has been quite ridiculous for the better part of this year. Nonstop labs and homework, I can’t wait until the end of this quarter…I may actually be able to breath!

So today’s blog post is about a little script that has been working faithfully for me for some time now. However, I have decided to just recently release it to the public. I’m not sure how much exposure it’ll get, but it’s out there now…well almost!

This script is used to organize your digital movie collection (you know, all the rips of your legitimately purchased movies?) I personally think this script is the best thing since sliced bread, but as the author I may be slightly biased… The script will look in your movie directory for an imdb.txt file that contains the imdb URL for that movie (it’ll also look in .nfo files) Once it finds the imdb URL the magic begins! The script pulls the official movie title from imdb along with the release year. The script also grabs posters and backdrops from TMDB to make your collection XBMC friendly. Once armed with this information it moves your movies into the specified directory and renames all the folders with the format: “<Movie Title> (<Release Year>)” The script takes into account special characters that Windows can’t stomach. (Such as :, which gets translated to ; )

As Billy Mays would say….But wait! There’s more!

The script also reads the original source directories for the strings 720p and 1080p. If it finds either of these strings the resultant output folder name will change to:” <Movie Title> (<Release Year>) HD <resolution>” Eventually I’d like to add support for reading the media files themselves and checking what resolution they really are, but for now folder names will have to do.

I am a fan of Asian films, primarily Korean Dramas and Japanese Action flicks. I personally choose to isolate this genre of film from my regular movie set. As such, this script has the added bonus of separating films that it deems are “asian”. (This is user controlled of course!)

Now for the goodies, where do I get it?

You can clone the source (and report bugs) from my codaset project page:

http://codaset.com/phiivo/movie-magic

Hopefully this script benefits some people as it has benefited me. This has saved me loads of time and has help to unify my media collection in a singular format. Once again, sorry for the lack of posts…I’ll try to keep updating this thing as I’ll probably have some more time after this quarter.

Dev Days LA 2009

Hey All,

So today I decided to ditch school and participate in Stack Overflow Dev Days 2009. I thought the conference was pretty good and the student price of $10 was amazing! The turn out was a little less than I had anticipated but I suppose that just left more room to spread out for those of us that went. I got there pretty early, 8:15am, checked in and grabbed a seat. They were serving coffee and some muffins.

There was a bit of swag available:

Stuff I liked:

  • The Python talk and dissection of the Google spell check algorithm by Mike Schiraldi of Reddit
    • This presentation was really well layed out, easy to follow and appealed to the geek in me as it ran in xterm on python haha. Pretty slick Mike…
  • The jQuery talk by Cody Lindely
    • This presentation would’ve been much better had the Internet worked. That, or had Cody saved all of his work locally to show the audience. I’m sure we would’ve been in for some really trick eye candy. He did however lead me on to two good sites, jsBin and Cody’s jQuery selector demo.
  • Most, if not all of Joel’s talks were highly entertaining. He talked about Fog Bugz and all the features that the software has, such as:
    • Not technically a feature, but ya….Fog Bugz 7
    • Fog Bugz Kiln, tight Fog Bugz integration with hg
      • I talked to Joel a little during one of the breaks and sadly support for git is not on the roadmap, and he said it probably won’t ever be….*sad panda*
    • Also not a direct feature, but part of a plugin for Fog Bugz, Balsamiq Mockups I think this app has great potential to interact with prospective clients
  • The QT (cute) presentation by Daniel Rocha of Nokia. This presentation really impressed me, he did actual coding (yes typing), compilation and a demo on 3 separate platforms and they all worked flawlessly. Kudos Daniel! This presentation also showed QT’s cross platform power, seamless migrations from one platform to another, that was pretty slick.
  • Jeff Atwood’s talk about random junk. I wished his presentation would’ve gone on longer it was pretty entertaining. He’s actually a really nice guy, I talked with him during one of the breaks and he gave me some coding horror stickers =D

Stuff I didn’t like:

  • The provided wifi was pretty crappy, I found myself tethered to my cell for most of the day. It was just unmanageable. I would have thought they would have gotten this right, especially after Joel’s writeup on conference wifi.
  • A lot of the presentations went backwards in my mind. I think the presenters should show the power of said technology first (get the fancy demos out of the way) and then talk about the code/app/etc. that powered that demo. This probably would’ve worked much better for Rory Blyth and his iPhone presentation. There were a lot of boring coding sessions that didn’t need to take place IMHO, we’re developers and we can figure out syntax on our own….rtfm.

Misc:

  • The Google Apps Engine talk by Jason A Cooper of Google would’ve been more captivating if he had spent more time talking about the product/service and less time typing code. Though he did show off some fancy gChat integration stuff that wow-ed the crowd, that was pretty neat.
  • The keynote was an interesting take on software design, I really liked what Joel had to say on Simplicity vs Power. It basically came down to: write elegant code so your users don’t have to make lots of decisions. Though I don’t think you should take elegant and make your code a giant unreadable 1 line mess. That’s a total maintenance buzz kill.

Well I think that’s it for now, see you all next year!

    CakePHP cPanel API Component

    Hey All,

    Long time no update, I know… Well I’ve been working on some projects that involve cPanel and its API so I decided to write a nifty little component for my fellow bakers. It makes extensive use of the php api library that can be found on the development forums, but I tweaked it a little bit to be more cake friendly.

    Unlike my prior posts, this component is a little too long to post here. So head over to my git hub repository to pick up your slice of goodness.

    As usual if you have any comments, concerns or questions feel free to get in touch!

    CakePHP Build Acl Action

    Hey Everyone,

    So I went ahead and took up Mark Story on his challenge task and added the node deleting functionality that was missing from the original buildAcl action. I’m not sure if this was the best way to code it….but a few beers, and a lot of coding later I came up with this gem. Feel free to use this wherever you want.

    
    /**
    * Rebuild the Acl based on the current controllers in the application
    *
    * @return void
    */
    function buildAcl() {
    $log = array();
    $methods = array();
    $tempChildren = array();
    
    $aco =& $this->Acl->Aco;
    $root = $aco->node('controllers');
    if (!$root) {
    $aco->create(array('parent_id' => null, 'model' => null, 'alias' => 'controllers'));
    $root = $aco->save();
    $root['Aco']['id'] = $aco->id;
    $log[] = 'Created Aco node for controllers';
    } else {
    $root = $root[0];
    }
    
    App::import('Core', 'File');
    $Controllers = Configure::listObjects('controller');
    $appIndex = array_search('App', $Controllers);
    if ($appIndex !== false ) {
    unset($Controllers[$appIndex]);
    }
    $baseMethods = get_class_methods('Controller');
    $baseMethods[] = 'buildAcl';
    
    // look at each controller in app/controllers
    foreach ($Controllers as $ctrlName) {
    App::import('Controller', $ctrlName);
    $ctrlclass = $ctrlName . 'Controller';
    $methods = get_class_methods($ctrlclass);
    
    // find / make controller node
    $controllerNode = $aco->node('controllers/'.$ctrlName);
    if (!$controllerNode) {
    $aco->create(array('parent_id' => $root['Aco']['id'], 'model' => null, 'alias' => $ctrlName));
    $controllerNode = $aco->save();
    $controllerNode['Aco']['id'] = $aco->id;
    $log[] = 'Created Aco node for '.$ctrlName;
    } else {
    $controllerNode = $controllerNode[0];
    // Get all the children of the current controller node
    $children = $this->Acl->Aco->children($controllerNode['Aco']['id']);
    $sizeChildren = sizeof($children);
    }
    
    //clean the methods. to remove those in Controller and private actions.
    foreach ($methods as $k => $method) {
    if (strpos($method, '_', 0) === 0) {
    unset($methods[$k]);
    continue;
    }
    if (in_array($method, $baseMethods)) {
    unset($methods[$k]);
    continue;
    }
    $methodNode = $aco->node('controllers/'.$ctrlName.'/'.$method);
    if (!$methodNode) {
    $aco->create(array('parent_id' => $controllerNode['Aco']['id'], 'model' => null, 'alias' => $method));
    $methodNode = $aco->save();
    $log[] = 'Created Aco node for '. $method;
    }
    }
    
    $sizeMethods = sizeof($methods);
    
    // More Aco's than methods
    if($sizeChildren > $sizeMethods) {
    foreach($children as $child) {
    $tempChildren[] = $child['Aco']['alias'];
    }
    // Get the difference between Acos and methods
    $diff = array_diff($tempChildren, $methods);
    foreach($diff as $alias) {
    $rogueAco = $aco->find('first',array(
    'conditions' => array(
    'alias' => $alias,
    'parent_id' => $controllerNode['Aco']['id'],
    )));
    $aco->del($rogueAco['Aco']['id']);
    $log[] = 'Deleted Aco node '.$controllerNode['Aco']['alias'].'/'.$alias;
    }
    }
    }
    debug($log);
    }
    
    

    Until next time, Laterz