crshman's Profile Page

Tag-Archive for » Programming «

Saturday, September 11th, 2010 | Author:

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!

Category: Development  | Tags: ,  | Comments off
Tuesday, September 08th, 2009 | Author:

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!

Category: Development  | Tags: ,  | Comments off
Thursday, August 06th, 2009 | Author:

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

Category: Development  | Tags: ,  | 3 Comments
Wednesday, July 29th, 2009 | Author:

Hey All,

Well I’ve been baking a lot of cake lately, and I’ve started to delve into the core a little….it’s not all that scary…kinda haha.

This post is being made in response to the infamous:

Warning (512): Cache not configured properly. Please check Cache::config(); in APP/config/core.php [CORE/cake/libs/configure.php, line 663]

I believe I found a fix/solution for this, and from what I can tell it’s quite portable (you can use it across different installations). This solution would be used in conjunction with providing the proper credentials to your cake installations “tmp” folder and all it’s sub-directories so that your web server can get down to business.

Open up your core.php file and look for the following at the end of the file:


Cache::config('default', array('engine' => 'File');

and replace it with


Cache::config('default', array('engine' => 'File', 'path' => ROOT.'/app/tmp'));

That should do it!

Until next time, l8rz!

Category: Development  | Tags: ,  | 4 Comments
Thursday, April 23rd, 2009 | Author:

Hey All,

So I have an account over at JaguarPC and I love it a lot there, they support everything I need and help me with all that I ask. However, there seems to be a snafu/caveat what have you to running RoR (Ruby on Rails) apps at JPC. cPanel runs RoRs apps using a mongrel instance, this is fine and it works….but sometimes it dies and needs to be restarted. Highly annoying….I run my redmine installation off of one of these mongrel instances and I really can’t have it be down. So….I devised this little gem below to check if your mongrel instance is down, if so to restart it.

To use the script throw it in your cPanel root and add the following line to your crontab:


*/5 * * * * php ~/reboot.php

Be sure to update the command above to reflect what you named the script…..

Hopefully someone else finds it useful and if you need help with the script comment!

cPanel Ror Mongrel Reboot


<?php
/*
 *
 * cPanel Mongrel Rebooter - v0.1
 * Author: Robert Navarro <[email protected]>
 *
 */

/*
 * The siteCheck function has the following parameters
 *
 * $url - This is the url of the application you want to check
 * $searchString - This is the erroneous string you want search the site for
 * $appPath - This is the full path to your cPanel RoR app installation
 * $appPort - This is the port that your cPanel RoR app runs on
 *
 * You can find the application port by running:
 * # ps aux |grep mongrel |grep <your username>
 *
 */
siteCheck("http://<my redmine install>","502 Proxy Error","~/Sites/<my redmine install>/","12001");

function siteCheck($url,$searchString,$appPath,$appPort) {
 // open the remote URL for reading
 $fp = fopen($url, 'r') or die('Unable to open file '.$off_site.' for reading');

 $buffer = '';

 // read in chunks
 while(!feof($fp))
 {
 $buffer .= fgets($fp, 4096);
 }

 // strip HTML but leave the tags you want
 $output = strip_tags($buffer,'<a>
<ul>
	<li>
<h2>
<h1><span>');

 // convert all whitespace, tabs and newlines into one single whitespace
 $output = preg_replace('/\s+/', ' ', $output);

 if(strstr($output,$searchString)) {
 restart($appPath,$appPort);
 }
}

function restart($path,$port) {
 exec("cd $path;mongrel_rails start -p $port -d -e production -P $path/log/mongrel.pid");

}
?>

Category: Development  | Tags:  | 5 Comments