Cogs and Levers A blog full of technical stuff

Rails 3 Cheatsheet

A cheatsheet of Rails 3 commands once all of the software infrastructure has been setup and is running.

Creating and destroying things

# Create a new application
rails new ApplicationName

# Create a new model
rails generate/g model ModelName

# Create a new controller
rails generate/g controller ControllerName

# Create a new migration
rails generate/g migration MigrationName

# Create a scaffolded controller, model and view 
rails generate/g scaffold ModelName ControllerName

# Destroy a new model
rails destroy model ModelName

# Destroy a new controller
rails destroy controller ControllerName

# Destroy a new migration
rails destroy migration MigrationName

Controlling the application

# Start the rails server
rails server/s

# Install a plugin
rails plugin install PluginName

# Start the rails console
rails console/c

# Start the database console
rails dbconsole/db

# Benchmark/Profile the application
rails performance

Manage the database

# Create the database
rake db:create

# Drop the database  
rake db:drop

# Migrate the database
rake db:migrate

# Drop and recreate database from schema
rake db:reset

# Rollback the latest migration
rake db:rollback

# Create the schema file
rake db:schema:dump

# Create a sessions migration
rake db:sessions:create

Utility tasks

# Build the RDOC html files
rake doc:app

# List all available tasks
rake –tasks

# Truncate log files
rake log:clear

# Clear session, cache and socket files
rake tmp:clear

# Print out all defined application routes
rake routes

Testing your application

# Run all tests
rake test

# Run functional tests
rake test:functionals

# Run integration tests
rake test:integration

# Run unit tests
rake test:units

Working with Gems

# Lock this application's gem set
rake rails:freeze:gems

# List dependent gems
rake gems

# Install all required gems
rake gems:install

# List all installed gems 
gem list

# Install a gem
gem install GemName

# Uninstall a gem
gem uninstall GemName

# Start the gem server
gem server

Installing UniVerse 10.3 (Personal Edition) on CentOS 6.3 amd64

A guide for installing the UniVerse database system on a RedHat flavored distribution.

Installation Pre-requisites

As the database server is being installed to a 64bit system, some 32bit libraries are required for the installation to succeed.

yum install glibc.i686 libstdc++.so.6 pam.i686

Running the installer

# Unpack the database installation into a temporary location.
unzip uvpe_rhlinux_10.3.3.zip

# Extract the uv.load script out of the archive
cpio -ivcBdum uv.load < ./STARTUP

# Set the date on the system to satisfy licensing requirements
date -s 1/1/2009

# Run the uv.load script
./uv.load

Completing the installation

Select the first option from the first menu:

1) Make 'root' the default owner and administrator of uniVerse.  
The current installation continues uninterrupted.  

On the second menu, change the rewind and no-rewind tape names to the location of the installation files.

4) Rewind tape name          /tmp/uvpe  
5) No-rewind tape name        /tmp/uvpe  

Starting the RPC daemon

Before attempting to start the RPC daemon from within the uv environment, an entry for the service itself needs to be added to the /etc/services file

echo "uvrpc 31438/tcp # uvNet rpc port" >> /etc/services  

References

Installing UniVerse on CentOS 6.2
http://u2tech.wordpress.com/2012/07/08/installing-universe-centos-6-2/

Burning Discs at the Console

A very short guide to burning CD and DVD media at the console with growisofs.

Control

Ejecting the drive

eject

Retracting the drive

eject -T  

Burning

Burn the contents of a directory

growisofs -dvd-compat -Z /dev/dvd -R -J -pad "/path/to/data"

Burn the contents of multiple directories

growisofs -dvd-compat -Z /dev/dvd -R -J -pad -graft-points "/foo=/path/to/foo" "/chu=/path/to/chu"

Burn an ISO to a disc

growisofs -dvd-compat -Z /dev/dvd=/path/to/image.iso

RW Burning

Formatting a RW disc for burning

dvd+rw-format -force /dev/dvd  

Appending data to a RW disc

growisofs -dvd-compat -M /dev/dvd -R -J -pad -graft-points "/foo=/path/to/additional/data"

Web Application Development with Flask

A brief guide to developing web applications with the python micro-framework, Flask.

Pre-requisites

The following units need to be installed prior to using this framework:

  • python
  • pip
  • virtualenv

