Skip to content

Instantly share code, notes, and snippets.

View JulesWang's full-sized avatar

juleswang JulesWang

View GitHub Profile
@JulesWang
JulesWang / I&T.rb
Created September 27, 2011 12:01
Iterator and Template Method
class List
include Enumerable
def each
yield 1
yield 2
end
#...
end
class SortAlogrithm
def quick_sort
#...
puts "quick_sort"
end
def bubble_sort
#...
puts "bubble_sort"
end
end
# create a new object
object = Object.new
# dup this object, dog is a object
dog = object.clone
# define a function ONLY for this object
def dog.sit
print "I`m sitting\n"
end
module Decorator
def initialize(decorated)
@decorated = decorated
end
def method_missing(method,*args)
# empty? is a method; ?: is a tri-operator
args.empty? ? @decorated.send(method):@decorated.send(method,args)
end
@JulesWang
JulesWang / sort.cpp
Created April 19, 2012 12:39
many sort algorithms
#include <iostream.h>
#include <stdlib.h>
/**/
const int NUM = 6;
void Swap(int &a,int &b)
{
int t = 0;
t = a;
a = b;
b = t;
@JulesWang
JulesWang / levenshtein.rb
Created July 30, 2012 05:10 — forked from abangratz/levenshtein.rb
Quick implementation of the Levenshtein (Edit Distance) Algorithm
#!/usr/bin/env ruby
class String
def levenshtein(other)
range_self_end = self.size
range_other_end = other.size
data =
(0..range_self_end).map {|s|
(0..range_other_end).map {|t|
t + s unless t>0 && s>0
@JulesWang
JulesWang / Fio.md
Last active December 28, 2015 04:29

FIO

fio is an I/O tool meant to be used both for benchmark and stress/hardware verification.

Setup

Linux: