Rails3 and Datamapper quick start May 21st, 2010



Rails3 is almost released and I decided to try it out with Datamapper to see how things work. Things work AWESOME!

Here's a rundown of the steps I used:


gem update --system # you need rubygems >= 1.3.6
git clone http://github.com/rails/rails.git
cd rails
rake install
cd ..
rails my_dm_rails3_app -m http://github.com/jeremyd/rails-templates/raw/master/dm_rails_master.rb
cd my_dm_rails3_app
bundle install
Note: I cloned snusnu's repository here and modified to install a Gemfile that uses prerelease rubygems instead of git repository checkouts. This seems much faster and there were less dependency problems for me..

vim plugin for Git integration, VCSCommand February 23rd, 2009


Yay, just switched to using Git at my workplace!! FINALLY, a chance to learn more about GIT which turns out to be the new king of all that is SCM

Found a sweet plugin for vim called vcscommand.

Clone the plugin. Merge copy the files from plugin/*, syntax/* into ~/.vim/*

Read doc/vcscommand.txt for the awesome commands.

The commands I like are: VCSVimDiff (love vimdiff!!), VCSBlame

vim ctags goto definition and omni-complete August 16th, 2008


When you're reviewing or writing lots of code, it helps to have a sharp tool. I prefer to write ruby and just about everything else in vim since it's available on all platforms and I'm constantly switching from platform to platform (mostly Linux and OSX these days though).
Vim is a great, lightweight, powerful editor with all the features that any other editor can provide (yeah, even the famed textmate has nothing vim doesn't have). The steps below can get you going at a birds eye view.

1) compile vim with ruby support (if you don't already have it). To see if ruby support is enabled type 'vim --version' and look for "+ruby". If you see "-ruby" then ruby support is not enabled.

2) install ctags (via apt-get or ports). You can run it in your project's directory and jump-to-definition will start working:

ctags -R --exclude=*.js
3) install the rails-vim plugin into ~/.vim

4) cook up a great .vimrc
set smartindent
let g:rails_menu=2
set viminfo^=!
colorscheme desert
syntax on
set path=~/myproject/trunk/**
set tabstop=2
set expandtab
set shiftwidth=2
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
VIM commands
Jump to tag (ie: go to definition of the method under your cursor)
Control + ]

Bring up the OMNI complete window in insert mode
Control+X Control+O

DV video capture and edit in Ubuntu linux August 12th, 2008


Video editing capability is a necessity these days, when I finally found a good combination of software to use I was very happy. After-all, all you students and poor people out there, it's not like you want to have to go pirate Final Cut Pro or anything like that just to practice some skillz as an amateur film producer .. Video editing should be free! Content is King!!

Use DVgrab directly (no need for fancy UI here)

sudo apt-get install dvgrab
To capture (plug in your firewire DV cam or whatever):
sudo dvgrab -a outfile-
Then use Cinelerra to edit the raw DV output files.
When you are done editing, save back into format RAW dv

From there use a program such as DeVeDe ...
sudo apt-get install devede
devede


These are the basics that will get you going in a professional way! I am very happy to see that Cinelerra has matured so much and the Ubuntu packages are working flawlessly on my main workbeast that currently runs Ubuntu Gusty. Thanks a bunch!

bash history and reverse history search March 31st, 2008


Spending a lot of time in linux means that you may type the same command twice or more. Using the bash history can save you a lot of re-typing. I typically only use one feature of history search known as 'reverse history search'. You can activate this mode by pressing CTRL-R at the bash prompt and then typing a substring of the command you want.

However, the default options for bash history don't do it any justice. By default it will only save the history when you exit from a terminal, the history is overwritten each time the save happens and is set to a small history size. To remedy all these things you can put the following in ~/.bashrc


export HISTCONTROL=ignoreboth
export HISTSIZE=1000000 HISTFILESIZE=1000000
export HISTFILE=~/.bash_history_safe
export PROMPT_COMMAND='history -a; history -n'
shopt -s histappend

Also, if your .bashrc file is already using PROMPT_COMMAND for other features then you must edit the PROMPT_COMMAND string and add '; history -a; history -n' to the end. For example, my .bashrc file was changed to the following:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"; history -a; history -n'
    ;;
*)
    ;;
esac

March madness HDTV is my desktop background in Ubuntu Gusty. What's yours? March 16th, 2008



The purpose of this post is for me to contribute all the useful information I've gathered on HDTV recording and playback over the last year on NVIDIA+Ubuntu platform.



First off, I'd like to say that not enough linux tutorials are specific enough about hardware branding. If you have hardware that works well out of the box, be loud about it! Plenty of people are out there looking for good linux compatible hardware and even a random blog post can help someone make the right hardware decision.

Hardware:

To playback/record HDTV in Linux, you gotta have the right hardware. You need an NVIDIA graphics card for great compiz-fusion compatibility and a chance at XvMC (that's short for X-Video Motion Compensation). You also need a pcHDTV 5500 tuner card from these guys. Now, it's important to note, I'm talking about broadcast HDTV here (not cable, because I don't have it).

Software:

Using the tools for recording HDTV:

Using the tools for playback of HDTV

Hope you enjoy!

Thanks for checking this out. It's a work in progress but could be very useful to someone who's a linux video geek like myself. Leave a comment!

Textmate style rails plugins for VIM. October 11th, 2007

"Textmate is cool, but VI is forever"
Here's how to get some textmate like potential out of VIM using plugins. I have the following plugins installed: project.vim, genutils.vim, rails.vim, multvals.vim, rubycomplete.vim and surround.vim.
non-insert mode

what to typewhat it does
:help surroundshows help for the surround plugin
yss=surrounds the current line with <%= %>
yss CTRL-Eturns the current line into a block <% -%>newline char<% end -%>
yss-surrounds the current line with <% -%>
CTRL-X CTRL-Obrings up the OMNI complete window for the current object/method
yssecreates an ending for the current block. ie: an 'end' or closing brace
CTRL-G ecreates an ending for the current block. use in insert mode
insert mode
what to typewhat it does
:help surroundshows help for the surround plugin
CTRL-G =surrounds the current line with <%= %>
CTRL-G CTRL-Eturns the current line into a block <% -%>newline char<% end -%>
CTRL-G -surrounds the current line with <% -%>
CTRL-X CTRL-Obrings up the OMNI complete window for the current object/method
CTRL-G eputs an 'end' on the next line

Generating KML / XML on the fly in Ruby on Rails June 7th, 2007

KML can now be used both in Google Maps and Google Earth.
I wrote a simple KML generator using Builder and Rails.
I also used an RSS parser to read geographic coords from an RSS feed which is in use now at Baleen.org, but that is a code story for another day..

I wanted to post some code snips from the project, cause it's cool.

The view "kml.rxml"

xml = Builder::XmlMarkup.new(:indent => 2)

xml.instruct! :xml

xml.kml( "kmlns" => "http://earth.google.com/kml/2.1" ) do
  xml.Document {
    xml.name("someplaces")
    xml.description("someplaces.org locator")
    xml.Style( "id" => "highlight" ) {
      xml.IconStyle {
        xml.Icon {
          xml.href("http://URL to transparent 32x32 png image.png")
        }
      }
    }
    Place.find_all.each do |p|
    xml.Place {
      xml.name(p.tooltip)
      xml.description {
        x=p.popup.dup
        xml.cdata!("#{x.slice!(1..250)}<br><a href=#{p.ext_url}>..Read more</a>")
        }
      xml.styleUrl("#highlight")
      xml.Point {
        xml.coordinates("#{p.x},#{p.y},4")
      }
    }
    end
  }
end
In the controller, you must specify the following headers.
def kml
  render_without_layout
  @headers["Content-Type"] = "application/vnd.google-earth.kml+xml kml; charset=utf-8"
  @headers["Content-Disposition"] = "attachment; filename=someplaces.kml"
end
Here is the migration I used: "001_create_places.rb" For storing latitude/longitude and a few other useful Google Earth / Maps data to be used in the KML
class CreatePlaces < ActiveRecord::Migration
  def self.up
    create_table :places do |t|
      t.column :x, :string
      t.column :y, :string
      t.column :ext_url, :string
      t.column :tooltip, :string
      t.column :popup, :text
    end
  end

  def self.down
    drop_table :places
  end
end
Use a route to behave as a downloadable file.
map.connect '/someplaces.kml', :controller => 'places', :action => 'kml'
That's all you need to start generating KML on the fly with Rails. Have fun!

Bonus Code !! Example Javascript for Google Maps API that loads up KML from an URL.

var geoXml = new GGeoXml("http://URL to someplaces.kml");
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(37.12755479789267,-112.7487179140864),3);
	map.setMapType(new GMapType([G_SATELLITE_MAP.getTileLayers()[0]], G_NORMAL_MAP.getProjection(), "test", {}));
	map.addOverlay(geoXml);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
      }
    }
Also, make sure you have 2.x as the version string where you delcare the Javascript, otherwise your placemarks might go missing!
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=YOURKEY>

Leave a comment if this tutorial helped you. Thanks!

Ubuntu VMware Server QuickStart May 12th, 2007

Ubuntu Server edition is very bare bones. I threw this together so I wouldn't forget the packages needed to spin up a VMware server installation.

sudo apt-get install build-essential linux-headers-`uname -r`
sudo apt-get install libxtst6 libx11-6 libXrender1 libXt6 libdb3 xinetd
tar -xzvf VMware-server-1.0.1-29996.tar.gz
cd vmware-server-distrib
sudo ./vmware-install.pl
After answering all the questions, you're good 2 go!

hellahella howto - web control panel hellanzb in Ubuntu 6.xx Edgy/Dapper May 12th, 2007

FYI:This guide has been RECENTLY CONSOLIDATED. Instructions for Dapper and Edgy are being combined back into one. Notes: Neither Edgy or Dapper can keep up on the python setuptools required to install hellahella's TRUNK. You must download the ez_setup.py script and use it for install. The ez_setup.py script likes to bomb out, I found that each time it got a bit further so I kept running it. After 4 runs it was able to download all the needed eggs and install them successfully. do this: Optional step) remove python setuptools if you have them installed from packages

apt-get remove python-setuptools python2.4-setuptools
then install subversion:
sudo apt-get install subversion
Then run the following command until it is successful. My experience was that it first choked on Paster setup, then on Cheetah, then on MyghtyUtils. The fourth time I ran it, it made it all the way through. Sweet!
sudo python ez_setup.py -U hellahella==dev
additional tips:: If you get GCC errors when ez_setup tries to compile Cheetah, you can install it from packages and run ez_setup.py again like this:
sudo apt-get install python-cheetah
sudo python ez_setup.py -U hellahella==dev

Finally, hellahella and it's dependancies are installed! Continue to setup:
paster make-config hellahella hella.ini
Then edit hella.ini to setup your hellanzb connection info and login information. The defaults seem to correspond to hellanzb.py 's defaults. Once you've setup hella.ini, you're almost there!
paster setup-app hella.ini
paster serve hella.ini
You now should be able to login to hellahella by opening http://localhost:5000/ in your browser.

hellanzb - automatic one-click nzb in Ubuntu Dapper 6.06 May 12th, 2007

This program is very cool. It handles verification and downloading of nzb files better than anything I’ve seen. This includes downloading par2 files on the fly when needed, and automatically un-compressing all of your downloads.

Here’s how to install it in Ubuntu Dapper.

install the needed ubuntu packages:
sudo apt-get install par2 python-twisted-web
download rar for linux here: RarSoft install it:
tar -xzvf rarlinux-3.6.b6.tar.gz
cd rar
sudo mv rar unrar /usr/bin
download hellanzb. install it:
sudo python setup.py install
configure it:
cd /usr/etc
sudo mv hellanzb.conf.sample hellanzb.conf
sudo gedit /usr/etc/hellanzb.conf

*Update: queue directory explained. By default, hellanzb.py will monitor a queue directory for new .nzb files. It’s a good idea to make this the same directory your browser uses for downloads (so you can one click nzb from your brower). The best way I’ve found to do this is to change your download directory into a symbolic link to the nzb daemon directory.

# Important locations
55      Hellanzb.PREFIX_DIR = '/home/yourhome/hellanzb/'
56
57      # Where to put queued .nzb files
58      Hellanzb.QUEUE_DIR = Hellanzb.PREFIX_DIR + 'nzb/daemon.queue/'
59
60      # Where the fully processed archives go
61      Hellanzb.DEST_DIR = Hellanzb.PREFIX_DIR + 'usenet/'

After running hellanzb.py for the first time, the above directories will be automatically created.

After you change the PREFIX_DIR, you should make a symbolic link to it and set Firefox to download into the directory. For example, create a symbolic link:
ln -s /home/yourhome/hellanzb/nzb/daemon.queue /home/yourhome/download

Then set Firefox to download to /home/yourhome/download. Hellanzb will ignore non .nzb files.

This config will monitor /home/yourhome/download for new .nzbs, and the finished product will go in /home/yourhome/hellanzb/usenet.