Skip to content

Instantly share code, notes, and snippets.

@az7arul
az7arul / .rvmrc
Created October 12, 2012 19:01
Sample .rvmrc file
rvm --create ruby-1.9.3-p194@gemset_name
@az7arul
az7arul / gist:3881301
Created October 12, 2012 20:23
Precompile assets before deploying to heroku
RAILS_ENV=production bundle exec rake assets:precompile
@az7arul
az7arul / gist:4585232
Last active December 11, 2015 10:18
Mimic times method
class Fixnum
def retards_times
n = 0
while (n < self)
yield n
n += 1
end
end
end
@az7arul
az7arul / gist:4946731
Created February 13, 2013 18:06
meta_def
class A
class << self
def meta_def(method_name, &b)
(class << self; self; end).send(:define_method, method_name, &b)
end
end
end
#usage : A.meta_def(:test) do
@az7arul
az7arul / gist:4973012
Last active December 13, 2015 20:49
Object like Hash
class H < Hash
def method_missing(m,*a);
m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
end
undef id, type if ?? == 63
end
@az7arul
az7arul / gist:5149300
Last active December 14, 2015 21:09
Creating alias for activating python virtual environments. Add this line to your ~/.bash_profile file.
for i in `ls ~/python-env`;do alias act_${i}="source ~/python-env/${i}/bin/activate";done
@az7arul
az7arul / .bash_prompt.sh
Last active December 15, 2015 04:38
Show virtual env and git info on command line. Usage: save the the file in home directory and add `. ~/.bash_prompt.sh` in your .bash_profile file
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@az7arul
az7arul / models.py
Created June 17, 2013 13:03
Generating a hash for module inheritance
from django.db import models
class Module(models.Model):
title = models.CharField(max_length=200, blank=True, null=True)
description = models.CharField(max_length=400, blank=True, null=True)
parent = models.ForeignKey('self', blank=True, null=True)
def _get_attributes(self):
@az7arul
az7arul / gist:5875345
Last active March 7, 2018 15:16
phantom-jasmine error when provided a full path to a file
events.js:74
throw TypeError('Uncaught, unspecified "error" event.');
^
TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at EventEmitter.emit (events.js:74:15)
at EventEmitter.<anonymous> (/usr/local/lib/node_modules/phantom-jasmine/node_modules/walkdir/walkdir.js:189:19)
at EventEmitter.g (events.js:175:14)
at EventEmitter.emit (events.js:98:17)
at statAction (/usr/local/lib/node_modules/phantom-jasmine/node_modules/walkdir/walkdir.js:57:17)
@az7arul
az7arul / gist:6217845
Created August 13, 2013 04:15
factorial in rust
fn main(){
fn re_fac(n: int) -> int {
if n < 2 {
1
} else {
n * re_fac( n - 1 )
}
}
let num = re_fac(5);
println(fmt!("%d",(num)));