Skip to content

Instantly share code, notes, and snippets.

View v2e4lisp's full-sized avatar

Yan Wenjun v2e4lisp

View GitHub Profile
@v2e4lisp
v2e4lisp / collection.js.md
Created June 24, 2014 07:31
js functions
@v2e4lisp
v2e4lisp / lru.rb
Created June 19, 2014 08:16
simple ruby LRU cache
class LRU
attr_reader :content
attr_accessor :max
def initialize(max, hash={})
@max = max
@content = hash
end
def [](key)
#include <string.h>
#include <uthash.h>
// this is an example of how to do a LRU cache in C using uthash
// http://uthash.sourceforge.net/
// by Jehiah Czebotar 2011 - [email protected]
// this code is in the public domain http://unlicense.org/
#define MAX_CACHE_SIZE 100000
@v2e4lisp
v2e4lisp / middle.rb
Last active August 29, 2015 14:02
middle ware pattern
module Middle
module Base
def self.included(base)
base.extend self
end
def returning value=nil
throw :done, value
end
end
@v2e4lisp
v2e4lisp / output
Last active August 29, 2015 14:02
simple test framework for ruby
F.*
sample test
Tape::Failure
/tmp/tape.rb:118:in `fail!'
/tmp/tape.rb:104:in `fail_if'
/tmp/1.rb:14:in `block in <main>'
/tmp/tape.rb:43:in `instance_eval'
/tmp/tape.rb:43:in `call'
/tmp/tape.rb:128:in `block in run'
(global-set-key (kbd "<f5>") 'F5)
(defun magic-F5 (f)
(fset 'F5 f))
@v2e4lisp
v2e4lisp / aliasing.rb
Created May 26, 2014 08:17
rails / activesupport / lib / active_support / core_ext / module / aliasing.rb
class Module
def alias_method_chain(target, feature)
# Strip out punctuation on predicates or bang methods since
# e.g. target?_without_feature is not a valid method name.
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
yield(aliased_target, punctuation) if block_given?
with_method = "#{aliased_target}_with_#{feature}#{punctuation}"
without_method = "#{aliased_target}_without_#{feature}#{punctuation}"
@v2e4lisp
v2e4lisp / gist:5a7452741026a17ecc67
Created May 10, 2014 18:01
ruby1.8.7 install watir-webdriver
gem install rubyzip --version "=0.9.9"
gem install selenium-webdriver --version "~>2.20.0"
gem install watir-webdriver
@v2e4lisp
v2e4lisp / array-iter-with-it.rb
Created May 2, 2014 22:11
bind `it' to block, as default.
class Array
class It
def initialize(it)
define_singleton_method(:it) { it }
end
end
def self.iter_with_it(*methods)
methods.each { |m|
old = "_#{m.to_s}".to_sym