Using Flask

Create the project folder, setup python environment

mkdir projname  
cd projname 
virtualenv env

From now on, activate the environment from within the project folder with this command:

$ . env/bin/activate

Install Flask

pip install Flask  

References

Flask websitehttp://flask.pocoo.org/

FreeBSD 9.0 installation on a T400

From time to time, FreeBSD has made its way onto my T400. Each time I do it, I never jot down what I did to get it to “work”. Here’s just a few thoughts and basic guide for installing FreeBSD RELEASE-9.0 on a Lenovo ThinkPad T400.

BIOS

The T400’s graphics mode needs to be switched from “Discreet” back to “Integrated”, otherwise the BSD installation process just continually reboots. The laptop will now allow a standard installation to be performed.

Post Installation

First things first. Stop the PC Speaker barking at you when you do something questionable (disable by adding this to /etc/sysctl.conf)

hw.syscons.bell=0

Some switches required for connection resilience need to be applied to the WiFi configuration (fix by commenting these lines from /etc/wpa_supplicant.conf)

# eapol_version=2  
# ap_scan=1  
# fast_reauth=1  

WiFi network entry should look as follows

network={  
	ssid="tuttle"  
	key_mgmt=WPA-PSK  
 	psk="secret-in-here"
}  

Add the full hostname to /etc/rc.conf

hostname="thor.local"  

Get the proc filesystem mounted at boot by adding the following line to /etc/fstab

proc   /proc  procfs  rw  0   0  

Organising the ports collection

In the interest of making the ports collection as “fresh” as possible, it’s best to remove the installed version and pull down the latest version over the web.

Remove the existing ports collection

cd /usr/ports
rm -Rf *  

Refresh the ports collection from an australian mirror. You can find full instructions here on this. Fetch the collection into /var/db/portsnap Extract the collection into /usr/ports

portsnap fetch
portsnap extract

From now on, to refresh ports just use the following command

portsnap update

Installation

Any port needed for installation is done with the following commands

cd /usr/ports/path/to/port  
make install clean  

bash (/usr/ports/shells/bash)

Set bash as the default shell for users by running the following

pw usermod user_name -s /path/to/bash  

sudo (/usr/ports/security/sudo)

Setup user groups who can sudo by editing the config

visudo -f /usr/local/etc/sudoers  

Uncomment the line allowing the wheel group

%wheel ALL=(ALL) ALL  

Add users who want to sudo to the wheel group

pw usermod user_name -G wheel  

Other pieces of software to make your environment feel more like home

vim (/usr/ports/editors/vim-lite)
git (/usr/ports/devel/git)
xorg (/usr/ports/x11/xorg)
xfce (/usr/ports/wm/xfce4)
gnome-keyring (/usr/ports/security/gnome-keyring)
gnome-power-manager (/usr/ports/sysutils/gnome-power-manager)
chrome (/usr/ports/www/chromium)
pidgin (/usr/ports/net-im/pidgin)
irssi (/usr/ports/irc/irssi)
evince (/usr/ports/graphics/evince)

Preferences

Set colourised output on ls by adding the following line to ~/.bash_profile

alias ls='ls -G'

Get bash_profile to execute bashrc if it exists by adding the following line towards the top to bash_profile

test -f ~/.bashrc && . ~/.bashrc  

dbus and hald need to be started at boot time if a mouse/keyboard is going to be used within X. To get these to start, add the following lines to the /etc/rc.conf file

dbus_enable="YES"
hald_enable="YES" 

Both of the above config lines can be removed if using a login manager (like gdm). All the needs to be added in this scenario is

gnome_enable="YES"  

Automatically mount any samba shares at boot by adding lines like the following to /etc/fstab </span>

>> //user@server/share  /mountpoint  smbfs  rw,-N,-Iserver  0  0  

With -N specified in the above fstab entry, any secrets needed to connect to the share need to be put into the ~/.nsmbrc file and should look as follows

[SERVER:USER]  
password=secret  

Tread with caution here: I’ve just rolled back authentication for the samba shares as FreeBSD’s mount_smbfs doesn’t contain a _netdev option which will delay mounting the remote share until the network is available. Not being able to do this makes the BSD boot fail with authentication errors.

Shutdown

sudo shutdown -h now