Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
int main() {
loop = uv_default_loop();
uv_tcp_t server;
uv_tcp_init(loop, &server);
struct sockaddr_in bind_addr = uv_ip4_addr("0.0.0.0", 7000);
uv_tcp_bind(&server, bind_addr);
int r = uv_listen((uv_stream_t*) &server, 128, on_new_connection);
if (r) {
module.exports = ComplexChild
/* A `ComplexChild` has inputs
The argument is a bunch of `geval` inputs that it
can read from. It's basically the parent notifying
it of stuff having happened
You can also pass it a hash of listener functions
@Raynos
Raynos / npm-mirror.py
Created April 19, 2014 22:02
An npm mirror
#!/usr/bin/env python
from traceback import print_exc
import urllib2
import hashlib
import os.path
import os
import json
REGISTRY_URL = 'https://registry.npmjs.org'
MIRROR_PATH = '/var/lib/mirror/npm'

Using channels as errors

One form of bug in I/O programmer is forgetting to handle an error.

var stream = new Socket(host, port)

// stream.error.input.take().then(function (err) {
// /* handle error here */

For each of { properties, hooks, nested properties, nested hooks } do {

  • test diff({ key: value }, { key: null })
  • test diff({ key: value }, { key undefined })
  • test diff({ key: value }, {}) }
cd ./{{project}}
git init
git add .
git commit -m 'initial commit'
git remote add origin {{uri}}:{{user}}/{{project}}
if hash hub 2>/dev/null; then
hub create {{user}}/{{project}}
fi

fixtures-fs

Create a temporary fs with JSON fixtures

Example

var test = require('tape');
var withFixtures = require('fixtures-fs');
/* usage:
var requireMain = require('require-main')
// instead of `require.main === module`
if (requireMain(require, module)) {
doStuff(process.argv)
}
*/

Fast pre-commit tests

pre-commit allows you to run linting & unit tests in a pre commit hook.

Generally a pre-commit hook should only test & lint that which has changed.

Linting what has changed.

This one is easy.

@Raynos
Raynos / index.js
Created April 3, 2014 06:46
requirebin sketch
var mercury = require("mercury")
var h = mercury.h
var delegator = mercury.Delegator()
var inputs = mercury.EventSinks(delegator.id, ["clicks"])
var clickCount = mercury.value(0)
inputs.events.clicks(function () {
clickCount.set(clickCount() + 1)
})