Skip to content

Instantly share code, notes, and snippets.

@dlmanning
dlmanning / toolbar.js
Last active December 16, 2015 01:31
How I make react components without react
import Icon from 'react-fa'
import hoverable from 'lib/hocs/hoverable'
import instyled, { flatKeyed } from 'instyled'
import cascade from 'cascade'
export const EditButton = hoverable(
instyled(
flatKeyed(
cascade({
position: 'absolute',
@dlmanning
dlmanning / checkbox.js
Last active December 17, 2015 02:28
A sample checkbox whose outerlayer is an instyled component
import React, { Component } from 'react'
import instyled, { flatKeyed } from 'instyled'
import cascade from 'cascade'
const CheckboxContainer = instyled(flatKeyed(cascade({
display: 'flex',
width: 'fit-content',
padding: 10,
borderRadius: 7,
background: 'gray',
@dlmanning
dlmanning / branchDispatch.js
Last active December 18, 2015 19:21
dispatch keyed values to keyed functions
const branchDispatch = (obj, table, defaultFn) =>
Object.entries(obj)
.map(([key, value]) =>
table[key] != null
? [key, table[key](value)]
: typeof defaultFn === 'function'
? [key, defaultFn(value)]
: [key, undefined]
)
.reduce((results, [key, value]) => {
@dlmanning
dlmanning / watch.js
Last active December 23, 2015 09:59
Possible regression between 0.10.16 and 0.10.17 related to libuv patch
Running watch.js on node 0.10.17 and OS X 10.8.5 gives the following when editing (in Sublime Text) and saving file in the same directory:
change : a.txt
rename : .subl319.tmp
change : a.txt
rename : .subl69d.tmp
etc...
Doing the same on 0.10.18 gives:
@dlmanning
dlmanning / addressbook.js
Created November 7, 2013 03:22
Sample code for a PCS exercise
var fs = require('fs');
var read = require('read');
var myBook = [];
var data = fs.readFileSync(__dirname + '/data.json', { encoding: 'utf8', flag: 'a+' });
if (data) {
myBook = JSON.parse(data);
}
@dlmanning
dlmanning / ifFilesExist.js
Created November 12, 2013 03:29
A function to asynchronously confirm the existence of every file in an array.
function ifFilesExist (files, cb) {
var numberOfFiles = files.length
, returnsChecked = 0
, existancesConfirmed = 0;
for (var i = 0; i < numberOfFiles; i++) {
fs.exists(files[i], next);
}
function next (e) {
{
"name": "knode.github.io",
"version": "0.0.1",
"description": "knode.github.io ===============",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postupdate": "echo \"Updated...\" && exit 0"
},
"repository": {
'use strict'
const async = makeGenerator => function () {
const generator = makeGenerator.apply(this, arguments);
const handle = result =>
result.done
? Promise.resolve(result.value)
: Promise.resolve(result.value)
.then(res => handle(generator.next(res)))
@dlmanning
dlmanning / gist:7741148
Created December 1, 2013 21:35
Solutions to one of the javascript koans
it("given I'm allergic to nuts and hate mushrooms, it should find a pizza I can eat (imperative)", function () {
var i,j,hasMushrooms, productsICanEat = [];
for (i = 0; i < products.length; i+=1) {
if (products[i].containsNuts === false) {
hasMushrooms = false;
for (j = 0; j < products[i].ingredients.length; j+=1) {
if (products[i].ingredients[j] === "mushrooms") {
hasMushrooms = true;
@dlmanning
dlmanning / injected.js
Created April 20, 2017 02:51
Script comcast injected in my http response to show me a modem ad
// Copyright (C) 2015 Comcast Cable Communications, LLC
// Contact Us: http://customer.xfinity.com/contact-us/
// Intended use of this message is to display critical and time sensitive notifications to customers.
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,