Skip to content

Instantly share code, notes, and snippets.

View psahni's full-sized avatar

Prashant Sahni psahni

View GitHub Profile
@psahni
psahni / blog
Created February 28, 2011 12:26
Facebook Like Tagging: Integration with Rails
I got an opportunity to learn Jquery in my last project, The user interface quite resembles with the Facebook.
I have to impelement Facebook like autosuggest with tagging support, There are number of Jquery plugins available which does this,
i found most of them incomplete or not to easy to modify
I choose http://code.drewwilson.com/entry/autosuggest-jquery-plugin, because of beautifully written ruby and easy customizable.
The full description of this plugin can read at above addr.
However understanding some of the options is little confusing like 'format list' callback
In this post you will see how to use this callback with server side rails ruby working out of the box :)
#SCRIPT TO CREATE CLASSES AND METHODS DYNAMICALLLY ON THE BASIS OF CSV FILE
def check_usage
unless ARGV.length ==1
puts "Usage: You must input some file in csv format."
exit
end
end
#---------------------------------------------------------------------------------
# Example of how you can to use Capybara with plain Rails' integration tests and FactoryGirl (or plain MyModel.create…)
require 'test_helper'
require 'capybara'
require 'capybara/dsl'
require 'database_cleaner'
Capybara.app = Pardy::Application
Capybara.default_driver = :rack_test
DatabaseCleaner.strategy = :truncation
@psahni
psahni / user.rb
Created March 25, 2011 18:19
code review vipin
require 'save_me'
class User
include SaveMe
attr_writer :first_name, :last_name, :age, :about
validates_presence_of :last_name, :first_name
# validates_length_of :last_name, :minimum => 1, :maximum => 7, :if => :me
# validates_uniqueness_of :first_name, :if => Proc.new { |user| user }
# validates_format_of :first_name,:with => (/thid/), :if => Proc.new { |user| user }
# validates_length_of :first_name, :if => Proc.new { |user| user }
@psahni
psahni / omniauth.rb
Created April 22, 2011 07:54 — forked from dira/omniauth.rb
OmniAuth strategy for a custom provider
module OmniAuth
module Strategies
# tell OmniAuth to load our strategy
autoload :Pixelation, 'lib/pixelation_authorization'
end
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "app_name", "secret"
provider :facebook, "app_name", "secret", :scope => ''
@psahni
psahni / .gitignore
Created May 15, 2011 17:40 — forked from karmi/.gitignore
Import your Gmail messages into ElasticSearch and search them with a simple web application.
.DS_Store
*.log
Gemfile.lock
class Article
attr_reader :filename
def initialize(filename)
@filename = filename
end
def <=> other
self.filename <=> other.filename
end
#gem install 'ruby-breakpoint'
require 'rubygems'
require 'breakpoint'
class Person
def initialize(name, age)
@name, @age = name, age
breakpoint("Person#initialize")
end
attr_reader :age
@psahni
psahni / mysql_connection_cleaner.rb
Created June 15, 2011 13:02 — forked from jagira/mysql_connection_cleaner.rb
MySQL Connection Cleaner
require 'mysql2'
client = Mysql::Client.new(:host => "localhost", :username => "root")
# Fetch running threads
processes = client.query("SHOW FULL PROCESSLIST")
processes.each do |process|
# Kill thread
@psahni
psahni / application.html.erb
Created August 3, 2011 06:48 — forked from chrisbloom7/application.html.erb
Static named redirect routes in Rails 3
<ul class="social-links">
<li class="facebook"><%= link_to "Like us on Facebook", facebook_path %></li>
<li class="twitter"><%= link_to "Follow us on Twitter", twitter_path %></li>
</ul>