public var blog:Object = {name:"chad's musings"};

Feb 14

Booting OS X with Grub2

I installed Ubuntu on a Mac Mini at work and needed to get back into OS X for some testing.  The default configured Grub entries wouldn’t load for OS X (hd0, part0).  After looking over the net and digging through lines and lines of Grub conf I found a little blurb from another user saying they’d tried this and it worked… so if you’re beating yourself up over OS X and Grub2 give this a try and see if it works… it did for me.

open up your Grub2 conf file, which in Ubuntu is located at

/boot/grub/grub.cfg

Then at the bottom of the menu entries I added:

menuentry "Mac OS X (Custom/Bootable)" --class osx --class darwin --class os {
        set root=(hd0,0)
        exit
}

This entry gets me booted into rEFIt at which point I can properly boot into OS X Lion without issues.  From this point forward the machine will default into rEFIt until you choose to boot into Linux again… which will push you back into Grub2 for future boots.

“If it’s stupid but it works, it isn’t stupid.”

Note: I’d already installed and had rEFIt running from the previous Ubuntu install

Dec 15

Bash’isms (SVN+Awk+Grep+Cut+Bash one liners)

A couple bash 1 liners I threw together recently that I’ve found to come in very handy so I thought I’d share.

The back story is simple, yearly reviews, talk about what you’ve done, yadda yadda yadda.  Well, I don’t remember honestly. I’ve done A LOT.  That’s not going to fly in a serious meeting with “The Bobs”.  So I needed a way to look over my years work, as a refresher of little and big projects alike.  No problem SVN to the rescue… but our SVN has a lot of developers, and several commits per day of new features, bug fixes, tweaks, etc. After consulting the SVN docs I was pretty shocked to find no way to pull logs based on the user submitting said changes… one would expect something along the lines of:

svn log -uchad

And one would be wrong in assuming such a feature exists.  Some Google time turned up convoluted and down right ugly solutions.  I decided to have a go at it with my bash-fu… for practice and profit.  Below is an easy way using a couple common *nix tools to get the info you want fast and easy. In the following examples data you’ll need to replace will be wrapped in %’s with example data in []’s (e.g. %username[chad]%)

Get all svn commits for a given username:

svn log | grep '| %username[chad]%' | cut -d' ' -f1 | awk '{print "svn log -"$1}' | bash 

Get all svn commits for a given username in a year/month/day:

svn log | grep %date[YYYY-MM-DD]% | grep '| %username[chad]%' | cut -d' ' -f1 | awk '{print "svn log -"$1}' | bash 

Get all modified files for a users commited for a day/week/etc.:

svn log | grep %date[YYYY-MM-DD]% | grep '| %username%' | cut -d' ' -f1 | awk '{print "svn log -v -"$1}' | bash | grep %files['/trunk']%

Jul 19

GrooveShark App (kind of) [Linux, Chrome]

I love GrooveShark, I love them so much that I looked for a stand alone app without much luck.  I usually just ran it in a background Chrome instance but I just wanted to be able to click a button and have all my Groovy goodness without tabs, or address bars, etc.

It took about 10 minutes, but here it is, super simple.

Step 1: Install Google Chrome 

