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:
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:
- If you don't have it already, download and install Putty or Cygwin for the ssh client
- Download VirtualBox for Windows Hosts. Based on this comparison of VMs, VirtualBox is the best choice for this application.
- Install VirtualBox. I installed version 4.1.12.
- Not knowing any better, I left all of the defaults selected. We'll soon see if that was the right choice.
- The install wizard proceeded as expected. Let it start VirtualBox.
- Download the latest Ubuntu ISO file.
- 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.
- Set up a new VM
- Click the "New" VM button, name it "Rails 3.2 on Ubuntu". Helpfully VB selects Ubuntu from the OS list.
- Memory: the default is 512Mb. Alan recommends 384. Since I have 3Gb available, I'll splurge on 512Mb.
- Virtual Hard Disk: create a new 8Gb disk.
- Virtual Disk Creation Wizard: leave the default "VDI" selected as recommended
- Virtual Disk Storage Details: leave the default "Dynamically allocated" selected as recommended
- Virtual Disk File Location and Size: leave the default values selected
- Review the Summary, then click Create
- File -> Virtual Media Manager
- Select CD/DVD Images
- Add the Ubuntu ISO image
- click Close
- Select the new VM image -> Settings
- Storage
- Storage Tree: Select IDE Controller -> Empty
- Attributes: click the tiny little CD image to right of the "CD/DVD Drive" dropdown and select the ubuntu ISO image
- Network
- Select Adapter 2 tab
- Check Enable Network Adapter
- Select Host-only Adapter
- Click OK
- Start the VM, then select "Install Ubuntu".
- Let the Ubuntu installer do its thing, then reboot the VM.
- After the VM reboots, install guest additions to get shared folder?
- Install samba (Windows file sharing)
- sudo apt-get install samba samba-common
- sudo apt-get install python-glade2
- sudo apt-get install system-config-samba
- Open Samba Server Configuration from Ubuntu desktop -> Dash home -> Applications -> Samba
- In Samba Server Configuration, select File -> Add Share -> Basic
- Directory: /home/[your name]
- Leave share name and description as is
- Select Writable and Visible
- On the Access tab, select Allow access to everyone. You'll still have to logon as the user from Windows
- In Preferences -> Server Settings,
- change the workgroup name to your PC's workgroup name. You can find the Windows workgroup name in the Windows "System" control panel
- Leave all of the other settings at their defaults.
- In Preferences -> Samba Users, you might have to set the Samba password for the user account
- Close Samba
- In windows, browse to \\server\user (e.g. \\ubuntu\philip), then enter the username/password when prompted
- Install Open SSH Server
- sudo apt-get install openssh-server
- ssh from Windows desktop via Cygwin or Putty: ssh you@your_ubuntu
- Create a .bash_profile file to source .bashrc for aliases, etc. when you log in via ssh:
if [ -f ~/.bashrc ]; then
. ~/bashrc
fi - Dev setup
- Install aptitude (if needed): sudo apt-get install aptitude
- 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
- Install rvm (Ruby Version Manager)
- curl -L get.rvm.io | bash -s stable
- Reload shell (or close and reopen it): source ~/.bash_profile
- Add rvm setup to .bashrc file:
- if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then source "$HOME/.rvm/scripts/rvm" ; fi
- Install Ruby and Rails. Insert the latest version numbers:
rvm install 1.9.3 && rvm --default ruby-1.9.3 && gem install rails sqlite3 - Smoke test:philip@ubi:~$ ruby -v && rails -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
Rails 3.2.3 - Create a Rails test site:
- mkdir ~/sites && cd ~/sites
- rails new rails_app && cd rails_app && rails s
- Browse to http://yoursite:3000/, if all goes well you'll see the default Rails home page
- 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, - 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:
=> Booting Thin
First, you might have to do this to install thin on Windows:
gem install eventmachine --preThen add the line gem 'thin' to your Gemfile to make Thin the default server when you run rails s, et voila:
gem install thin
thanks to frogz
=> 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
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?
Or it may become just a footnote in web history - anyone remember ColdFusion?
1949 torus for fusion experiments, Clarendon Laboratory, Oxford courtesy Robin Stevens
Wednesday, March 28, 2012
Rats in the attic
Sometimes you have to deal with the rats in the attic.
A coworker dropped by to brainstorm a perplexing problem he noticed in the report he was working on. The report is a PDF document generated from XML using XSLT and Apache FOP. An index table appears on the last page of the report, listing the name and page number of each section in the report. All of the sections were listed with the correct page number, except the section output on page 2 of the report, which the index showed as starting on page 1.
After tracing through the legacy XSLT code for a couple of minutes, we realized that the section start was flagged in the XSL-FO code in an "invisible" table that happened to come out at the very bottom of page 1, forcing the "visible" table over to page 2. Thus the table of contents correctly but deceptively showed the section starting on page 1. The code base that generates this report is several years old, and it has gone through multiple hands, as such code often does, so we had no idea why the original designers chose to output the section start flag in this way.
We came up with a couple of possible fixes he could to try, like eliminating the "invisible" table and moving the flag into the visible table, or if the invisible table was really necessary, apply a "keep with next" attribute so it would always stick to its corresponding section.
My coworker then said the problem reminded him of a scene from Bad Boys 2 (caution, link is not PG or SFW!), wherein Cuban drug lord Johnny Tapia, crawling through the attic where he stashed a mountain of stolen cash, discovers a nest of huge rats gnawing through the piles of loot. After blasting the rats with a cannon-sized revolver, Tapia exclaims to his henchman, "Carlos, this is a stupid f****ing problem to have, but, it is a problem, nonetheless!"
A coworker dropped by to brainstorm a perplexing problem he noticed in the report he was working on. The report is a PDF document generated from XML using XSLT and Apache FOP. An index table appears on the last page of the report, listing the name and page number of each section in the report. All of the sections were listed with the correct page number, except the section output on page 2 of the report, which the index showed as starting on page 1.
After tracing through the legacy XSLT code for a couple of minutes, we realized that the section start was flagged in the XSL-FO code in an "invisible" table that happened to come out at the very bottom of page 1, forcing the "visible" table over to page 2. Thus the table of contents correctly but deceptively showed the section starting on page 1. The code base that generates this report is several years old, and it has gone through multiple hands, as such code often does, so we had no idea why the original designers chose to output the section start flag in this way.
We came up with a couple of possible fixes he could to try, like eliminating the "invisible" table and moving the flag into the visible table, or if the invisible table was really necessary, apply a "keep with next" attribute so it would always stick to its corresponding section.
My coworker then said the problem reminded him of a scene from Bad Boys 2 (caution, link is not PG or SFW!), wherein Cuban drug lord Johnny Tapia, crawling through the attic where he stashed a mountain of stolen cash, discovers a nest of huge rats gnawing through the piles of loot. After blasting the rats with a cannon-sized revolver, Tapia exclaims to his henchman, "Carlos, this is a stupid f****ing problem to have, but, it is a problem, nonetheless!"
Wednesday, February 15, 2012
Subscribe to:
Posts (Atom)