Skip to content

Instantly share code, notes, and snippets.

View yyfrankyy's full-sized avatar

Frank Xu yyfrankyy

View GitHub Profile
@yyfrankyy
yyfrankyy / async-cluster.js
Last active March 19, 2017 00:18
async.js, cluster, and dnode
var cluster = require('cluster')
var async = require('async')
var donde = require('dnode')
var hashring = require('hashring')
var ring = new hashring()
var jobs = require('os').cpus().length
var masterPort = 7000
var workers = {}
var queue = async.queue(function(o, next) {
@yyfrankyy
yyfrankyy / mongo.js
Created March 6, 2013 05:03
清除脏数据
db.collection.remove({"key": {$exists: false}})
@yyfrankyy
yyfrankyy / extsrc_for_chrome.sh
Created January 21, 2013 04:33
Enable chrome to install extensions from github; userscripts and crossrider
defaults write com.google.Chrome ExtensionInstallSources -array "https://*.github.com/*" "http://userscripts.org/*" "http://*.crossrider.com/*"
@yyfrankyy
yyfrankyy / product.js
Created November 7, 2012 10:39
Cartesian Product
function product() {
return Array.prototype.reduce.call(arguments, function(as, bs) {
var o = []
as.forEach(function(a) {
bs.forEach(function(b) {
if (Array.isArray(b)) {
b = [b]
}
o.push(a.concat(b))
})
@yyfrankyy
yyfrankyy / hashRange.js
Created October 20, 2012 14:28
Mongoose plugin for creating DynamoDB's hash-and-range kind of hash, support for more than two keys
var assert = require('assert')
module.exports = function(hash, indexes) {
if (typeof hash === 'object') {
indexes = hash
hash = '_hash'
}
return function(schema, options) {
@yyfrankyy
yyfrankyy / jitsu_env_add.js
Created September 30, 2012 20:38
make `jitsu env set key value` more easily, by adding `env` key to package.json
// add a extra key to package.json
// { env: {'k1', 'v1'} }
var exec = require('child_process').exec
var env = require(process.cwd() + '/package.json').env
var async = require('async')
var tasks = []
for (var j in env) {
tasks.push((function(i) {
@yyfrankyy
yyfrankyy / unit_test_oauth.coffee
Created September 18, 2012 17:24
Unit test for oAuth
# `tobi` did a great job by simulating a browser in command line, but still have some bugs..
# So, these code need a fixed version of `tobi` git://github.com/yyfrankyy/tobi
# Btw, I put all the login code at `before` block, so that you can do anything with `browser` instance
# which will keep the sessions in memory for further request.
assert = require 'assert'
tobi = require 'tobi'
browser = tobi.createBrowser 5000, 'localhost'
describe 'User', ->
@yyfrankyy
yyfrankyy / shorter-uuid.coffee
Created September 12, 2012 16:15
a shorter uuid
base62 = require 'base62'
crc32 = require 'crc32'
uuid = require 'node-uuid'
exports.unique = ->
base62.encode parseInt("0x#{crc32 uuid.v4()}", 16)
@yyfrankyy
yyfrankyy / file.log
Created September 8, 2012 08:12
log
Document Path: /favicon.ico
Document Length: 1406 bytes
Concurrency Level: 100
Time taken for tests: 1.468 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Keep-Alive requests: 10000
Total transferred: 16390000 bytes
@yyfrankyy
yyfrankyy / gitlab_push_and_close_issue.sh
Created August 31, 2012 06:11
gitlab push and close issue
#!/bin/sh
# copy from http://pastebin.com/meF2mB67
PRIVATE_TOKEN="MySecretToken"
GITLAB_URL="https://gitlab.domain.tld/"
URL=`git config --get remote.origin.url`
PROJECT=`basename ${URL} .git | cut -d':' -f2`
for issue_id in `grep -o -e "\(closes\|fixes\) #[0-9]\+" $1 | cut -d'#' -f2`; do