Skip to content

Instantly share code, notes, and snippets.

@bvsatyaram
bvsatyaram / weighted_random.rb
Created December 20, 2011 04:11
Weighted random method for Array
class Array
# Chooses a random array element from the receiver based on the weights
# provided. If _weights_ is nil, then each element is weighed equally.
#
# [1,2,3].random #=> 2
# [1,2,3].random #=> 1
# [1,2,3].random #=> 3
#
# If _weights_ is an array, then each element of the receiver gets its
# weight from the corresponding element of _weights_. Notice that it
@bvsatyaram
bvsatyaram / print_vs_puts.rb
Created December 20, 2011 04:34
print vs puts in Ruby
# Prints five dots in a single line
5.times do
print "."
end
# Prints five dots in five different lines
5.times do
puts "."
end
@bvsatyaram
bvsatyaram / .gitconfig
Created December 20, 2011 05:10 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
smtpuser = pavan.sss1991@gmail.com
@bvsatyaram
bvsatyaram / evitca_data_encoder.rb
Created December 20, 2011 05:24
Data Encoder to save marshal dump data to database
module EvitcaDataEncoder
require "base64"
class << self
def encode(data)
Base64.encode64(Marshal.dump(data))
end
def decode(string)
Marshal.load(Base64.decode64(string))
@bvsatyaram
bvsatyaram / .irbrc
Created December 20, 2011 05:27
Showing SQL statements in the Rails console
if ENV['RAILS_ENV']
# Called after the irb session is initialized and Rails has been loaded
IRB.conf[:IRB_RC] = Proc.new do
logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = logger
ActiveResource::Base.logger = logger
end
end
@bvsatyaram
bvsatyaram / application.js
Created December 20, 2011 05:59
Load Content on Page Load
/* Assuming that jQuery is already loaded */
$(document).ready(function() {
/* Ajax Content Load */
$('.ajax_content_loader').click();
})
@bvsatyaram
bvsatyaram / heroku_push.sh
Created May 13, 2012 11:10
Deploying private branch to heroku
git push heroku master
@bvsatyaram
bvsatyaram / gist:5841062
Last active December 18, 2015 20:29 — forked from trcarden/gist:3295935
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Place all the ssl files is `~/.ssl` directory
$ mkdir ~/.ssl
$ cd ~/.ssl
# 2) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
/**
* Add dataset support to elements
* No globals, no overriding prototype with non-standard methods,
* handles CamelCase properly, attempts to use standard
* Object.defineProperty() (and Function bind()) methods,
* falls back to native implementation when existing
* Inspired by http://code.eligrey.com/html5/dataset/
* (via https://github.com/adalgiso/html5-dataset/blob/master/html5-dataset.js )
* Depends on Function.bind and Object.defineProperty/Object.getOwnPropertyDescriptor (shims below)
* Licensed under the X11/MIT License
/**
* Add dataset support to elements
* No globals, no overriding prototype with non-standard methods,
* handles CamelCase properly, attempts to use standard
* Object.defineProperty() (and Function bind()) methods,
* falls back to native implementation when existing
* Inspired by http://code.eligrey.com/html5/dataset/
* (via https://github.com/adalgiso/html5-dataset/blob/master/html5-dataset.js )
* Depends on Function.bind and Object.defineProperty/Object.getOwnPropertyDescriptor (shims below)
* Licensed under the X11/MIT License