Friday, April 27, 2012

Where is my Cygwin whereis?

THE useful whereis command was AWOL from my most recent Cygwin install. As blog.arithm mentions you can this and many more Unix-y commands from the util-linux package, "a suite of essential utilities for any Linux system":
addpart, agetty, blockdev, cal, cfdisk, chfn, chkdupexe, chrt, chsh, col, colcrt, colrm, column, ctrlaltdel, cytune, ddate, delpart, display-services, dmesg, elvtune, fastboot, fasthalt, fdformat, fdisk, flock, fsck.cramfs, fsck.minix, getopt, halt, hexdump, hwclock, initctl, ionice, ipcrm, ipcs, isosize, kill, last, line, logger, login, look, losetup, mcookie, mesg, mkfs, mkfs.bfs, mkfs.cramfs, mkfs.minix, mkswap, more, mount, namei, need, newgrp, partx, pg, pivot_root, provide, ramsize, raw, rdev, readprofile, reboot, rename, renice, reset, rev, rootflags, script, scriptreplay, setsid, setterm, sfdisk, shutdown, simpleinit, swapoff, swapon, taskset, tailf, tunelp, ul, umount, vidmode, vipw, wall, whereis, and write

Friday, April 13, 2012

iPads

Usually I'm the only one reading an iPad on my daily bus commute. This morning, I spotted no fewer than three other guys (yes, guys) tapping away on various iPad models. Steve Jobs must be smiling down from Heaven.

Wednesday, April 11, 2012

Parsing Large XML Documents in Ruby

Bill Rawlinson tells how in Parsing Large XML Documents in Ruby. The takeaway: use Nokogiri despite the state of its documentation. Bill gives us an example code listing as well. Thanks.

Gmail: how to remove "on behalf of" from sender name

I use my Gmail account to send email from my philip@psteiner.com email account, but I noticed the recipient sees it as sent from me "on behalf of" my Gmail account, i.e.
From: dontusethisemail@gmail.com on behalf of Philip Steiner <philip@psteiner.com>
The tricky thing for me is that my psteiner.com domain is hosted on Google Apps, so I have no mail server available at the psteiner.com domain, nor do I want to pay bucks every month just for this service - at least not when Google can provide it for free.

Luckily Steve Mould over at LifeHacker was generous enough to share his solution for configuring Gmail to use Google Apps as the outgoing mail server. Huzzah!

How to configure cygwin to use ctrl + arrow to move cursor a word at a time

TruMaze points the way to DOS box fumble-finger compatibility

Tuesday, April 10, 2012

Curses, Cygwin! Let's be clear...

Out of the box Cygwin doesn't include the 'clear' command. Hmm. Install ncurses to get it. Then add alias cls='clear' to your .bashrc or .bash_profile. Also learned bash responds to Control-L to clear the screen.

Sunday, April 8, 2012

Rails 3 on Ubuntu 11.10 on VirtualBox VM on Windows 7

Okay, so Rails runs pretty well for development on Windows 7 using RailsInstaller, but you're still running in a Windows environment. This is apparently now tolerable, but still not recommended, for two-fisted Rails development. I figure the best approach is to set up a development environment that's similar to the deployment environment. The defacto commercial Rails stacks now consists of some Linux distro, Passenger, Rails, MySQL and Git, so that's what I'll approach in this setup.

