Monday 9 July 2012

SSH into EC2 server

Here's how to mount a remote filesystem and use it as if it were local, using sshfs in bash to an EC2 server using a pem file (note: replaceable options in CAPS_AND_UNDERSCORES):

mkdir <MY_PATH>

sshfs -o IdentityFile=<PATH_TO_PEM_FILE>  EC2_USERNAME@<EC2_IP_OR_DOMAIN_NAME>:/<OPTIONAL_FOLDER_PATH>  <MY_PATH>



This will mount the remote filesystem to <MY_PATH> and allow you to do your file transfers. Of course permissions still matter, so keep those in mind if you start having write-protect errors.


To unmount from the remote filesystem:

umount <MY_PATH>

Friday 29 June 2012

jQuery Conference 2012 San Francisco

John Resig created something amazing 6 years ago.

A javascript library that would reduce the pain of programming websites; that would on all browsers. Instead of writing and maintaining separate branches of code to run in different browsers, developers could write one version of their javascript that would just work.

For anyone who's had to debug cross-browser issues, this was like showing us the path to The Promised Land.

Throw in some syntactic sugar, add convenience methods, and add some pretty awesome tools to handle asynchronous programming challenges, and you have jQuery only 6 years later -- the de facto javascript library for every browser and every platform

Today, I'm at the second day of jQuery Conference 2012 in San Francisco with 600 fellow coders. After a marathon day yesterday that went on until the hackathon ended at 10pm, here's some of the highlights:

  • jQuery 1.9 will be released in early 2013
  • jQuery 2.0 will be released in early 2013
  • what's the difference? Well, 2.0 no longer supports IE6, IE7 or IE8! It is promised to be smaller, faster, and smarter. Need to support IE6/7/8? Keep using 1.9. The API's will be identical, so you can simply conditionally load 1.9 or 2.0.
  • thanks to shorter codepaths to querySelectorAll and matchesSelector, the Sizzle selector engine has made a 5-10% improvement in overall speed, which is great, because that's where most time is spent.
  • Sizzle's find('#byId') function has achieved a 300% improvement in speed!
  • might be wrong here, but I think that it's the node.js grunt build system that is used to slim down the jQuery.js file so you can removed modules that you don't use; anyways, documentation is in the README
  • on that note, there's some improved support for hand-rolling customized versions of jQuery so you can weed out what you don't need. Be sure to check out the alpha at http://jquerymobile.com/download-builder to hand-roll your own jQueryMoble.js file. Modularity!
  • jQueryMobile has faster listviews, and a new highly flexible popup data-role
  • jQuery-ui 1.9 will have an accordion, autocomplete, tabs, better menu items, tooltips, and a spinner (numerical chooser)

Finally, consider joining the jQuery Foundation. As we all know, free software isn't really free, and a buck or two from each of us 7,000,000 developers who visit http://api.jquery.org each month surely get a boost in their daily productivity at work, so why not give back a bit?

Or, better yet, convince your boss to pay for it and plant a cool jQuery sponsor icon on your website.

Monday 4 June 2012

Lenovo W520 Thinkpad Review

I bought this laptop a few months ago, mainly because of its full-sized keyboard and its reputation for quality. Here's some notes if you're considering one.

First, a few details. I got a dual-drive RAID-ed model, with the second drive in the DVD drive bay. It's got a quad-core i7, and takes up to 32GB of RAM. Crazy. I ordered it with 4GB of RAM, and bumped it up to 16GB of RAM after purchase. 32GB is a crazy amount of memory, and those 8GB sticks are quite expensive right now. I did splurge for a 128GB SSD drive that fits into a peripheral mSata slot, once shipped to Canada it was about $200. I renstalled Windows 7 on it and it smokes.

The biggest problem I have with Windows 7 on this machine is that it often fails to come out of sleep mode. I'll be moving to a Debian Linux very soon, though I'm not confident this problem will disappear.

The biggest plus is that with the SSD, the battery lasts eight hours. The screen is great. The keyboard is awesome, though I can't understand why the lower left corner Fn and Ctrl keys are reversed (there is even a BIOS option to revert these to normal). Some sort of IBM legacy strangeness happening here.

