Skip to content

Instantly share code, notes, and snippets.

View abhishek77in's full-sized avatar

Abhishek Srivastava abhishek77in

View GitHub Profile
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$KCODE = 'UTF8'
require 'rubygems'
require 'google-search'
query = ARGV[0] || "paris hilton"
HTML = File.dirname(__FILE__) + '/face.html'
open(HTML, 'w') do |file|
@samsworldofno
samsworldofno / gist:535038
Created August 18, 2010 15:04
cap db:pull
namespace :db do
desc "Download the a full dump of the production database into the development database"
task :pull do
config = YAML::load(File.open(File.join('config', 'database.yml')))
dump_database_remotely(config['production'], remote_file)
compress_backup_remotely(remote_file)
download_backup(remote_file(:compressed), local_file(:compressed))
@mhenrixon
mhenrixon / _form.html.haml
Created May 18, 2011 11:02
A complete sample of how to perform nested polymorphic uploads in rails using carrierwave
=semantic_form_for [:admin, @dog], validate: true, html: {multipart: true} do |f|
=f.inputs do
=f.input :name
=f.input :kennel_name
=f.input :birthdate
=f.input :gender, as: :radio, collection: {'Tik' => 'F', 'Hane' => 'M'}
=f.input :father_id, as: :select, collection: @dogs
=f.input :mother_id, as: :select, collection: @bitches
=f.semantic_fields_for :pictures do |pic|
@viola
viola / gist:1070410
Created July 7, 2011 20:00
Example of fetching Hash (key,value) to the simple_form collection.
-- model
some sort of constant hash:
HASH_NAME = {
0 => "Choose:",
1 => "On-Campus Recruiting - CSO",·
2 => "CSO Staff Referral",
3 => "Faculty Contact",·
4 => "Career Day",·
5 => "CSO Summer Job Listing",·
6 => "Alumni Contact",·
@metaskills
metaskills / wait_until.rb
Last active May 2, 2024 01:51
Never sleep() using Capybara!
# WAIT! Do consider that `wait` may not be needed. This article describes
# that reasoning. Please read it and make informed decisions.
# https://www.varvet.com/blog/why-wait_until-was-removed-from-capybara/
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@reqshark
reqshark / simple-mongodb-connection.rb
Created July 3, 2012 12:36
connecting to mongo from ruby
#!/usr/bin/env ruby
# ruby_simple_example.rb
#
# A sample ruby script covering connection to a MongoDB database given a
# fully-qualified URI. There are a few additional means, but we prefer the URI
# connection model because developers can use the same code to handle various
# database configuration possibilities (single, master/slave, replica sets).
#
# Author:: Mongolab
@leemeichin
leemeichin / url_validator.rb
Created July 20, 2012 15:02
Rails Custom URL Validator
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)
end
# a URL may be technically well-formed but may not actually be
# valid, so this checks for both.
def url_valid?(url)
url = URI.parse(url) rescue false
url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS)
@moustafasamir
moustafasamir / gist:4250738
Created December 10, 2012 14:05
get facebook friends with picture using Koala
def get_facebook_friends(access_token)
@graph = Koala::Facebook::API.new(access_token)
friends = @graph.get_connections("me", "friends?fields=id,name,picture.type(large)")
return friends
end
@keighl
keighl / application.rb
Created December 19, 2012 16:42
Faster Rails asset precompilation via Capistrano .. just do it locally!
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false