Skip to content

Instantly share code, notes, and snippets.

View arnab's full-sized avatar

Arnab Deka arnab

View GitHub Profile
# From http://nathansjslessons.appspot.com/lesson?id=1080
counter = ( ->
count = 0 # cannot be accessed as it's tied to the closure
f = ->
count += 1
f
)()
console.log counter() # 1
@arnab
arnab / ruby-like-inspect-in-javascript.rb
Created August 5, 2011 15:59
You know you do a console.log(object) and you see a string called "Location" (except if you are in Chrome :)). Well here's the solution...
console.log("%o", window.location);
@arnab
arnab / word-wrap.css
Created July 11, 2011 23:34
How do you ord-wrap a link
.wrap-words {
word-wrap: break-word;
}
@arnab
arnab / rails_202_properties.rb
Created April 9, 2011 04:06
Rails 3.0.6 Properties
# see https://github.com/rails/rails/blob/v2.0.2/railties/builtin/rails_info/rails/info.rb
@properties = {
:ruby => "#{RUBY_VERSION} (#{RUBY_PLATFORM})",
:rubygem => Gem::RubyGemsVersion,
:rails => Rails::VERSION::STRING,
:app_root => File.expand_path(RAILS_ROOT),
:env => RAILS_ENV,
:db_adapter => ActiveRecord::Base.configurations[RAILS_ENV]['adapter'],
:db_schema_version => (ActiveRecord::Migrator.current_version || nil),
#
# = Hash Recursive Merge
#
# Merges a Ruby Hash recursively, Also known as deep merge.
# Recursive version of Hash#merge and Hash#merge!.
#
# Category:: Ruby
# Package:: Hash
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
@arnab
arnab / mri_1_8.rb
Created November 19, 2010 00:44
Standard Exceptions in Ruby (MRI 1.9 and 1.8) and how to generate them
ruby-1.8.7-p302 > tree_printer.call tree
Exception
IRB::Abort
NoMemoryError
ScriptError
LoadError
NotImplementedError
SyntaxError
SignalException
Interrupt
@arnab
arnab / running-fog-specs.sh
Created November 16, 2010 17:14
fog spec errors (756 in the whole suite)
ArgumentError in 'Fog::Vcloud power_on with a vapp uri that doesn't exist should == {:type=>"application/vnd.vmware.vcloud.org+xml", :name=>"Boom Inc.", :href=>"https://fakey.com/api/v0.8/MockOrganization/2174953160"}'
Unrecognized arguments: username, module, password, versions_uri
/Users/arnab/code/github/fog/lib/fog/core/service.rb:141:in `validate_arguments'
/Users/arnab/code/github/fog/lib/fog/core/service.rb:43:in `new'
/Users/arnab/code/github/fog/spec/vcloud/terremark/ecloud/requests/../../../spec_helper.rb:276:
@arnab
arnab / NumberGuess.java
Created November 12, 2010 06:50
The number guess game in Common Lisp (from Land of Lisp), to compare to the Ruby implementation
import java.io.Console;
public class NumberGuess {
private int small;
private int big;
private int guess;
private void guess(){
this.guess = nextGuess();
String verdict = System.console().readLine(guess + ": smaller/bigger/start-over? ");
@arnab
arnab / sdb_put_attributes_with_fog.rb
Created October 18, 2010 19:52
SimpleDB put_attributes using fog
require "fog"
CREDS_FILE = 'Somewhere'
DOMAIN = 'Dogs'
ATTRIBS_TO_CHANGE = {
'color' => 'white'
}
OPTIONS = {
:replace => ['color'],
:expect => {
require "pp"
class String
def all_substrings
substrs = []
start_index, end_index = [0, self.length - 1]
start_index.upto end_index do |i|
i.upto end_index do |j|
# puts "#{self}[#{i}, #{j}] => #{ss}"
substrs << self[i..j]