The weirdest feature is how much the battery sticks out of the back of the machine, a full inch. It hasn't really been a problem for me, but it is something to pay attention to when buying a sleeve or bag.

The fan hardly ever comes on, and my hard drives hardly ever spin, because I'm working off the SSD the majority of the time. I've read complaints about fan noise and heat, but I have not experienced any of this. Quite the opposite, it's cool and quiet. (Disclosure: last laptop a Dell 6400 15.4", for about 7 years, and my only laptop. Loved it, replaced the mousepad and three keyboards, but it still works fine. Though it never bothered me the Dell got hot and the fan blew often.)

In time, I imagine I'll replace the two RAID-ed spinning drives with SSDs, but I've put enough money into it for now. I feel like the capacity of this machine has me ready for another decade of laptop computing, and I am quite happy with my purchase.

I have read some negative reviews of Lenovo products, and the W520 in particular, before I purchased it, so just wanted to put this out there. I'm not a fanboy or an employee, just a programmer who was looking for a kick-ass machine. In my opinion, the W520 is it.

Sunday 11 March 2012

Thinkpad W520 x64 install USB3.0

Summary: Steps to ThinkPad Windows7 clean install through USB3.0 port.

I decided to upgrade laptops, and since I want to run a few VMs and I also want to see what all the SSD craze is all about, I ended up getting a ThinkPad W520. Quad core hyperthreaded to eight virtual cores with an Intel i7, capable of holding 32GB of RAM in 4 slots, and also able to hold an mSATA SSD drive to run your OS. Geek heaven, I'm sold. I upgrade the networking card, add bluetooth, and decide to forego the optical drive so I can have RAID 1 data protection (that's two mirrored hard drives, with one in a caddy where the DVD drive usually goes).

I make the backup recovery disks with the ThinkVantage tool, and then I decide to test the backup, figuring I have no data to lose. Good thing, since the recovery utility seems to work but after using it I boot into a black screen. Re-attempts to use the recovery disk all end in black screen. My brand new ThinkPad is dead.

No big deal, I think, I'll just do a clean install and forget about the Lenovo recovery partitions, since I'll dual boot this with Linux anyhow. So I burn Windows7 to a bootable USB, and during Windows install get "a CD/DVD drive device driver is missing" error. Most people who get this recreate their install DVD or USB, and it works the second time, so I think it must be a corrupted install disk. But every time I attempt to reinstall Windows7 from a fresh bootable USB key, I get the "CD/DVD drive device driver is missing" error. There is some talk of creating an x64 boot drive on a 32-bit machine. I download bootsect.exe and put it in the Windows bootable USB tool directory as advised, but still no luck.

Others say to switch the USB port around if this fails until it works. See, most people have a combination of USB2.0 and USB3.0 ports on their machines. So if they get this error, they move the USB plug around until they hit a USB2.0 port, and the install proceeds swimmingly. Not the W520. All ports are USB3.0. And it turns out that the Windows7 installation disk does not have USB3.0 drivers.

