Skip to content

Instantly share code, notes, and snippets.

@lsm
lsm / gist:1544579
Created December 31, 2011 17:01
Compare Buffer and String
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var dataString = ['xxx', 'ssss', 'yyyyy', '1121212', 'aaaaa'];
var dataBuffer = [new Buffer('xxx'), new Buffer('ssss'), new Buffer('yyyyy'), new Buffer('1121212'), new Buffer('aaaaa')];
suite.add('Buffer#copy', function() {
var offset = 0;
dataBuffer.forEach(function(chunk) {
@lsm
lsm / benchmark_js_oo
Last active October 13, 2015 05:17
Benchmark between different implementation of javascript 'class'
# npm install genji benchmark
var genji = require('genji');
var Benchmark = require('benchmark');
var Base = genji.Base;
var util = require('util'),
times = 500000;
@lsm
lsm / binary_parser.js
Created February 14, 2013 09:03
Javascript binary parser by Jonas Raoni Soares Silva
/**
* Binary Parser.
* Jonas Raoni Soares Silva
* http://jsfromhell.com/classes/binary-parser [v1.0]
*/
var chr = String.fromCharCode;
var maxBits = [];
for (var i = 0; i < 64; i++) {
maxBits[i] = Math.pow(2, i);
@lsm
lsm / base.js
Last active December 15, 2015 12:48
Feature rich Javascript OO implementation
/**
* Javascript OO helpers
*/
/**
* Module exports.
*/
exports.Base = Base;
// 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 {
@lsm
lsm / yosemite2ISO
Created May 17, 2015 03:49
Yosemite to ISO
#!/bin/bash
# Mount the installer image
hdiutil attach /Applications/Install\ OS\ X\ Yosemite.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
# Convert the boot image to a sparse bundle
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o /tmp/Yosemite
# Increase the sparse bundle capacity to accommodate the packages
hdiutil resize -size 8g /tmp/Yosemite.sparseimage