Skip to content

Instantly share code, notes, and snippets.

@uniphil
uniphil / blah.jsx
Last active September 20, 2016 03:42
React CSS API sketch
import React from 'react';
import css from 'blahcss';
const BlahSFC = ({ title }) => css((
<div>
<header>
<h1>{title}</h1>
<p>some text in the header</p>
</header>
@uniphil
uniphil / mongo-example.js
Created October 26, 2015 04:17
thenAlways: safer resource management with promises
import assert from 'assert';
import { MongoClient as mongoClient } from 'mongodb';
import thenAlways from './then-always';
/**
* Use thenAlways to make a helper to safely initialize, use, and clean up a mongodb connection
* @param {string} dbURI The mongodb test database to connect to
* @param {func} doStuff A callback to run some tasks with the test database
* @returns {Promise} A promise resolving or rejecting when everything's done
*/
@uniphil
uniphil / blah.md
Created September 22, 2015 12:18
results runtime typechecks

Idea: let the enum declare how many arguments each EnumOption takes

const ProjectActions = Enum({
  CLEAR: 0,
  SELECT: 1,
  HOVER: 1,
 RENAME: 2,
@uniphil
uniphil / grr.ts
Created September 22, 2015 12:13
Type-checked hard-coded results match API
interface Matchable {
name: string;
data: any[];
match: (options: ProjectActionMatcher) => any;
}
interface MatcherCatchAll {
_: (...args: any[]) => any;
}
@uniphil
uniphil / map-demo.py
Created August 14, 2015 01:30
python map
my_list = [0, 1, 2, 3, 4, 5, 6]
# if it's a very simple transformation, you can inline the function with `lambda`
squared = map(lambda el: el**2, my_list)
# squared should now be the list with all elements squared
assert squared == [0, 1, 4, 9, 16, 25, 36] # passes, woo!
@app.route('/')
def home():
return "hello world"
### OR ###
def home():
return "hello world"
app.route('/')(home)
@uniphil
uniphil / reflux-conventions.js
Created July 16, 2015 22:43
reflux conventions
/**
* An example store to document sane conventions.
*
* Stores should implement these five methods at minimum.
* Additional methods (eg., event handlers) may be added.
* Never write directly to `this.data`, except in `init`
* and `setData`.
*
* A few methods are allowed to be called by external
impl Drop for PortMidi {
fn drop(&mut self) {
match portmidi::terminate() {
Err(why) => panic!(why),
Ok(_) => {/* nothing to do here */}
}
}
}
@uniphil
uniphil / keybase.md
Last active August 29, 2015 14:13
keybase.md

I have a public key whose fingerprint is BE83 68DF 6C48 11C0 385C 8590 B02D 3B27 D870 6A99