Skip to content

Instantly share code, notes, and snippets.

View aalavandhan's full-sized avatar
🎯
Focusing

Aalavandhan aalavandhan

🎯
Focusing
View GitHub Profile
@aalavandhan
aalavandhan / eth-helpers.js
Created April 11, 2018 21:36
Ethereum Web3 helper functions
function $waitForOneBlock(){
const id = Date.now();
return new Promise((resolve, reject) => {
web3Instance.currentProvider.send({
jsonrpc: "2.0",
method: "evm_mine",
params: [], "id": id,
}, function(e,r){
if(e) reject(e);
@aalavandhan
aalavandhan / move-up.py
Last active February 28, 2016 03:08
A script to move subfolders up
from multiprocessing import Pool
from os import listdir, stat, rename, mkdir, rmdir
from os.path import join, isdir, getsize
import sys
def listFolders(path):
return filter(lambda f: isdir(join(path, f)), listdir(path))
PATH = sys.argv[1]
@aalavandhan
aalavandhan / gist:1a75c2e3120c6ccf5ba1
Created November 26, 2014 16:55
$resource for Jquery - WIP
"/api/v1/resources/:resource_id"
"/api/v1/master/:master_id/resources/:id"
{
master_id: "master_id",
resource_id: "resource_id",
}
var Resource = function(url, map){
class ArrayInquirer < Array
private
def method_missing method, *args
begin
any? { |elem| elem.to_s == method[0..-2] }
rescue NoMethodError
super method, *args
end
end
end
@aalavandhan
aalavandhan / query_object.rb
Created September 26, 2014 05:01
Sample Query Object
class OrdersQuery
def initialize(relation = Order.all)
@relation = relation.extending(Scopes)
end
def find
@relation.includes(:order_state,
:region,
:merchant_payment_method_currency => [
:merchant, :payment_method_currency => [ :payment_method_branch ]
@aalavandhan
aalavandhan / with.rb
Created September 19, 2014 19:55
A simple implementation of Javascript With Operator in ruby,
class With
attr_accessor :object, :result
def initialize(object)
@object = object
@result = nil
end
def method_missing(method, *args, &block)
@aalavandhan
aalavandhan / message_handler.rb
Created September 7, 2014 11:11
A simple rails utility which cahces data from config/locales/*.yml files as a hash and returns a hash for each specified language file. It also parses and reloads the YAML files everytime they are changed.
module Util
class MessageHandler
@@data = {}
class << self
def data_in(language)
load! if !@@data[language] or (files_changed? and Rails.env.development?)
@@data[language][language.to_s]
@aalavandhan
aalavandhan / render_rails.rb
Created August 29, 2014 15:17
Rails simple render
def render(view_name)
filename = File.join "app", "views", "#{view_name}.html.erb"
template = File.read filename
eruby = Erubis::Eruby.new(template)
eruby.result
end
@aalavandhan
aalavandhan / promise.js
Created August 1, 2014 20:40
A Custom Promise
var Promise = function(){
this.pending = [];
}
Promise.prototype = {
then: function(onResolve, onReject){
this.pending.push({
resolve: onResolve,
reject: onReject
@aalavandhan
aalavandhan / factorial.rb
Last active August 29, 2015 14:04
Factorial 2 ways
#Non-Tail-Recursion
def fact(x)
(x == 0) ? 1 : x * fact(x-1)
end
#Tail-Recursion
def factorial(x)
iteration = ->(acc, n) {
(n == 0) ? acc : iteration.call(acc * n, n-1)
}