Skip to content

Instantly share code, notes, and snippets.

View bmeck's full-sized avatar

Bradley Farias bmeck

View GitHub Profile
@bmeck
bmeck / out.log
Created November 15, 2014 13:58
httpd-trunk>grep -r -i --include=\*.c --include=\*.cc --include=\*.cpp --include=\*.h rlimit .
./include/apreq_error.h:#define APREQ_ERROR_OVERLIMIT (APREQ_ERROR_MISMATCH + 1)
./include/apreq_error.h:#define APREQ_ERROR_UNDERLIMIT (APREQ_ERROR_MISMATCH + 2)
./include/http_core.h:#if APR_HAVE_STRUCT_RLIMIT
./include/http_core.h:#ifdef RLIMIT_CPU
./include/http_core.h: struct rlimit *limit_cpu;
./include/http_core.h:#if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
./include/http_core.h: struct rlimit *limit_mem;
./include/http_core.h:#ifdef RLIMIT_NPROC
./include/http_core.h: struct rlimit *limit_nproc;
./modules/apreq/filter.c: ctx->body_status = APREQ_ERROR_OVERLIMIT;
@bmeck
bmeck / wtf.js
Last active August 29, 2015 14:09
readable yet not...
// something about delaying a pipe causes child process stdout to become `readable:false`
function test(prefix, delay_fn, cb) {
var x=new (require("stream").Transform);
x._transform = (function (chunk, enc, cb) {
console.log(prefix, 'chunk:', chunk);
cb(null);
})
var child=require("child_process").spawn("head", ["-c","-2"]);
child.on('exit', function () {
console.log('exit', prefix);
@bmeck
bmeck / sentry-arg.js
Created December 1, 2014 21:00
a simple syntax for guarding functions
function i_cant_event(is_even, sentry onError) {
if (is_even % 2 !== 0) {
// invoke onError(err) , only 1 param goes through
// return undefined
throw new Error('not even');
}
}
function i_cant_event(is_even, sentry onError) {
// invoke onError(err) , only 1 param goes through
// return undefined
@bmeck
bmeck / partial_application.js
Last active August 29, 2015 14:10
simple tagged template functions
let tee = (a) => {console.log(String(a)); return a}
// our applicator
let $_ = (n) => {
let args = new Array(n);
for (let i = 1; i <= n; i++) {
args[i-1] = `$${i}`
}
return (raw, ...values) =>
Function(...args.concat(tee('return ' + raw.reduce(
@bmeck
bmeck / greet-function.js
Created December 11, 2014 23:03
how a greet generator in es6 maps to a function in es5
function greet() {
var done = false;
var who = undefined;
var states = {
BEFORE_HELLO: function (value, err) {
// we have an error, could be *any* value so we use length check
if (arguments.length === 2) {
done = true;
throw err;
}
@bmeck
bmeck / guard-generator.js
Created December 11, 2014 23:56
how a guarded function generator in es6 maps to a function in es5
// will keep calling the function and yield the value
function* guard() {
var fn = yield undefined;
while (true) {
try {
fn = yield fn();
}
catch (e) {
fn = function () {
return undefined;
@bmeck
bmeck / stream-generator.js
Created December 12, 2014 00:14
how a stream generator in es6 maps to a function in es5
function* SerialStream() {
var queued = [];
var ended = false;
function* pipe() {
while (!ended) {
if (queued.length === 0) {
throw new Error("No streams queued");
}
else {
ended = yield* queued.shift();
@bmeck
bmeck / sop.css
Last active August 29, 2015 14:11
button {
color: red;
}
// goto: localhost:9090/
// use step through and a break point to see the names
var original = '(function () {var aloha=1;})()';
var generated = original.replace(/aloha/g, 'hello');
var map = new (require('./').SourceMapGenerator)({
file: "source-mapped.js"
});
var position = {line: 1, column: original.indexOf('aloha')+1};
map.addMapping({
generated: position,
@bmeck
bmeck / this-file.js
Last active August 29, 2015 14:12
attempt to find repro for Jan-'s problem
// usage: node this-file.js file-to-read
stream=require('fs').createReadStream(process.argv[2]);
var to_read = 315208358;
var max_chunk = Math.pow(2,17);
var largest_chunk = 0;
var total_read = 0;
stream.on('readable', function () {
console.log('readable')
var b=stream.read(Math.min(max_chunk, to_read - total_read))
while(b != null && to_read) {