Skip to content

Instantly share code, notes, and snippets.

@andrew8088
andrew8088 / words.json
Created March 18, 2014 19:49
Word Game Data
[{"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"},
@andrew8088
andrew8088 / server.js
Last active August 29, 2015 14:08
A Node Problem
// 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) {
@andrew8088
andrew8088 / chirps.js
Created June 15, 2015 20:17
The Flux store creator that I'm currently using (with Facebook's own flux repo, which includes just a dispatcher). `chirps.js` is an example of it in action.
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));
@andrew8088
andrew8088 / users.js
Created July 27, 2015 21:59
Are these good unit tests? I've been lazy about doing good unit testing, but I'm trying to change that.
'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) {
@andrew8088
andrew8088 / terminalCommandTest.js
Created July 29, 2015 18:00
How to test a terminal command.
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();
});
var array = ["one", "two", "three", "four", "five"];
document.writeln(array + "<br />");
var newArray = shuffle(array);
document.writeln(newArray);
function shuffle (arr) {
var copy = arr.concat(),
sample gist
(function ($) {
$.fn.chromeFade = function (opts) {
var defs = { msTilFade : 2000, fadeSpeed : 500, fadeTo : 0.01 },
sets = $.extend({}, defs, opts),
elems = this,
fadeFunc = function () {
elems.fadeTo(sets.fadeSpeed, sets.fadeTo);
},
fadeTimer = setTimeout(fadeFunc, sets.msTilFade);
@andrew8088
andrew8088 / jquery_mobile.html
Created October 17, 2010 01:42
playing with jQuery Mobile
<!DOCTYPE html>
<html>
<head>
<title>Page Title some change </title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
</head>
<body>
@andrew8088
andrew8088 / __noSuchMethod__.js
Created October 22, 2010 15:31
Playing around with FireFox's __noSuchMethod__ property; all browsers should have this!
var myObj = (function () {
var data = {
products : ["foobar", "bazquirk", "gizmo"],
services : ["widgets", "other", "last"]
};
return {
__noSuchMethod__ : function (id, args) {
if (id === 'all_products') return data.products;
if (id === 'all_services') return data.services;