Skip to content

Instantly share code, notes, and snippets.

View sintaxi's full-sized avatar
🔥
GSD

Brock Whitten sintaxi

🔥
GSD
View GitHub Profile
var fs = require("fs")
var request = require("request")
var filePath = __dirname + "/payload.tar.gz"
fs.createReadStream(filePath).pipe(request.put('http://api.lvh.me:3001/').pipe(process.stdout))
@sintaxi
sintaxi / _layout.jade
Created January 10, 2014 04:50
How to do navigation with Harp. Put the following files in a directory and start the server with `harp server`. Compile to html by running `harp compile`.
doctype
html
head
link(rel="stylesheet" href="/main.css")
body
ul
li(class="#{ current.source == 'index' ? 'active' : '' }")
a(href="/") Home
li(class="#{ current.source == 'about' ? 'active' : '' }")
a(href="/about") About
@sintaxi
sintaxi / transition.js
Created December 19, 2013 01:36
Transition bliss
var Transition = function(callback){
this.instantOperations = []
this.deferredOperations = []
this.total = 0
this.count = 0
this.callback = callback || new Function()
return this;
}
Transition.prototype.add = function(el, args, cb){
@sintaxi
sintaxi / test.js
Created December 17, 2013 20:48
superagent not returning a body when status code is 500. running node v0.10.17.
var http = require('http')
var assert = require('assert')
var agent = require('superagent')
http.createServer(function (req, res) {
res.writeHead(500, {'Content-Type': 'text/plain'})
res.end('Hello World\n')
}).listen(1337, '127.0.0.1', function(){
agent.get('http://127.0.0.1:1337/').end(function(err, response){
assert.equal(response.status, 500)
@sintaxi
sintaxi / harp.json
Created October 26, 2013 20:47
brainstorming about redirects object. not yet implemented.
{
"redirects": {
"/:year/:month/:day/:slug": "/#{ year }/#{ slug }"
}
}
module.exports = function(req, rsp, stack, callback){
var that = this
var index = 0
function next(err){
var layer = stack[index++]
if(!layer) return callback(req, rsp, next)
layer.call(that, req, rsp, next)
}
@sintaxi
sintaxi / test.js
Created September 2, 2013 20:29
trying to spawn a child process as root user without being prompted in main script.
// test by running `node test.js`
var spawn = require("child_process").spawn
var child = spawn("sudo", [__dirname + "/bin/server"])
child.stderr.on('data', function (data) {
child.stdin.write("somepassword" + '\n');
})
@sintaxi
sintaxi / batcher.js
Last active December 14, 2015 01:39
Async compatible Batch and Retry api requirements.
var batcher = require("batcher")
var myUploader = function(item, done){
uploadSomewhere(item, function(err, result){
done(err, result)
})
}
var myErrCheck = function(err, retry, pass){
if(err.statusCode == 503){
@sintaxi
sintaxi / gist:4229518
Created December 6, 2012 23:52
old resize lib from back in the day
# This Geometry class was yanked from RMagick. However, it lets ImageMagick handle the actual change_geometry.
# Use #new_dimensions_for to get new dimensons
# Used so I can use spiffy RMagick geometry strings with ImageScience
class Geometry
# ! and @ are removed until support for them is added
#old# FLAGS = ['', '%', '<', '>']#, '!', '@']
FLAGS = ['', '%', '<', '>', '!']#, '@']
RFLAGS = { '%' => :percent,
'!' => :aspect,
'<' => :>,
var dnode = require('dnode');
exports.createServer = function(){
var server = dnode({
foo : function (s, cb) {
cb(s.replace(/[aeiou]{2,}/, 'oo').toUpperCase())
}
})