Skip to content

Instantly share code, notes, and snippets.

View dhruvasagar's full-sized avatar

Dhruva Sagar dhruvasagar

View GitHub Profile
@dhruvasagar
dhruvasagar / damerau_levenshtein_distance.rb
Last active March 3, 2019 21:34 — forked from dimus/damerau_levenshtein distance for ruby
Damerau-Levenshtein distance for ruby in C
#!/usr/bin/env ruby1.9
# encoding: UTF-8
require 'rubygems'
require 'inline'
require 'time'
class DamerauLevenshtein
def distance(str1, str2, block_size=2, max_distance=10)
res = distance_utf(str1.unpack("U*"), str2.unpack("U*"), block_size, max_distance)
(res > max_distance) ? nil : res
@dhruvasagar
dhruvasagar / gist:1532564
Created December 29, 2011 07:23
Sinatra File Server for serving Videos
APP_ROOT = File.expand_path('.')
require 'sinatra'
get '*' do
mimetype = `file -ib #{File.join(APP_ROOT, params[:splat].join)}`.gsub(/\n/,"")
content_type mimetype
send_file File.join(APP_ROOT, params[:splat].join)
end
@dhruvasagar
dhruvasagar / abilities.rb
Created September 17, 2012 07:58 — forked from ryanb/abilities.rb
How you can break up large Ability class in CanCan
module Abilities
def self.ability_for(user)
if user.admin?
AdminAbility.new(user)
else user
MemberAbility.new(user)
else
GuestAbility.new
end
end
function! FoldAllBut( foldminlines )
folddoclosed
\ if ( (foldclosed(".") >= 0 ) && ( foldclosedend(".") - foldclosed(".") + 1 < a:foldminlines ))
\ exe "normal! zO"
\ endif
endfunction
function Describe(title, testFunc, parent) {
this._title = title;
this._parent = parent;
this._testFunc = testFunc;
if ( ! this._parent ) { // root
this.run();
}
}
#!/usr/bin/env ruby
require 'uri'
require 'json'
require 'net/http'
if ARGV.length > 0
query = ARGV[0]
else
print 'Input word: '
(function (f) {
return (function (g) {
return g(g);
})(function(h) {
return f(function () {
return (h(h)).apply(this, arguments);
});
});
})(function(f) {
return function (n) {
@dhruvasagar
dhruvasagar / gist:b56f52c416f1e8a15a61
Last active August 29, 2015 14:01
Get a list of first n primes
(defn prime-nth [n]
(take n
(filter
(fn [x]
(nil? (some #(zero? (mod x %)) (range 2 (inc (int (/ x 2)))))))
(iterate inc 2))))
@dhruvasagar
dhruvasagar / gist:2cde7e4f5490fdda3efa
Last active August 29, 2015 14:03
SSH Public Key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZH/9G6dnwQRu0Rtij382bIIjIE7Eb/1Ja1w9kBN3DwPXMZsfY22XYNJHCspcoyhHpwUR1ZxMoCs4cmh3PVv1Gq9PHX9ogsO0ufeoZdHeoFv53L2yU9nRVtPAqZfkQxrlXQWmDFFHWpld7i4tNZp9j0KW1SS91a9wvttnSo4FwWi8BrUprN9iECaYPgPwwiRybQ37D4grTjbr3SdMev+vCYKVpTQftC7HzRvTJXTO/vHm+16sEOjM+LwqnGipGuBfQjHJnHVwlAT+aF8JxCseitI9TD+52e+5ZJ4oPzStRiccVdFJEkmGglo5n2ZVoN9Di6RL6PJ/SUzAKF8lbpxlf dhruvasagar@dhruvasagar
#!/usr/bin/env bash
set -u
set -e
export GIT_WORK_TREE="/var/www/example.com"
export NODE_VERSION="0.10"
echo "--> Checking out..."
git checkout -f