View localStateRedux.js
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));
};
View terminalCommandTest.js
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();
});
View users.js
'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) {
View chirps.js
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));
View server.js
// 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) {
View stringify.js
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; }) + '}';
}
View words.json
[{"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"},
View fizzbuzz.befunge
1v >"zzuBzziF" ,,,,,,,,$v
>>::35*%!| >"zzuB" ,,,,$v
>:5%!| >"zziF",,,,$v
|%+1*:*25:+1< >:3%!|
@ .
^ ,*25< <
View gist:4360639
> 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 <
View detectives.sql
CREATE DATABASE intrepid_detectives;
USE intrepid_detectives;
CREATE TABLE detectives(
id INTEGER NOT NULL AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50) NOT NULL,
phone_number VARCHAR(10) NOT NULL,
certification_date DATE NOT NULL,
CONSTRAINT detectives_pk PRIMARY KEY (id)