This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A quick little thingy that takes a Stream instance and makes | |
* it emit 'line' events when a newline is encountered. | |
* | |
* Usage: | |
* ‾‾‾‾‾ | |
* emitLines(process.stdin) | |
* process.stdin.resume() | |
* process.stdin.setEncoding('utf8') | |
* process.stdin.on('line', function (line) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { format } from 'url'; | |
import { STATUS_CODES } from 'http'; | |
import uppercamelcase from 'uppercamelcase'; | |
class HTTPError extends Error { | |
constructor(code, message, extras) { | |
super(message || STATUS_CODES[code]); | |
if (arguments.length >= 3 && extras) { | |
Object.assign(this, extras); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
jsfunc() { | |
local code="$(cat)" | |
local fn="$(cat <<EOFF | |
$1() { | |
node <(cat <<EOF | |
require('stream').Readable.prototype.then = function (...args) { return new Promise((res, rej) => { const bufs = []; this.on('error', rej).on('data', buf => bufs.push(buf)).on('end', () => res(Buffer.concat(bufs))); }).then(...args) }; | |
(async () => { | |
${code} | |
})().then(val => typeof val !== 'undefined' && console.log(typeof val === 'string' ? val : JSON.stringify(val, null, 2))).catch(err => console.error(err.stack) || process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function endianness () { | |
var b = new ArrayBuffer(4); | |
var a = new Uint32Array(b); | |
var c = new Uint8Array(b); | |
a[0] = 0xdeadbeef; | |
if (c[0] == 0xef) return 'LE'; | |
if (c[0] == 0xde) return 'BE'; | |
throw new Error('unknown endianness'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var net = require('net'); | |
var inherits = require('util').inherits; | |
var EventEmitter = require('events').EventEmitter; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
input="$1" | |
shift | |
files_dir="$HOME/files" | |
mkdir -p "$files_dir" | |
# Delete old files | |
rm -f "$files_dir"/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ref = require('ref'); | |
module.exports = BufferType; | |
/** | |
* Fixed length "Buffer" type, for use in Struct type definitions. | |
* | |
* Optionally setting the `encoding` param will force to call | |
* `toString(encoding)` on the buffer returning a String instead. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data; | |
process.stdin.on('data', function(chunk) { | |
data = chunk | |
}); | |
process.stdin.on('end', function() { | |
console.log(data); | |
var givenCrc = data.slice(data.length-2); | |
givenCrc = (data[1] << 7 | data[0]); | |
console.log(givenCrc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
eval "`curl -sfLS import.pw`" | |
import "import.pw/robwhitby/shakedown" # load the framework | |
shakedown GET /foo # make a GET request | |
status 404 # assert on http status code | |
content_type 'text/html' # assert Content-Type header contains string | |
contains 'Not found' # assert body contains string | |
matches 'No.*' # assert body matches regex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <ffi.h> | |
/* Acts like puts with the file given at time of enclosure. */ | |
void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[], | |
FILE *stream) | |
{ | |
*ret = fputs(*(char **)args[0], stream); | |
} |