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
| const now = () => { | |
| const [sec, nano] = process.hrtime(); | |
| return sec * 1e9 + nano; | |
| }; | |
| const rand = () => Math.floor(Math.random() * 1e16); | |
| const getRequestId = () => | |
| (now() + rand()) | |
| .toString(16) |
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
| let propsToSave = []; | |
| export const setProps = (props) => propsToSave = props; | |
| export const getLocalStore = () => JSON.parse(localStorage.getItem('state')); | |
| export const setLocalStore = (store) => { | |
| var toSave = {}; | |
| var state = store.getState(); | |
| propsToSave.forEach(p => toSave[p] = state[p]); | |
| localStorage.setItem('state', JSON.stringify(toSave)); | |
| }; |
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 test = require('tape'); | |
| var execSync = require('child_process').execSync; | |
| test('ls', function (t) { | |
| var output = execSync('ls').toString(); | |
| t.equal(output, 'node_modules\ntest.js\n'); | |
| t.end(); | |
| }); |
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
| 'use strict'; | |
| var db = require('mongoose').connection; | |
| var credential = require('credential'); | |
| var User = require('./models/user'); // the mongoose model | |
| exports.createUser = function createUser(userAttrs, callback) { | |
| db.once('open', function () { | |
| User.findOne({ username: userAttrs.username }, 'username', function (err, person) { | |
| if (err) return callback(err); | |
| if (person) { |
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 constants = require('../constants'); | |
| var ChirpStore = module.exports = require('./store').extend({ | |
| init: function () { | |
| this.bind(constants.RECEIVE_CHIRPS, this.loadChirps); | |
| this.bind(constants.CREATED_CHIRP, this.loadChirps); | |
| }, | |
| loadChirps: function (data) { | |
| data = ({}).toString.call(data).indexOf('Array') > 0 ? data : [data]; | |
| data.forEach(ChirpStore.add.bind(ChirpStore)); |
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
| // This will hang, and you'll never see "done" because it doesn't drain the `res` Readable Stream. | |
| var http = require('http'); | |
| var server = http.createServer(function (req, res) { | |
| res.writeHead(404); | |
| res.end(); | |
| }); | |
| server.listen(3000, function () { | |
| http.get('http://localhost:3000/', function (res) { |
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 stringify(obj) { | |
| if (typeof obj !== 'object' || obj === null || obj instanceof Array) { | |
| return value(obj); | |
| } | |
| return '{' + Object.keys(obj).map(function (k) { | |
| return (typeof obj[k] === 'function') ? null : '"' + k + '":' + value(obj[k]); | |
| }).filter(function (i) { return i; }) + '}'; | |
| } |
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
| [{"id":1,"level":3,"word":"anguine","definition":"snakelike"}, | |
| {"id":2, "level":1,"word":"cardinal","definition":"of fundamental importance"}, | |
| {"id":3, "level":3,"word":"detersion","definition":"act of cleansing"}, | |
| {"id":4, "level":3,"word":"exiguous","definition":"meager"}, | |
| {"id":5, "level":2,"word":"fraternise","definition":"associate with"}, | |
| {"id":6, "level":2,"word":"masticate","definition":"chew"}, | |
| {"id":7, "level":2,"word":"prognosticate","definition":"predict"}, | |
| {"id":8, "level":2,"word":"abscond","definition":"leave hurriedly"}, | |
| {"id":9, "level":2,"word":"accoutrements","definition":"personal clothing and accessories"}, | |
| {"id":10,"level":1,"word":"dollop","definition":"shapeless mass"}, |
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
| 1v >"zzuBzziF" ,,,,,,,,$v | |
| >>::35*%!| >"zzuB" ,,,,$v | |
| >:5%!| >"zziF",,,,$v | |
| |%+1*:*25:+1< >:3%!| | |
| @ . | |
| ^ ,*25< < |
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
| > v | |
| v,,,,,,,,,,,,,,,,,,,,"Welcome to Coin Toss"< | |
| >52*, v | |
| v"Type H or T to choose heads or tails:"< | |
| >,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,v | |
| v `*8*52~ < | |
| v ? v | |
| v_v ^ v_v | |
| > v < | |
| v < |