Sunday, October 16, 2011

Ruby On Rails 3.1 Cheat Sheet

* To create a new application use the rails new command. Replace MyApp with the actual name of your application.

rails new MyApp


* If running Ruby On Rails 3.1 on Ubuntu, you will encounter an error stating " Could not find a JavaScript runtime". To fix this locate the Gemfile in the root of your application and append the following two lines

gem 'execjs'
gem 'therubyracer'

then, to update the bundles run the following command
bundle install


* To run the development webserver for your application use the following command
rails server

Then from any web browser, navigate to port 3000 of your Ruby on Rails server. In my case the machine name is testror. Substitute with your server name or ip address.
http://testror:3000


* To manually work with the sqlite database, use the sqlite3 command followed by the name of the database file
sqlite3 development.sqlite3

To show a list of tables while inside sqlite use the .tables command
.tables

To exit sqlite use the .exit command
.exit


* To search for the first record which matches in a database table bound to a model use
@info = Info.find(:first, :conditions => [ "name = ?", "a"])


* Variable Scoping
$ - a global variable
@ - an instance variable
[a-z] - local variable
[A-Z] - constant
@@ - class static variable

Monday, July 4, 2011

How to shutdown ubuntu server properly

The right way to shutdown an ubuntu server is simply

sudo shutdown -h now

Notice the -h option. Without that the system doesn't really shutdown and you end up at the Recovery Menu which is really annoying on a headless server.

2.3 Drill Format in Eagle

Just a tidbit for anyone else who runs into this problem. To change EAGLE 4.16r2 to use a 2.3 leading zero drill format modify the following sections of the eagle.def file in your installation of eagle.  The eagle.def file is located in the bin directory of your eagle installation.  Relevant changes are shown highlighted in red.

[EXCELLON]

Type     = DrillStation
Long     = "Excellon drill station"
Init     = "%%\nM48\nM72\n"
Reset    = "M30\n"
ResX     = 1000
ResY     = 1000
;Rack     = ""
DrillSize  = "%sC%0.4f\n"        ; (Tool code, tool size)
AutoDrill  = "T%02d"             ; (Tool number)
FirstDrill = 1
BeginData  = "%%\n"
Units    = Inch
Select   = "%s\n"                ; (Drill code)
Drill    = "X%05.0fY%05.0f\n"      ; (x, y)
Info     = "Drill File Info:\n"\
           "\n"\
           " Data Mode         : Absolute\n"\
           " Units             : 1/1000 Inch\n"\
           "\n"

Just Why does 2.3 leading zero even matter?  I'm not sure it really even does anymore.  Many years ago when batchpcb and golden phoenix PCB first hit the scene they were pretty stringent on the drill file being a specific format.  I think the process of submitting PCBs has advanced far enough now that nobody may even care how screwed up the drill file is, but since I have always had good success sending it in the required 2.3 leading zero format, i figure why change a good thing.  I did recently send some boards to SeeedStudio in a quite messed up drill format and they processed it just fine so maybe nobody really does care anymore.