Skip to content

Instantly share code, notes, and snippets.

@polotek
polotek / git-unstash.js
Created July 22, 2011 10:05
This is a git script that makes it easier to stash and unstash multiple patches in a dirty working tree.
#!/usr/bin/env node
/*
* This is a git script that makes it easier to stash and unstash
* multiple patches in a dirty working tree. This is a first draft
* taken from this approach
* http://stackoverflow.com/questions/1360712/git-stash-cannot-apply-to-a-dirty-working-tree-please-stage-your-changes
*
* It's written with javascript for node.js, because I wanted to explore scripting
* with node.
fs.createReadStream('jsconf.png')
.pipe( request.post({url:'http://transform.it/'}) )
.pipe( response );
@polotek
polotek / gist:1052033
Created June 28, 2011 19:57
Some coffeescript syntax experimenting. How are these different?
baz = -> alert 'baz'
foo -> alert 'foo'
bar ->
foo
baz = ->
foo = -> alert 'new foo'
baz()
foo()
@polotek
polotek / gist:1023428
Created June 13, 2011 18:53
amd_define_example.js
// This is the usual AMD form that supports the dependency array.
define(['mymodule'], function(mymodule) {
// The module mymodule should be loaded and available here.
mymodule.doSomething();
});
// This is the "basic" form that is now supported by node
define(function(require, exports, module) {
// This will be loaded synchronously in node. In the browser you need
// a build step and a smart loader to do this.
@polotek
polotek / twitter_stream_example.js
Created May 18, 2011 06:06
Contrived example of using a BufferedStream to implement custom stream behavior
function TwitterStream(tweetstream /* the raw data socket from twitter.com */) {
// some setup
this.bufferedstream = new BufferedStream(); // my version
tweetstream.pipe(buffer).pipe(this);
// Now I have a buffered data stream that I know I can pause/resume at will. No one else has to be affected by this.
}
// standard stream method
TwitterStream.prototype.write = function(chunk) {
@polotek
polotek / pipeaccept.js
Created May 18, 2011 01:16 — forked from heapwolf/pipeaccept.js
accepting input from a pipe, nodejs
var data;
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
data += chunk;
});
process.stdin.on('end', function() {
@polotek
polotek / node_redir_test.js
Created April 25, 2011 03:31
Testing 301 redirects with node
var http = require('http');
var server = http.createServer(function (req, resp) {
if(req.url.match('redir')) {
resp.writeHead(301, {'Location':'http://google.com/', 'Expires': (new Date).toGMTString()});
resp.end();
} else {
resp.writeHead(200, {'content-type': 'text/plain', 'content-length':4});
resp.end('Main');
}
});
@polotek
polotek / stream-buffering.js
Created March 2, 2011 13:53
An attempt to observe how stream.pause() behaves with different read sources
var http = require('http')
, Stream = require('stream').Stream
, fs = require('fs')
, util = require('util');
var slice = Array.prototype.slice;
/**
@polotek
polotek / hanging_text.css
Created February 15, 2011 19:01
Cross browser css for hanging text
.hanging {
display:-moz-inline-box;
display:inline-block;
vertical-align:top;
}
var fs = require('fs');
OAuth = require('oauth').OAuth;
var config = JSON.parse( fs.readFileSync(__dirname + '/default_config.json') );
var oauth = config.oauth;
console.warn(oauth);
var oa = new OAuth(oauth.requestTokenURL
, oauth.accessTokenURL