Skip to content

Instantly share code, notes, and snippets.

View hpyhacking's full-sized avatar

Liang Qiu hpyhacking

  • Knew Play Inc.
  • Ottawa
  • 19:03 (UTC -04:00)
View GitHub Profile
-module(test).
@hpyhacking
hpyhacking / gist:1717551
Created February 1, 2012 15:33
erlang timestamp to integer
get_timestamp() ->
T1 = calendar:datetime_to_gregorian_seconds(erlang:localtime()),
T2 = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
T1 - T2.
@hpyhacking
hpyhacking / db.erl
Created February 17, 2012 15:26
Erlang Programming Chapter II
-module(db).
-export([new/0, destroy/1, write/3, delete/2, read/2, match/2]).
new() -> [].
destroy(_Db) -> successful.
write(Key, Val, Db) -> [{Key, Val} | Db].
delete(_Key, []) -> [];
delete(Key, [{HK, _}|T]) when Key == HK -> delete(Key, T);
@hpyhacking
hpyhacking / xxx_sup_spawn_test.erl
Created April 30, 2012 07:49
Test Named Process in Eunit
-module(xxx_sup_spawn_test).
-include_lib("eunit/include/eunit.hrl").
test_1_() -> {spawn, {
setup,
fun setup/0,
[
?_assert(is_pid(whereis(xxx_sup))),
]
}}.
@hpyhacking
hpyhacking / fib.erl
Created May 11, 2012 22:01
EUnit eats my stack trace !!!
-module(fib).
-export([fib/1]).
-include_lib("eunit/include/eunit.hrl").
%% this call a undef function in erlang module
fib(a) -> erlang:lists_to_atom("a");
fib(0) -> 1;
fib(1) -> 1;
fib(N) when N > 1 -> fib(N-1) + fib(N-2).
@hpyhacking
hpyhacking / generated_by_coffee.js
Created July 4, 2012 14:24
the do keyword in coffeescript
var filename, _fn, _i, _len;
_fn = function(filename) {
return fs.readFile(filename, function(err, contents) {
return compile(filename, contents.toString());
});
};
for (_i = 0, _len = list.length; _i < _len; _i++) {
filename = list[_i];
_fn(filename);
@hpyhacking
hpyhacking / index.html
Created August 1, 2012 06:45 — forked from anonymous/index.html
Skill list
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CodePen &middot; Pen</title>
<!--
Copyright (c) 2012 Mahroof Ali, http://codepen.io/anon
Permission is hereby granted, free of charge, to any person obtaining
@hpyhacking
hpyhacking / index.html
Created August 1, 2012 06:49 — forked from anonymous/index.html
Machanical Grass
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mechanical Grass &middot; CodePen</title>
<!--
Copyright (c) 2012 Tim Holman, http://codepen.io/tholman
Permission is hereby granted, free of charge, to any person obtaining
@hpyhacking
hpyhacking / sample.html
Created September 14, 2012 14:37
Bootstrap ScrollSpy Sample
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style type="text/css">
@hpyhacking
hpyhacking / parse_doc.patch
Created November 15, 2012 00:20
maruku 0.6.0 patch fixed Iconv warnning.
21,24d20
<
< require 'iconv'
<
<
49c45
< converted = Iconv.new('utf-8', enc).iconv(data)
---
> converted = data.encode enc