Skip to content

Instantly share code, notes, and snippets.

View JulesWang's full-sized avatar

juleswang JulesWang

View GitHub Profile
@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:

@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 / 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;
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
# 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
class SortAlogrithm
def quick_sort
#...
puts "quick_sort"
end
def bubble_sort
#...
puts "bubble_sort"
end
end
@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
@JulesWang
JulesWang / singleton.rb
Created June 6, 2011 07:00
singleton pattern by ruby
require 'singleton'
class Single
include Singleton
#...
end
single = Single.instance
# private method `new' called for Single:Class (NoMethodError)
@JulesWang
JulesWang / observer.rb
Created June 6, 2011 06:59
observer pattern by ruby
class Newspaper
include Observable
def deliver(news)
changed
@news = news
notify_observers @news
end
end
class Subscriber
def update(news)
/*
MERGE(A, p, q, r)
1 n1 ← q - p + 1
2 n2 ← r - q
3 create arrays L[1...n1 + 1] and R[1...n2 + 1]
4 for i ← 1 to n1
5 do L[i] ← A[p + i - 1]
6 for j ← 1 to n2
7 do R[j] ← A[q + j]
8 L[n1 + 1] ← ∞