Skip to content

Instantly share code, notes, and snippets.

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Modify by linuz.ly
package main
import (
"bytes"
"fmt"
"code.google.com/p/go.crypto/ssh"
@lsm
lsm / firefs
Created December 11, 2014 00:52
An example of using firebase as filesystem
// Example folder object
{
example_folder: {
type: "folder",
children: {
file1: {
type: "file",
blob: <Buffer 74 68 69 73 20 69 73 20 61 6e 20 65 78 61 6d 70 6c 65 20 66 69 6c 65> // this is a 10MB file
},
Step 1: From your project repository, bring in the changes and test.
git fetch origin
git checkout -b anton-redesign origin/anton-redesign
git merge master
Step 2: Merge the changes and update on GitHub.
git checkout master
git merge --no-ff anton-redesign
git push origin master
@lsm
lsm / gist:8167d7a2f2f39ad586d1
Created March 16, 2015 23:34
Compare stream style
$(function() {
var spaceKeyCode = 32;
//-----------------------------------------
var stream = require('dim')();
var model = {};
stream
'use strict';
module.exports = {
re: function(fnName, context) {
var fn;
context = context || this;
if ('function' === typeof fnName) {
fn = fnName;
fnName = fn.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
} else {
var Pool = Base(EventEmitter, {
init: function(getConnection, size) {
this._super();
this._pool = [];
this._queue = [];
this.size = size;
var me = this;
getConnection(size, function(conn) {
me.emit('back', conn);
});
function() {
var me = this,
writeHead = me.flaker.writeHead,
write = me.flaker.write,
contentType = mime.lookup(extname(filePath));
fs.stat(filePath, function(err, stat) {
if (err || !stat.isFile()) {
errback ? errback(err) : me.error(404, 'File not found');
return;
}
@lsm
lsm / long-string-cipher-base64.js
Created October 29, 2010 15:46
long string cipher->base64 and decipher
var c = require('crypto');
// cipher to binary
var cipher = c.createCipher('aes192', 'hello');
var en = cipher.update('你好你好你好你好你好dfferfdgwefdv4t5g56euhergy56yhe54wtfgq34tg你好你好你好你好你好你好你好erwgw43etr', 'utf8', 'binary') + cipher.final('binary');
console.log(en);
// binary to base64
var buff = new Buffer(en, 'binary');
var base64 = buff.toString('base64');
@lsm
lsm / pure_javascript_hash-ring.js
Created December 14, 2010 14:03
copied from node-memcached
var CreateHash = require('crypto').createHash,
StringDecoder = require('string_decoder').StringDecoder,
Bisection = require('./utils').Bisection;
/*
example usage:
var sys = require( 'sys' ),
hashing = require( '../lib/hashring' ),
hashring = new hashing.hashRing(
[ '192.168.0.102:11212', '192.168.0.103:11212', '192.168.0.104:11212' ],