Skip to content

Instantly share code, notes, and snippets.

View utkarshkukreti's full-sized avatar

Utkarsh Kukreti utkarshkukreti

View GitHub Profile
<?php
/*
Plugin Name: Include Custom Files
Plugin URI: http://wpprogrammer.com/include-custom-files/
Description: Allows you to include multiple stylesheets and javascript files on a per-post basis.
Version: 1.0
Author: Utkarsh Kukreti
Author URI: http://utkar.sh
== Release Notes ==
@utkarshkukreti
utkarshkukreti / gist:786224
Created January 19, 2011 14:23
Nginx, PHP (with php-fpm) and MySQL setup on Ubuntu
apt-get install htop binutils cpp flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl m4 libpcre3 libpcre3-dev libssl-dev libpopt-dev lynx make perl perl-modules openssl unzip zip autoconf2.13 gnu-standards automake libtool bison build-essential zlib1g-dev ntp ntpdate autotools-dev g++ bc subversion psmisc libmysqlclient-dev libcurl4-openssl-dev libjpeg62-dev libpng3-dev libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libxslt1-dev libbz2-dev libxml2-dev libevent-dev libltdl-dev libmagickwand-dev imagemagick git-core
# server
apt-get install nginx
# mysql
apt-get install mysql-server
# php
cd /usr/src
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
[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
@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"
#! /usr/bin/env python
# vim: set fileencoding=utf-8
# (c) Uwe Kleine-König <[email protected]>
# GPLv2
# Modified by Utkarsh Kukreti <[email protected]> - 2011/05/31
import locale
import sys
f = file(sys.argv[1])
@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]]]]]]
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: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
@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 ------------------------------------