Skip to content

Instantly share code, notes, and snippets.

View creationix's full-sized avatar
💚
<3

Tim Caswell creationix

💚
<3
View GitHub Profile
@creationix
creationix / stream-chunks.js
Last active August 29, 2015 14:00
Some experimental stream interfaces.
// readable.queue -> array of items to consume
//
// readable.wait() => more - wait for more data to consume
// The => in my docs means "returns" a promise for more in the form of a continuable function, but callback-last style is also accepted.
// ES6 function to convert a stream to an array
function* read(stream) {
while (yield stream.wait());
return stream.queue;
}
@creationix
creationix / bare-repo.js
Last active August 29, 2015 14:00
sample of fs-db in node
var fs = require('fs');
var dirname = require('path').dirname;
var repo = {
rootPath: pathJoin(__dirname, "repo.git")
};
require('js-git/mixins/fs-db')(repo, {
readFile: function (path, callback) {
fs.readFile(path, function (err, buffer) {
if (err) {

Keybase proof

I hereby claim:

  • I am creationix on github.
  • I am creationix (https://keybase.io/creationix) on keybase.
  • I have a public key whose fingerprint is 5586 E707 E6BA D3CA F9B2 0315 A79E F464 F27E D7D2

To claim this, I am signing this object:

@creationix
creationix / generate-key.js
Created June 3, 2014 02:49
Generate key as tedit extension.
"use strict";
var rsa = window.forge.rsa;
var pki = window.forge.pki;
var fs = require('data/fs.js');
var reloadTree = require('ui/tree.js').reload;
var notify = require('ui/notify.js');
var modes = require('js-git/lib/modes.js');
var bodec = require('bodec.js');
@creationix
creationix / draw.js
Created June 3, 2014 03:37
tedit image creator
var reloadTree = require('ui/tree.js').reload;
var modes = require('js-git/lib/modes.js');
var bodec = require('bodec.js');
var fs = require('data/fs.js');
/**
* PNG Encoder
*
* @version 1.0
* @author Robert Eisele <robert@xarg.org>
@creationix
creationix / rackspace-monitoring-agent.service
Last active August 29, 2015 14:04
Virgo service file for archlinux
; Create this file at /etc/systemd/system/rackspace-monitoring-agent.service
; Then reload the configs using `systemctl daemon-reload`
; Enable it with `systemctl enable rackspace-monitoring-agent.service`
; Restart this service using `systemctl restart rackspace-monitoring-agent`
[Unit]
Description=Rackspace Monitoring Agent
After=network.target
[Service]

In git, there is a specified sort order for trees. The sort order matters because if you later re-sort using a different algorithm, it is no longer the same object and should have a different hash.

I'm constantly bit by a bug in the REST API for Git objects where you sort trees wrong. Whenever I happen to hit one of these cases on tedit, I get stuck and can't save my work without manually moving things around and renaming files in tricky ways to avoid the bug.

The correct way to sort is simple:

// As implemented in js-git (JavaScript)
function treeSort(a, b) {
 var aa = a + "/";
local coroutine = require('coroutine')
local table = require('table')
local uv = require("luv")
local function await(fn, ...)
local co = coroutine.running()
local args = {...}
table.insert(args, function (err, result)
if err then error(err) end
return assert(coroutine.resume(co, result))
@creationix
creationix / takeoff.rb
Last active August 29, 2015 14:06
Takeoff for sonic pi
sample :ambi_drone, rate: 0.5
sample :ambi_drone, rate: 0.3
sample :ambi_drone, rate: 0.7
for i in 0..1000
sample :ambi_soft_buzz, rate: (0.3 + i * 0.01)
sample :ambi_soft_buzz, rate: (5 - i * 0.01)
sleep 0.5 / (i / 10 + 1)
end
@creationix
creationix / transform.md
Last active August 29, 2015 14:06
Transform Interface

In many of my libraries, I like to program stream transforms using this simple format. It can then be easily adapted to virtually any stream interface.

function transform(emit) {
  // Given an emit function as input, return a new emit function.
  // Per-stream state can be initialized here and it closed over by the returned fn.
  return function (item) {
    // When the new emit function is called, process the input and call
    // the old emit zero or more times.
 };