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 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 commandsJump 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
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:
- Pre-requirements
sudo apt-get install subversion cvs build-essential xserver-xorg-dev dvb-utils
sudo apt-get install mplayer
Alternatively you can download and compile it yourself from www.mplayerhq.hu.$ cat /etc/X11/XvMCConfig
libXvMCNVIDIA.so.1
$ ls -l /usr/lib/libXvMC*
lrwxrwxrwx 1 root root 25 2007-11-23 22:46 /usr/lib/libXvMCNVIDIA.so.1 -> libXvMCNVIDIA.so.1.0.9639
...
cvs -d :pserver:anoncvs@cvs.freedesktop.org:/cvs/xapps co xwinwrap
cd xwinwrap
make
svn co http://svn.rubyonlinux.org/mplayerctl
Using the tools for recording HDTV:
- You can skip to the playback section if you are only interested in HDTV playback
- First off, you need to configure the TV channels using dvb-utils scan.
mkdir ~/.azap
scan -a /dev/dvb/adapter0 > ~/.azap/channels.conf
Using the tools for playback of HDTV
- mplayer-drb-server.rb does not require anything except for ruby + mplayer + linux to run
- I've coded in some defaults for mplayer options that use xwinwrap -or- xvmc (don't try to use both at once). The default is to let mplayer choose automatically
- Here's examples of how to use it To have HDTV as your desktop background:
mplayer-drb-server.rb -f livetv.ts -x /home/user/xwinwrap/xwinwrap
To use XvMC and foreground playback:
mplayer-drb-server.rb -f livetv.ts -n
pause.rb -> pauses
seek.rb +30 -> seeks 30 seconds forward
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!acts_as_serializable March 15th, 2008
You heard it here first folks. Acts_as_serializable is making it's public debut today! Yes it may be horrifically stuck in a brain twister of recursion that could bring your server to it's knees when used improperly, AND THAT'S why I feel it is finally READY.
Are YOU ready? Here we go:
script/plugin install http://svn.rubyonlinux.org/acts_as_serializable/trunk
Haha, I know no one is even reading this. That's ok because I need someone to help me finish coding it first :) It's really coming along though! Even as I'm writing this, I would describe it to you but instead I'm going to work on the documentation and tests.
...
OK, I think the way I was approaching it was too crazy. I think this serializable thing is better suited to be some kind of helper like the TestFactory. Mocks etc should be used to stub out required relationships. Building a generic solution is way less effective than teaching how to export your data serialized in yaml form (custom).
Example:
..coming soon
If what you see in the SVN interests you, drop me 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 type | what it does |
| :help surround | shows help for the surround plugin |
| yss= | surrounds the current line with <%= %> |
| yss CTRL-E | turns the current line into a block <% -%>newline char<% end -%> |
| yss- | surrounds the current line with <% -%> |
| CTRL-X CTRL-O | brings up the OMNI complete window for the current object/method |
| ysse | creates an ending for the current block. ie: an 'end' or closing brace |
| CTRL-G e | creates an ending for the current block. use in insert mode |
| what to type | what it does |
| :help surround | shows help for the surround plugin |
| CTRL-G = | surrounds the current line with <%= %> |
| CTRL-G CTRL-E | turns the current line into a block <% -%>newline char<% end -%> |
| CTRL-G - | surrounds the current line with <% -%> |
| CTRL-X CTRL-O | brings up the OMNI complete window for the current object/method |
| CTRL-G e | puts 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&v=2.x&key=YOURKEY>
Leave a comment if this tutorial helped you. Thanks!
code highlighting links May 12th, 2007
Code highlighting is enabled! Here are the links that helped get me started:
Elliott Blatt's Blogand
Raymond Lim's Blogthe code was overflowing out of the div at first, so I changed the top of codehighlight.css to enable horizontal scroll
pre {background-color: #FFFFCC;
background-color: #000;
padding-left: 20px;
padding-top: 1em;
padding-bottom: 1em;
margin-bottom: 1.5em;
color:#fff;
width: 450px;
overflow: auto;
overflow-y:hidden;
}
Sweet, we're live and cookin now.
props to the theme guys! May 12th, 2007
I've finally got the theme selected and tweaked! Using inf02 which was in the Mephisto Theme Gallery
Props go out to the following:
Design by Inf infscripts
Ported by railsgrunt
Powered by mephisto
Also, I made the following MOD to layout.liquid enabling search:<div id="menu">
<div>
<form method="get" id="sform" action="/search">
<input type="text" id="q" value="search" name="q" size="10" onfocus="q.value='';" onblur="q.value='search' "/>
</form>
</div>
...
Using DRb and ruby to control mplayer and record/playback HDTV. March 14th, 2007
I wanted HDTV broadcast in Ubuntu, so I bought a PC-HDTV 5500 tuner. It needs a 2.6.18 or higher kernel to work.
I’ve been working on some scripts to control my TV. So far I have a rudimentary server and client along with a HDTV record script that uses a direct copy from the device using the linux tool ‘cat’. My system @kernel 2.6.19 had a bug which causes cat to overflow.. So there is error detection and resume recording after a crash.
I’ll be using linux CRON to schedule recordings.
It is a work in progress.
Here is the SVN repository:
http://svn.rubyonlinux.org/mplayerctl/
I used Kazuki Takemura’s code to control mplayer, and extended it to use DRb connections.
Go ahead and comment if you are interested in helping with the project. I want it to become a simpler MythTV style thing eventually.. SIMPLER is better.
New commits, March 2008. Rudimentary recording and scheduling via cron are now possible. Need to improve the actual mplayer part now but it’s working so that’s great.