Skip to content

Instantly share code, notes, and snippets.

View utkarshkukreti's full-sized avatar

Utkarsh Kukreti utkarshkukreti

View GitHub Profile
<?php
/**
* Check for post format type, apply filter based on post format name for easy modification.
*
* @since 1.0
*/
function chimps_post_formats_content() {
$format = get_post_format();
$root = get_template_directory_uri();
@utkarshkukreti
utkarshkukreti / rbenv-install-system-wide.sh
Created September 27, 2011 03:22
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@utkarshkukreti
utkarshkukreti / gist:1028007
Created June 15, 2011 20:18
floor vs to_s.size
ruby-1.9.2-p180:001:0>> qb(10**6) { Math.log10(123456789).floor + 1 }
Rehearsal ------------------------------------
1.120000 0.000000 1.120000 ( 1.100062)
--------------------------- total: 1.120000sec
user system total real
1.090000 0.000000 1.090000 ( 1.085366)
# => nil
ruby-1.9.2-p180:002:0>> qb(10**6) { 123456789.to_s.size }
Rehearsal ------------------------------------
@utkarshkukreti
utkarshkukreti / gist:1009030
Created June 5, 2011 15:04
Trying to inherit a module from a parent.
require 'httparty'
class HTTP
include HTTParty
def initialize uri
self.class.base_uri uri
end
end
class Dropbox < HTTP
pry(main)> module Blah
pry(main)* def blah
pry(main)* true
pry(main)* end
pry(main)* end
=> nil
pry(main)> a = []
=> []
pry(main)> Enumerable.send(:include, Blah)
=> Enumerable
@utkarshkukreti
utkarshkukreti / gist:1002072
Created June 1, 2011 10:11
Single and double quotes in Ripper
pry(Ripper)> sexp %q{"foo\nbar"}
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo\\nbar", [1, 1]]]]]]
pry(Ripper)> sexp %q{'foo\nbar'}
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo\\nbar", [1, 1]]]]]]
pry(Ripper)> sexp %q{'foo\nbar'}
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo\\nbar", [1, 1]]]]]]
pry(Ripper)> sexp %q{'foo\\nbar'}
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo\\nbar", [1, 1]]]]]]
pry(Ripper)> sexp %q{"foo\\nbar"}
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo\\nbar", [1, 1]]]]]]
#! /usr/bin/env python
# vim: set fileencoding=utf-8
# (c) Uwe Kleine-König <ukleine@strlen.de>
# GPLv2
# Modified by Utkarsh Kukreti <utkarshkukreti@gmail.com> - 2011/05/31
import locale
import sys
f = file(sys.argv[1])
@utkarshkukreti
utkarshkukreti / Rakefile
Created April 14, 2011 15:32
Watch a directory for changes on *.haml files, and automatically compile them to *.html
# Save as Rakefile, and run `rake watch`
def recompile(base, relative)
haml = File.join(base, relative)
html = File.join(base, relative.gsub(/\.haml$/, '.html'))
print ">>> Change detected to #{relative} >> "
system "haml", haml, html
puts "Compiled <<<"
end
desc "Watch HAML files for changes"
[od]$ rails c
Loading development environment (Rails 3.0.6)
ruby-1.9.2-p180 :001 > Deparment.all
=> #<Mongoid::Criteria
selector: {},
options: {},
class: Deparment,
embedded: false>
ruby-1.9.2-p180 :002 > Deparment.all.entries
def setup()
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("testbooks")
end
@book = Books.create(title: 'Turn of a Screw', author: "Henry James", barcode: '666')
end
def test_barcode
# Test for uniqueness of each book barcode