How to stop webrick from the command line
Rails, Ruby 2 Comments »To create a bash file to stop webrick.
In a terminal type gedit stopWebrick and add the following to the contents of the file and save it. Give the file execute permission with chmod of using the file properties in nautilus.
#!/bin/bash
kill -9 `ps -o pid,cmd –no-heading -p $(pgrep ruby) | grep script/server | awk ‘{print $1}’`
This will kill the first ruby process it finds running as script/srever
Run it as needed.
UserSumChallenge Module
Rails, Ruby 1 Comment »The following module is my first ever Ruby/Rails Module.

The UserChallenge module will create a simple random sum, that can be prompted to the user for solving as part as your authentication scheme during a registration process.
Simply create an instance of UserSumChallenge or UserSumImageChallenge and store against the user session. If you use the image challenge, call render to create the image otherwise just add the question attribute to your output.
|
Here is a simple controller that uses a ImageChallenge. Notice the background being supplied to the render method
class MainController < ApplicationController require "UserChallenge" def welcome @challenge = UserChallenge::UserSumImageChallenge.new session["uc"] = @challenge end def image storePath = "/home/user/path" filename = storePath + "/Camouflage.png" challenge = session["uc"] session["uc"] = nil send_data challenge.render(filename), :filename => "confirm.png", :type => 'image/png', :disposition => 'inline' end end
Installing RMagick on Ubuntu
Ruby No Comments »Taken from the rubyonrails wiki, for my reference:
If you need RMagick support for your web app, your going to need to install ImageMagick and RMagick.
sudo apt-get install imagemagickdpkg -l | grep magick
This will install the most current imagemagick and then
list the ‘magick’ packages installed. Look for what version of
libmagick got installed and make sure you specify THAT version number when you install libmagick-dev.
sudo apt-get install libmagick9-devsudo gem install rmagick
After a lengthy build process, you’re ready to edit images in ruby!
Installing Ruby and rails on Ubuntu Feisty
Rails, Ruby 1 Comment »
Found these instructions at http://www.aptana.com/forums/viewtopic.php?p=10640
Blogging to ensure I have a copy, credits go to janmartin.
Lets start with a fresh Ubuntu Feisty Fawn 7.04 installation:
- sudo apt-get install build-essential
- sudo apt-get install sun-java6-jdk
- sudo update-java-alternatives –list
- sudo apt-get install ruby irb ri rake rdoc ruby1.8-dev rubygems
- sudo apt-get install libmysql-ruby mysql-server
- sudo gem update –system
- sudo gem install rails –include-dependencies
Some tests:
- ruby –version
- rails –version
- mysql –version
- gem list
END of command line installation
Download
Aptana + Rails (Linux).
Extract it into ~/aptana
Follow these instructions:
# Open up Aptana, and Navigate to the Help > Software Updates > Find and Install menu.
# Select “Search for new features to install”, click “Finish”
# Select “Ruby on Rails Development Environment”, click “Finish”
# Select the Ruby on Rails Development Environment feature.
# Continue through the dialog boxes until complete.
Follow these instructions:
http://www.aptana.com/forums/viewtopic.php?t=1397
Configure:
Menu -> Window -> Preferences
Rails -> Configuration
Rails path: /usr/bin/rails
Rake path: /usr/bin/rake
Ruby
Installed interpreters:
/usr
Ri/rdoc
RDoc path:/usr/bin/rdoc
Ri path: /usr/bin/ri
Finished!
Powered by ScribeFire.
Ruby Class Cheat sheet
Ruby 1 Comment »The following is my ruby class cheat sheet, aimed at developers new to ruby and rails.
class MyClass #class declaration, notice the capital letter as this is a Constant
attr_reader :readOnlyProperty, … #shortcut to save writing a property getter
attr_writer :writeOnlyProperty, … #shortcut to save writing a property setter
attr_accessor :readWriteProperty, … #shortcut to save writing a property setter and getter
def initialize #class initialization method
@instanceVar=1 #instance variable, available throughout an instance of the class.
@readOnlyProperty=2
@writeOnlyProperty=3
@readWriteProperty=4
end
def instanceVar #property getter
@instanceVar #return the value of the instance variable
end
def instanceVar=(value) #property setter
@instanceVar = value # set the instance variable to the passed in value
end
def instanceMethod #instance method, available to all instances, this is the instance
end
def MyClass.classMethod #class method, only accessible via the class, this is the class
end
CLASSCONSTANT = ["a","b","c"] #constant defined by the class accessible by all instances note its in uppercase
end
I hope you have found this useful. If you have anything to add please comment.
Recent Comments