Skip to content

Instantly share code, notes, and snippets.

View sidazhang's full-sized avatar

Sidney Zhang sidazhang

  • Facebook
  • San Francisco
View GitHub Profile
@sidazhang
sidazhang / index.js
Created July 31, 2014 16:04
bookshelf
// format and parse (turning snakecase into camelcase and vice versa)
var S = require('string')
var _ = require('underscore')
var format = function(attrs) {
return _.reduce(attrs, function(memo, val, key) {
memo[S(key).underscore().s] = val
console.log(memo)
return memo;
}, {});
}
{
"format_on_save": true,
"max_preserve_newlines": 2,
"space_in_paren": false
}
@sidazhang
sidazhang / semaphore.go
Last active August 29, 2015 13:56
Semaphore that times out if it is not unlocked within a time frame
package main
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
type Empty struct {
@sidazhang
sidazhang / decodeJson.js
Created February 9, 2014 19:58
decode json
// There is a bug https://github.com/cryptocoinjs/btc-transaction/pull/5
// Below works:
// couple of points:
// change the key of scriptPubkey and scriptSig to 'script'. This is something I intend to change
// The bug is at parsing the values. (the values should not be a number and its should be a string)
// e.g. '2000000' rather than 2000000
var binConv = require( "binstring" );
@sidazhang
sidazhang / Buffertools.js
Last active August 29, 2015 13:56
pure js buffertool
var Buffer = require('buffer').Buffer
// compare equivalence 0 is true 1 is false
Buffer.prototype.compare = function(buf) {
if (!Buffer.isBuffer(buf)) {
buf = new Buffer(buf)
}
if (this.length !== buf.length) {
return 1
}
@sidazhang
sidazhang / my_configs.vim
Last active December 30, 2015 22:49
custom vim configs
try
syntax enable
set background=dark
let g:solarized_termcolors = 256
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
colorscheme solarized
map <C-h> :tabp<cr>
map <C-l> :tabn<cr>
def classic_roman(int)
# initialise variable
num = int
num = num.to_f
output = []
# initialise keys
numeral_to_value = {
1 => "I",
@sidazhang
sidazhang / gist:6159031
Last active December 20, 2015 16:08
map vs map to proc benchmark
require 'benchmark'
def map
100000.times do
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100].map do |int|
int.to_s
end
end
end
@sidazhang
sidazhang / Firebase
Created May 8, 2013 04:57
Firebase Cheatsheet
To create references to children of node .child()
@sidazhang
sidazhang / index.html
Created May 2, 2013 19:11 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>