In the spirit of (and cribbing from) notes that Alan D. Jackson made while setting up Rails 3 on Windows with Ubuntu on a VM, here's my experience doing the same thing:
  1. If you don't have it already, download and install Putty or Cygwin for the ssh client
  2. Download VirtualBox for Windows Hosts. Based on this comparison of VMs, VirtualBox is the best choice for this application.  
  3. Install VirtualBox. I installed version 4.1.12.
    1. Not knowing any better, I left all of the defaults selected. We'll soon see if that was the right choice.
    2. The install wizard proceeded as expected. Let it start VirtualBox.
  4. Download the latest Ubuntu ISO file.
    1. Hrm, first question. I'm running Windows 7 64-bit, so I guess that means I want 64-bit Ubuntu? I don't know, the VirtualBox setup wizard lets me select either 32- or 64-bit. However, the Ubuntu download page recommends 32-bit. I'll go with the 32-bit for now.
  5. Set up a new VM
    1. Click the "New" VM button, name it "Rails 3.2 on Ubuntu". Helpfully VB selects Ubuntu from the OS list.
    2. Memory: the default is 512Mb. Alan recommends 384. Since I have 3Gb available, I'll splurge on 512Mb.
    3. Virtual Hard Disk: create a new 8Gb disk.
    4. Virtual Disk Creation Wizard: leave the default "VDI" selected as recommended
    5. Virtual Disk Storage Details: leave the default "Dynamically allocated" selected as recommended
    6. Virtual Disk File Location and Size: leave the default values selected
    7. Review the Summary, then click Create
  6. File -> Virtual Media Manager
    1. Select CD/DVD Images
    2. Add the Ubuntu ISO image
    3. click Close
  7. Select the new VM image -> Settings 
    1. Storage
      1. Storage Tree: Select IDE Controller -> Empty
      2. Attributes: click the tiny little CD image to right of the "CD/DVD Drive" dropdown and select the ubuntu ISO image
    2. Network
      1. Select Adapter 2 tab
      2. Check Enable Network Adapter
      3. Select Host-only Adapter
      4. Click OK
  8. Start the VM, then select "Install Ubuntu".
  9. Let the Ubuntu installer do its thing, then reboot the VM.
  10. After the VM reboots, install guest additions to get shared folder?
  11. Install samba (Windows file sharing)
    1. sudo apt-get install samba samba-common 
    2. sudo apt-get install python-glade2
    3. sudo apt-get install system-config-samba
    4. Open Samba Server Configuration from Ubuntu desktop -> Dash home -> Applications -> Samba
    5. In Samba Server Configuration, select File -> Add Share -> Basic
      1. Directory: /home/[your name]
      2. Leave share name and description as is
      3. Select Writable and Visible
      4. On the Access tab, select Allow access to everyone. You'll still have to logon as the user from Windows
    6. In Preferences -> Server Settings, 
      1. change the workgroup name to your PC's workgroup name. You can find the Windows workgroup name in the Windows "System" control panel
      2. Leave all of the other settings at their defaults.
    7. In Preferences -> Samba Users, you might have to set the Samba password for the user account
    8. Close Samba
    9. In windows, browse to \\server\user (e.g. \\ubuntu\philip), then enter the username/password when prompted
  12. Install Open SSH Server
    1. sudo apt-get install openssh-server
    2. ssh from Windows desktop via Cygwin or Putty: ssh you@your_ubuntu
    3. Create a .bash_profile file to source .bashrc for aliases, etc. when you log in via ssh:
      if [ -f ~/.bashrc ]; then
          . ~/bashrc
      fi
  13. Dev setup
    1. Install aptitude (if needed): sudo apt-get install aptitude
    2. Install basic packages: sudo aptitude -y install curl git-core build-essential zlib1g-dev libssl-dev libyaml-dev libreadline5-dev sqlite3 libsqlite3-dev autoconf automake nodejs
  14. Install rvm (Ruby Version Manager) 
    1. curl -L get.rvm.io | bash -s stable
    2. Reload shell (or close and reopen it): source ~/.bash_profile
    3. Add rvm setup to .bashrc file: 
    4. if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then source "$HOME/.rvm/scripts/rvm" ; fi
  15. Install Ruby and Rails. Insert the latest version numbers:
    rvm install 1.9.3 && rvm --default ruby-1.9.3 && gem install rails sqlite3
  16. Smoke test:philip@ubi:~$ ruby -v && rails -v
    ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
    Rails 3.2.3
  17. Create a Rails test site:
    1. mkdir ~/sites && cd ~/sites
    2. rails new rails_app && cd rails_app && rails s
    3. Browse to http://yoursite:3000/, if all goes well you'll see the default Rails home page
  18. Make Rails faster! Edit this setting in ~/.rvm/rubies/ruby-1.9.X-pXXX/lib/ruby/1.9.X/webrick/config.rb to speed up browsing the rails app from the Windows host:# :DoNotReverseLookup => nil,
    :DoNotReverseLookup => true,
  19. Now the app can be edited from the Samba share on Windows.

Tuesday, April 3, 2012

How to replace WEBrick with Thin for Windows development

WEBrick still seems awful slow on Windows. Last time I played with Rails, Mongrel was the goto replacement for WEBrick. Alas, Mongrel's no longer supported. So then I learned Thin is the new Mongrel. Here's how to get it working on Windows:

First, you might have to do this to install thin on Windows:
gem install eventmachine --pre
gem install thin


thanks to frogz
Then add the line gem 'thin' to your Gemfile to make Thin the default server when you run rails s, et voila:
=> Booting Thin 
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

Monday, April 2, 2012

Rails: How to kill WEBrick 1.3.1 on Windows 7

This worked for me, using RailsInstaller on Windows 7 - launch the WEBrick process into a separate command window by using the start command:

C:\Sites\myapp>start "rails" rails s


This will open a new command window entitled "rails - rails s", running the WEBrick process, leaving the original command window available for use. 

When you're ready to kill WEBrick, just close the "rails" command window. Brutal, but effective. 

Is Node.js the next Big Next Thing?

Andrew Chen explains that Node.js might be poised to be the next Big Next Thing for web apps. He asserts that "Rails, PHP and Visual Basic were all successful because they made it easy to build form-based applications," and if the Node.js community can make something as easy as How to build a blog engine in 15 min with Rails, then it may pick up real traction.

Or it may become just a footnote in web history - anyone remember ColdFusion?


1949 torus for fusion experiments, Clarendon Laboratory, Oxford courtesy Robin Stevens