(http://www.google.com/chrome/)

Step 2: Setup launcher with the -app flag

    /path/to/google-chrome -app=http://grooveshark.com
    example:
    /opt/google/chrome/google-chrome -app=http://grooveshark.com

This flag will cause Chrome to launch without common browser elements like the address bar, buttons, bars, etc.

Optional Steps: (for great justice)

Pick an icon for your launcher

May 14

Nexus S + MIUI + Netflix = Working

You’ll need root, and you’ll need a 2.3+ ROM installed.

In

/system/build.prop

You’ll have to edit the lines.

ro.product.model=[model_name_here]

ro.product.manufacturer=unknow

To 

ro.product.model=Nexus S

ro.product.manufacturer=samsung

Reboot the phone and install the Netflix app from the market or install the .apk manually from your sdcard.

For navigating to / and editing build.prop I suggest using ES File Explorer as it supports root, navigating to /system/ and writing to the file all in a single app.

Note: For safety sake you might want to copy an unedited version of build.prop to your sdcard (/mnt/sdcard/) for safe keeping should you need to revert back to the old file easily.

Protip: If you’re running a rooted device with a 2.3 ROM using these flags on your phone will make the Netflix app usable.

Apr 21

Ubuntu / Debian : List software from repository

This will list packages coming from a specific repository

grep <repository_name> /var/lib/apt/lists/* | grep tar | cut -d' ' -f4 | sort -u

Example

$ grep backbox /var/lib/apt/lists/* | grep tar | cut -d' ' -f4 | sort -u
aircrack-ng_1.1-1backbox1.debian.tar.gz
autotools-dev_20100122.1backbox1.tar.gz
backbox-about_1.2.tar.gz
backbox-artwork_1.6.tar.gz
...

Feb 18

Redirect user, hide referrer

Found a nice little way to trick browsers into redirecting users without passing a long associated referrer information.  Works in Chrome, IE6/7/8, and Firefox… sneaky sneaky sneaky.

For more info drop me a message in the comments.

Jan 04

VTech Pre-Computer Power Pad … I love thee.

VTech

My little cousins pulled out my VTech PreComputer Power Pad (the laptop looking version) while I was home this holiday at my Grandmothers house. I hadn’t seen the thing in years and was so happy to see it still around. I waited for them to get tired of it and sat down at the kitchen table to give it a go. It had been years and I recall one application but I couldn’t remember the name. It was the only one that would let you type and type and type, almost like a word processor, but you couldn’t save anything.

I always loved computers as a kid and when I was given this vtech I was a little disappointed. It was 1994, going on 1995 (christmas gift) and Windows 95 was coming out. My friends were playing solitaire, my uncle had a Mac PowerPC with full paint application and screen savers… and I was given a VTech. It played crossword puzzles, and math games, some basic trivia. Basically my 11 year old self saw it as a toy, capable of nothing more than making me a better student, but never teaching me about computers like I wanted to learn about them. I would go and hang out at office depot and circuit city just so I could play with the real laptops of the time with their spring loaded roller ball mouses, and tiny screens.

I recall hating mine, it was pointless… useless! I would still play on it, pretending to be a troubled lawyer, or possibly some form of hacker. I recall one day opening that “one word processor application” and typing gibberish in while pretending to be stealing top secret government files. When I pressed enter on the keyboard the screen lit up… it was lines and lines and lines of gibberish back, x’s, 0’s, #’s, and I was sure I had broken the thing, pulling the plug and restarting it fixed it right up, and I could never figure out what I had typed.

So now, 2011 is here, it’s been nearly 14 years since I was given my first VTech from my grandma and I sit down at her kitchen table to play with my old “toy” laptop that was “useless” for all those years. Something is different this time, I’m telling my little cousins that there is an application on here and you can just type whatever you want… it was the one I used the most as a kid. Then I realize it and a huge smile comes across my face. I look down at the buttons (applications) that you can press and I see one, almost in disbelief, it reads “BASIC”.

At this point I’m in disbelief, I press the button and sure enough the screen reads “BASIC HAVE FUN!”. This was IT, this was that application… and what’s even cooler, is now I’ve been working full time as a programmer since I was 20… and now I know what BASIC is! I immediately realize that this “useless” toy is far more powerful than I had ever realized as a kid! I sat there at that little laptop on a tiny screen only capable of displaying a handful of characters at time taking requests from my cousins and writing them little applications, there was a birth date calculator, a weight on mars calculator, a square footage calculator, I made special messages appear when they entered correct words when we played 21 questions.

That little VTech sparked my inner child again, and I’m still floored that I was given (and wasted) such a valuable tool as a child, I hope that I sparked the same interest in my cousins that day and they’ll spend as many hours playing with that little VTech as I did… but hopefully they’ll be able to grok BASIC and get a real head start on the “other kids” with their fancy WIndows 7 and OS X.

And that’s how I learned that I achieved my first buffer overflow at the age of 11… on accident.

Jul 23

Chrome Extension : Screenshots made sexy

 After browsing the Google Chrome extensions catalog I found this little gem.  If you’re in the business of taking screenshots of web pages (developer, designer, sharing funny stuff online, etc.) I highly recommend giving the “Awesome Screenshot” extension an install!.

download it here (https://chrome.google.com/extensions/detail/alelhddbbhepgpmgidjdcjakblofbmce)

Virtualbox & Windows 7 : Shared Folders

I’ve just recently installed Virtualbox on my Ubuntu machine and decided to set up a Windows 7 VM.  Once everything was complete it was time to enable shared folders so I could transfer some files to and from the VM.  Only 1 problem… I can’t find them?!

After a bit of looking around on the web I finally found a random user comment on a random blog that hinted at where they “might” be so I decided to put this article up for any future VB + Win7 users that are just as confused as I was.  Some people were suggesting installing FTP servers to the Windows install and even using Web services like Dropbox to move the files from the host machine to the VM. :/

First things first… create your folder on your system.

mkdir ~/VMShare

Add said folder to your VB shared folders list.

Once that is done you’ll open up your Win7 Network view.

Start > Computer > Network (in the left window pane)

And clicking on VBOXSVR will list your shared folders.

Now you’re sharing files easily.

Note: You’ll need to have the Virtualbox Guest Additions package installed in the VM for this to work properly.

Jul 21

Ubuntu 10.04 Netbook Remix : Disable UNR Launcher

I installed UNR in version 9.10 and immediately disabled the netbook launcher for the classic desktop.  This was easy in 9.10 thanks to a setting in the system preferences called “Desktop Mode Switcher”.  It was great, it was easy… and now it’s gone.

For whatever reason in 10.04 they decided to get rid of this handy little tool.  I had to purge some nautilus config files and all of a sudden, I was back to UNR launcher.  I couldn’t find my trusty switcher so I started looking around the web… people are going through 5-12 steps to get around this thing, many without full success.  I’m writing this in the hopes that _YOU_ the person reading this finds it before you go through 12 steps of tweaking config files. 

Step 1: Remove the netbook-launcher

sudo aptitude remove netbook-launcher

Step 2: Install regular ubuntu-desktop

sudo aptitude install ubuntu-desktop

Step 3: Restart Gnome

sudo service gdm restart

Step 4: Login using Gnome as your session

Done and done… hope this saves someone from a headache.

Jul 15

Quickly search your bash history using arrow keys

Add these lines to your /etc/inputrc to enable the functionality.

"\e[A": history-search-backward
"\e[B": history-search-forward

Thanks Reddit and Archwiki!
(http://wiki.archlinux.org/index.php/Bash)

p.s. this functionality is included in your inputrc file by default on Ubuntu 10.4 and can be used by uncommenting the lines (41 & 42), but rather than arrows it uses Page Up and Page Down.

Feb 18

9.10 + Google Chrome + Netbook = YES!

If you haven’t tried Google Chrome on *nix yet I highly recommend it.

Feb 08

str_replace & Fatal error: Only variables can be passed by reference

If you’re using a simple str_replace() call in PHP and getting a strange Fatal error that doesn’t make a whole lot of sense to you I have a hunch as to why.

Fatal example:

$file_name = str_replace('findit', 'replaceit', $haystack, 1);

In PHP 5.0.5 some changes were made to how PHP handles variables, functions, and references.  This broke a lot of older code but also introduced some vague and questionable fatal errors.  They meant well by doing this by essentially requiring parameters be passed via reference.  I’m assuming this was to prevent PHP from copying large pieces of data to work on them and thus helping memory performance overall. Luckily there is a simple fix, just declare your variable to be passed inline.

Working example:

$file_name = str_replace('findit', 'replaceit', $haystack, $count = 1);

Note: if you’re working with a large data set in a loop I would highly recommend setting the reference outside of the loop and avoid this inline method.

Jan 25

An effective JavaScript & CSS cache busting technique

Client side cache is both a friend and an enemy.  As many web designers and developers have learned in the past what it saves you in bandwidth is worth more than it’s share of headaches.  With that said one of it’s major headaches is old files on end users computers being used and breaking functionality.  This can be felt in layout as well as code (e.g. undefined function ‘do_important_stuff()’) if you’re newly modified files never make it to your end users.

There is an old trick that’s been around for a good while and helped this a bit, an old annoying and version tracking pain in the ass trick.  You would change your file names with each major revision (core.v1.js or member.v1.css) which would cause browsers on the client side to request and store the file thinking it was new.  From a design aspect it wasn’t to bad, from the version control aspect it wasn’t to bad, and from the implementation aspect it wasn’t to bad… but it was annoying.

Trying to move away from this you’d more than likely discover the GET variable hack.  Basically appending useless garble to the end of your file name (file.css?garble=1351341) would ensure your end users browser fetch the file from your server.  This was usually done with a variable in your source or more often than not a Unix time stamp.  A concern with this method arose in your bandwidth bill if you did it wrong.  Most people would just append the time stamp, and since it changes everyone second every single page load would cause yet another extra and pointless call to the server for the same old unmodified file.  As if that wasn’t already fugly and possibly expensive (depending on your traffic) it didn’t work in some versions of IE.

During a discussion on better ways to handle JavaScript cache busting with our head software engineer I came up with a fairly simple idea that I hadn’t thought of before… let the file bust it’s own damn cache! Basically using PHP and file system mtimes we should be able to not only make this problem null and void but we can fix it once and never look back.

Using a couple quick functions in PHP and a simple rewrite rule placed on the server we were up and running in no time. Some code snippets and explanations will follow.

PHP include function:

function javascript_include($file_name = null){
    if (empty($file_name)){
        return false;
    }

    $file = WWW_WEB_DIR.'/js/'.$file_name;
    $timestamp = 0;

    if ($file_exists($file)) {
        $timestamp = filemtime($file);
    } else {
        return false;
    }

    $script_url = "/js/$timestamp/$file_name";

    return "<script type=\"text/javascript\" src=\"$script_url\"></script>\n”;
}


Using PHP function:

<?=javascript_include('site_core.js')?>

Resulting output:

<script type="text/javascript" src="/js/135134134/site_core.js"></script>

Rewrite rule:

RewriteRule (.*)/[0-9]+/(.*\.js)$ $1/$2 [PT]

Summary:

So there you have it, completely automated and effective cache busting.  This works because browsers universally see the change in the directory structure and automatically assume it’s a new file causing an initial fetch of the file and caching it.  If you publish changes to that file the mtime on the file system of the server will be updated, therefore the next request to include said file will have a different directory structure.

Hope this helps others dealing with caching headaches.

Nov 24

Flex Security sandbox violation

Working in Flex and/or Flash you often run into the same problem many times and forget the easy and common sense answer.  Security sandbox violations for me is one of those cases.

Googling for answers is usually fruitless and starts talking about server side crossdomain.xml policy files and meta data.  These are important in the long run but what about when they’re in place and you’re just testing new client side code.  Well I’ve done this a few times now and EVERY time I do it I completely forget the quick and easy work around.  So if you’ve looked into the crossdomain.xml tutorials and everything is ship shape but you still can’t test from your local machine I suggest doing the following.

1. right click on any .swf file

2. choose “Settings…”

3. Privacy Tab

4. “Advanced…” button

this will load up an Adobe page that allows you to change and tweak global settings in Flash player that can only be done so there.  It’s pretty clutch.

5. click “Global Security Settings Panel” on the left side menu

6. click “Edit Locations…”

7. click “Add Locations…”

8. in the prompt window that comes up put /

9. click confirm

10. change radio button to “Always allow”

Wahlah… your local .swf files are now null and void as far as cross domain sandbox rules are concerned in the world of Flash player.

What you’ve essentially done here is tell Flash Player to ignore security rules for any files in your root files system.  If you’re security minded and run a lot of .swf files that you don’t trust locally I wouldn’t recommend this setting as it completely overrides security measures put in place to protect you.  You can also use the “browse” functionality to pick specific files which realistically is much safer from a security stand point.  I myself don’t worry about it because I don’t store any .swf files locally when it boils down to it.