This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * "What is the probability of getting | |
| * 7 tails in a row, out of 150 tosses | |
| * of a fair coin?" | |
| */ | |
| function experiment(streak, tosses) { | |
| var i, ctr = 0; | |
| for (i = 0; i < tosses; i++) { | |
| if (Math.random() < 0.5) ctr = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " http://vim.wikia.com/wiki/Making_Parenthesis_And_Brackets_Handling_Easier | |
| inoremap ( ()<Esc>i | |
| inoremap [ []<Esc>i | |
| inoremap { {<CR>}<Esc>O | |
| autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR> | |
| inoremap ) <c-r>=ClosePair(')')<CR> | |
| inoremap ] <c-r>=ClosePair(']')<CR> | |
| inoremap } <c-r>=CloseBracket()<CR> | |
| inoremap " <c-r>=QuoteDelim('"')<CR> | |
| inoremap ' <c-r>=QuoteDelim("'")<CR> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fork = require('child_process').fork; | |
| module.exports = ProcessPool; | |
| function ProcessPool(path, size) { | |
| this.free = []; | |
| this.waiting = []; | |
| this._init(path, size || 1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); | |
| function get(url, cb) { | |
| http.get(url, function (req, res) { | |
| if (req.statusCode !== 200) { | |
| var err = new Error('bad status code'); | |
| err.code = req.statusCode; | |
| return cb(err); | |
| } | |
| var chunks = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dgram = require('dgram'); | |
| var client = dgram.createSocket('udp4'); | |
| var message = new Buffer('Hello world!'); | |
| client.send(message, 0, message.length, 9999, 'localhost', function (err) { | |
| if (err) return console.error(err); | |
| console.log('message sent'); | |
| client.close(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint no-console: 0, new-cap: 0 */ | |
| import Acl from 'acl'; | |
| import express from 'express'; | |
| import bodyParser from 'body-parser'; | |
| import {parallel} from 'async'; | |
| import AclMongoDBBackend from './backend'; | |
| import mongodb from 'mongodb'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint no-console:0 */ | |
| var git = require('git-node'); | |
| var fs = require('fs'); | |
| var pathJoin = require('path').join; | |
| exports.clone = function clone(url, ref, target, cb) { | |
| var remote = git.remote(url); | |
| var repo = git.repo(pathJoin(target, 'git')); | |
| var opts = {onProgress: console.log}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function compile(filename) { | |
| var result = undefined; | |
| var cacheKey = filename + ":" + babel.version; | |
| var env = process.env.BABEL_ENV || process.env.NODE_ENV; | |
| if (env) cacheKey += ":" + env; | |
| if (cache) { | |
| var cached = cache[cacheKey]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Doubly-linked list | |
| const list = { | |
| root: 'a', | |
| nodes: { | |
| a: {id: 'a', next: 'b'}, | |
| b: {id: 'b', prev: 'a', next: 'c'}, | |
| c: {id: 'c', prev: 'b', next: 'd'}, | |
| d: {id: 'd', prev: 'c'}, | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var https = require('https'); | |
| var fs = require('fs'); | |
| var url = require('url'); | |
| process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | |
| var options = { | |
| key: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_key.pem'), | |
| cert: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_cert.pem'), | |
| }; |