So after many hours of fiddling, I had to make a custom Windows install disk. Here's what worked for me:

  • download the beta of RT Seven Lite for your architecture. I am on x86 so 32-bit, although I am making x64 boot disk.
  • install RT7Lite
  • Lenovo has a USB3.0 driver you'll need, and a WLAN driver (or maybe Ethernet if you're going to hard-wire your network connection) that are the minimums you'll need. Run the .exe files, and accept the default folders of just put them into the same folder you used just above. It will extract the files, and then say done, with an option to install the drivers. Uncheck the checkbox and click finish.
  • start up RT7Lite from your desktop. Click the "browse" button, point it to your Win7 ISO (if you only have an IMG file, rename it's extension to .iso), and then point it to a folder to store some temporary files in. Let it do it's stuff for a while. Then select the "Integration" checkbox. Click on the "Integration" button on the left, then select "Add" and add drivers. Now navigate to the folders that the two drivers you just downloaded and uncompressed are in. There should be two .inf files in the USB3.0 driver folder (\x64\), and two .inf files in the WLAN driver folder (\Win7\S64\Drivers\). "Add" the four files to RT7Lite.
  • click on the Apply button, then on Commit. Let the app do its magic. This takes a long time, and the progress hangs. Once it's done there will be a green checkmark next to the "Finished" stage.
  • at the end, click on the ISO-Bootable button on the left, and then burn it to a medium. At this point, if you are on a 32-bit system, you will have to burn a DVD image, then hook up the DVD with some external wires which you can get for $20 from the computer shoppe. (This is what I did) A 32-bit system with the USB option fails at this point with an x64 warning. If you can do all this stuff on a 64-bit system, you can make the USB. 64-bit machiens can select Mode "USB Bootable", and select your connected USB Device. Click on USB button. 
  • whichever option you choose, this will take a while.
  • meanwhile, download the ThinkVantage System Update. It will install all the driver updates you'll need. Just install and run this app once installation is complete, it is much easier than downloading drivers one at a time.

Now that I'm done, my boot time to home screen went from 1:10 to 0:45. This is a crude measurement since it includes login credentials time. 

Hope this helps.

Still lost? This blog helped me.

Tuesday 6 March 2012

yii mobile - Part 1

I'm working on a new project, Pressimus, which is built on the yii framework.

As a relatively young framework, yii documentation is a bit sparse, so I'm publishing this in hopes of helping others, and hopefully eliciting commentary to improve my design. So if you know better than me, please tell me!

Without further ado...

yii mobile strategy

There is a fair bit of planning and consideration in creating a mobile strategy for your site. I have done this for a mature website, which is a whole different ball of wax. Here we're going to start fresh, and if the question is "What should my mobile strategy be?", the answer is "it depends". Saying all websites are the same is like saying all houses are the same. They aren't.

The main consideration is: mobile web, or native app? I'm going to concentrate on building a web version of a site now, but this is the biggest question you'll face. Google it to find reams of discussion.

Taking a linear approach into the web app, you'll first want to know if your users are using a mobile device or not. A very simple regex-based approach is used by the yii extension detectmobilebrowser.

Simply add the following into the components array in public_html/protected/config/main.php file:

'detectMobileBrowser' => array(
'class' => 'application.extensions.yii-detectmobilebrowser.XDetectMobileBrowser',
),

Since I put the extension file XDetectMobileBrowser.php into the public_html/protected/extensions/ folder under its own folder, yii-detectmobilebrowser, I changed the classpath from the one listed on the extension's tutorial to application.extensions.yii-detectmobilebrowser.XDetectMobileBrowser.

Then, in controllers/SiteController.php, I have added the detection call in the init() method:

public function init(){
if (Yii::app()->detectMobileBrowser->showMobile) {
//$this->layout='//layouts/mobile';
Yii::app()->session['isMobile'] = 1;
} else {
Yii::app()->session['isMobile'] = 0;
}
}


Now, you can draw this from your session variable.    

Considerations at this point: 
  1. If you need to know more than a browser type (like screen size, resolution, camera support, etc.) then you can consider the WURFL library, which has recently and controversially become commercial. The incredible Apache Software Foundation (A has recently accepted an incubator called DeviceMap that will be a mobile browser capability detection library that will remain open source, and is probably the one you'll want to use and contribute to going forward, if you want to avoid the commercial licencing and associated fees. This one'll be done right, knowing the big brains behind the ASF.
  2. What should you do when a browser is mobile? Immediately connect to the mobile site? Go to a "choose preferred site version" screen? There are many permutations here: for example, what if a mobile site is a stripped-down version of the main site, and the user wants full-site functionality and you've forced them into the mobile site?  I won't go one here but each site will have to carefully consider it's use cases here.

Next time: we'll create a yii mobile theme!

Sunday 4 March 2012

Hello World!

I work as a software developer. I have been educated as a computer scientist at UBC.

I often find myself going to the web for information, and hope this will do a bit to give back to the fantastic online developer community. When I think about Computer Science, I often think of an old REM lyric: "Standing on the shoulders of giants, leaves me tall". (Yes, I changed the last word.)

So here goes, my first blog...