Skip to content

Instantly share code, notes, and snippets.

<%= link_to "Sign up",{:controller=>"users",:action=>"new"} ,:class=>"some-class-name" %>
@randika
randika / gist:299049
Created February 9, 2010 09:31
Javascript trim with Regular Expressions
<script type="text/javascript">
//Javascript trim() example
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
//Usage:
var str = " foo bar ";
alert("Original string: '" + str + "'");
str = str.trim();
alert("Trimmed string: '" + str + "'");
</script>
@randika
randika / gist:361105
Created April 9, 2010 12:23
Ruby on Rails: How to bypass Model validation
#Ruby on Rails: How to bypass Model validation
#User Model
class User < ActiveRecord::Base
validates_presence_of :first_name, :last_name
end
#BusinessAccount Model
class BusinessAccount < ActiveRecord::Base
validates_uniqueness_of :username
validates_presence_of :username, :category, :name
@randika
randika / gist:1006368
Created June 3, 2011 13:46
How To Search Shell Command History
# Search all history
randika@randika-XPS-M1330:~$ history
1 sudo apt-get install aptitude
2 sudo aptitude update
3 sudo aptitude install build-essential curl git-core
........
........
29 chmod 400 xxxxx.pem
30 ssh -i xxxxx.pem root@ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com
@randika
randika / gist:1006395
Created June 3, 2011 14:09
Check whether the mongrel port 3000 is open
$ lsof -i -P | grep 3000
ruby 11374 randika 5u IPv4 26389 0t0 TCP *:3000 (LISTEN)
# Terminate the process if you want
$ kill -9 11374
@randika
randika / Installtion_notes_Ruby192_Ubuntu
Created October 30, 2011 10:55
Install Ruby 1.9.2 and Rails 3.0 on Ubuntu
$ sudo apt-get install aptitude
Make sure to update once finished.
$ sudo aptitude update
OK now we have aptitude installed on our system and let’s install rvm. There is a shell script already on rvm server for this. To run this script we need git and curl installed on our system.
$ sudo aptitude install build-essential curl git-core
activesupport (3.1.1) lib/active_support/whiny_nil.rb:48:in `method_missing'
storage_room (0.3.13) lib/storage_room/embeddeds/file.rb:24:in `set_with_filename'
storage_room (0.3.13) lib/storage_room/embeddeds/file.rb:15:in `block in new_with_filename'
storage_room (0.3.13) lib/storage_room/embeddeds/file.rb:15:in `tap'
storage_room (0.3.13) lib/storage_room/embeddeds/file.rb:15:in `new_with_filename'
app/controllers/entry_controller.rb:11:in `create'
actionpack (3.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
@randika
randika / gist:1342263
Created November 6, 2011 00:44
MySQL database configuraion notes
# Create database, user and grant permissions
grant all on <DATABASE>.* to '<USER>'@'%' identified by '<PASSWORD>';
@randika
randika / deploy-notes-heroku.txt
Created November 7, 2011 12:38
Deploy rails3.1 App to Heroku Cedar
###How to deploy rails 3.1 app on heroku Cedar stack
Gem configuration
==============================
1) On your Gem file move the default sqlite3 gem config to development group and add PosgreSQL
group :production do
# gems specifically for Heroku go here
gem "pg"
end
@randika
randika / gist:1371283
Created November 16, 2011 20:32
Apache Server Permission set-up
Apache Server Permission set-up
================================
sudo chown -R www-data:www-data /home/ubuntu/websites
sudo chmod -R 755 /home/ubuntu/websites