Skip to content

Instantly share code, notes, and snippets.

View hpyhacking's full-sized avatar

Liang Qiu hpyhacking

  • Knew Play Inc.
  • Ottawa
  • 05:39 (UTC -04:00)
View GitHub Profile
@hpyhacking
hpyhacking / fib.erl
Created November 18, 2012 15:46
eunit-a-lightweight-unit-demo-code
-module(fib).
-export([fib/1]).
-include_lib("eunit/include/eunit.hrl").
fib(0) -> 1;
fib(1) -> 1;
fib(N) when N > 1 -> fib(N-1) + fib(N-2).
fib_test_() ->
[?_assert(fib(0) =:= 1),
@hpyhacking
hpyhacking / string.format.coffee
Created December 1, 2012 21:21
String.format coffeescript version
@format = ->
return unless arguments.length
str = arguments[0]
for i in [1...arguments.length]
re = new RegExp('\\{' + (i-1) + '\\}', 'gm')
str = str.replace(re, arguments[i])
str
@hpyhacking
hpyhacking / add_pinyin_to_vcard.rb
Last active February 6, 2022 13:09
Can use index by pinyin with English language setting on iPhone.
require 'rubygems'
require 'chinese_pinyin'
name = []
cp = false
def p(z)
pinyin = Pinyin.t(z, '')
pinyin[0] = pinyin[0].upcase
pinyin
@hpyhacking
hpyhacking / gist:4376961
Created December 26, 2012 01:21
change NSMutableArray by reference
NSArray *ma1 = [@[@"a", @"b", @"c"] mutableCopy];
NSArray *ma2 = [@[@"a", @"b", @"c"] mutableCopy];
NSArray *array = @[ma1, ma2];
NSLog(@"orign %@", array);
[[array objectAtIndex:0] replaceObjectAtIndex:0 withObject:@"X"];
[[array objectAtIndex:1] replaceObjectAtIndex:2 withObject:@"Y"];
-module(sample).
-export([combos/1, combos/2]).
combos(1, L) -> [[X] || X <-L];
combos(K, L) when K == length(L) -> [L];
combos(K, [H|T]) ->
[[H | Subcombos] || Subcombos <- combos(K-1, T)]
++(combos(K, T)).
combos(L) ->
@hpyhacking
hpyhacking / unicorn
Created July 24, 2013 17:03
unicorn service script
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
# encoding: utf-8
class TempTask
def self.get_shareholders
ipo_address = '1LDipoYVWA7UsFzWrrcXUGLnsXWuYaJB9f'
raw = get_raw(ipo_address)
ipo_result = JSON.parse(raw)
txs = ipo_result["txs"].reverse
for i in txs
out_addrs = []
@hpyhacking
hpyhacking / gist:b0c9af3cc29507cf4b17
Created February 16, 2016 08:17
Compile Error for Muse
[ 90%] Built target genesis_update
[ 90%] Built target get_dev_key
[ 91%] Built target witness_node
[ 91%] Built target delayed_node
[ 92%] Building CXX object programs/js_operation_serializer/CMakeFiles/js_operation_serializer.dir/main.cpp.o
In file included from /home/muse/muse/libraries/chain/include/graphene/chain/protocol/types.hpp:38:0,
from /home/muse/muse/libraries/chain/include/graphene/chain/protocol/base.hpp:26,
from /home/muse/muse/libraries/chain/include/graphene/chain/protocol/operations.hpp:25,
description "slanger"
author "hpyhacking <https://yunbi.com>"
start on startup
stop on shutdown
respawn
respawn limit unlimited
chdir /root
contract owned {
address public owner;
function owned() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_