Skip to content

Instantly share code, notes, and snippets.

@grncdr
grncdr / deferred-proxy.js
Last active August 29, 2015 14:05
Promise-based generic deferred proxy
/**
* Create a proxy object with the given prototype that caches all method calls to be applied to a target later.
*
* Example of proxying an asynchronously obtained Result object
*
* function Client (transport) {
* this._transport = transport;
* }
*
* Client.prototype.query = function (query) {
@grncdr
grncdr / custom-error.js
Last active August 29, 2015 14:05
Custom JS errors
var inherits = require('inherits');
inherits(CustomError, Error);
function CustomError () {
this.constructor.super_.apply(this, arguments);
this.name = this.constructor.name;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
@grncdr
grncdr / example.js
Created June 14, 2014 21:38
testing API's with buster
'use strict';
var buster = require('buster');
var testApi = require('./test-http');
function exampleApp () {
return function (req, res) {
res.setHeader('content-type', 'text/plain');
res.setHeader('content-length', req.url.length);
res.end(req.url);
@grncdr
grncdr / patch-project.pbxproj.diff
Created March 13, 2014 19:53
Patch for graphviz homebrew formula
--- macosx/graphviz.xcodeproj/project.pbxproj.orig 2012-08-13 15:14:54.000000000 -0500
+++ macosx/graphviz.xcodeproj/project.pbxproj 2012-08-14 13:59:30.000000000 -0500
@@ -380,12 +380,10 @@
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
- ../lib/cdt/.libs,
- ../lib/cgraph/.libs,
- ../lib/gvc/.libs,
+ "$(PREFIX)/lib",
@grncdr
grncdr / README.md
Created February 18, 2014 02:40
Minimal listener/event notifier for JavaScript

event-emitter-minus

EventEmitter without a base class or string event names. Supports adding, removing, and one-shot listeners.

Synopsis

var listeners = require('listeners')

var onEvent = listeners()
@grncdr
grncdr / yield-bang.sjs
Last active January 3, 2016 04:39
macro that thunkifies node-style functions
macro yield! {
rule { $func ( $args (,) ... ) } => {
yield function (cb) {
$func($args (,) ..., cb)
}
}
}
@grncdr
grncdr / not-exactly-thread-first.js
Last active January 3, 2016 02:08
This acts sort of like a thread first. Instead of actually modifying the arguments list, I implicitly assign the result of each line in the body to `$_` then you can use `$_` in the body to refer to the result of the last line.
macro thread {
case { $name ($args (,) ...) { $body ... } } => {
var result = makeIdent('$_', #{$name})
return withSyntax($$_ = [result]) {
console.log('here')
return #{
(function () {
var $$_ = arguments.length > 1 ? [].slice.call(arguments) : arguments[0];
thread_body $$_ $body ...;
return $$_
@grncdr
grncdr / error.txt
Created January 7, 2014 23:04
this happened earlier, not happening now
curl -v https://registry.npmjs.org/batch/-/batch-0.5.0.tgz > /dev/null
* About to connect() to registry.npmjs.org port 443 (#0)
* Trying 199.27.77.162...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* connected
* Connected to registry.npmjs.org (199.27.77.162) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
@grncdr
grncdr / explanado.md
Last active January 1, 2016 06:49
weirdness with browserify + concat-stream & bops

I have some code that uses concat-stream here. It's collecting some javascript from the README and evaling it. The eval currently fails with a syntax error when I use covert test.js, but not when I use node test.js.

covert pipes test.js through browserify and into node. There's some other stuff in between for the actual coverage collection but it's not relevant for this discussion. So we'll simplify things to this:

$ browserify test.js | node
TAP version 13
# README examples

[stdin]:3069
$ lein cljsbuild clean && lein cljsbuild once
Deleting files generated by lein-cljsbuild.
Compiling ClojureScript.
Compiling "client.js" from ["src/cljs"]...
WARNING: No such namespace: core at line 524 resources/js/cljs/core/async.cljs
WARNING: No such namespace: java.util.Arrays at line 675 resources/js/cljs/core/async.cljs
Successfully compiled "client.js" in 39.640165 seconds.