Skip to content

Instantly share code, notes, and snippets.

View skeggse's full-sized avatar

Eli Skeggs skeggse

View GitHub Profile
@skeggse
skeggse / test.sh
Created November 8, 2013 23:53
O.o
#!/bin/bash
echo "echo Again." >> ~/test.sh
echo Hello.
@skeggse
skeggse / a-test.js
Last active December 28, 2015 16:59
An unexpected abort and subsequent core dump when using the dgram module
var dgram = require('dgram');
var socket = dgram.createSocket('udp4');
// looks like the send might not need to be in the bind callback
socket.bind(8001, '0.0.0.0', function() {
socket.send(new Buffer('HELO'), 0, 4, 8001, 'localhost');
});
socket.on('message', function ondata(data, rinfo) {
/**
* @param {Object.<string, boolean>} data
* @return {number}
*/
function hello(data) {
var q = 0;
if (data.a) {
if (data.b && data.c) {
q = 1
} else if (data.d) {
@skeggse
skeggse / play-store-reviews.js
Created December 12, 2013 09:21
Simple (and pretty bad) scraper for Google Play Store reviews.
var scan = (function(window, document) {
/**
* Scans through all the pages and maps all the reviews.
*
* TODO: automatically switch to date-ordered reviews, and page backwards to
* beginning.
*
* @param {function(?Error, Object, Array)} callback The callback when all reviews have
* been found.
*/
@skeggse
skeggse / stupid-test.conf
Created December 13, 2013 03:49
Upstart apparently not working logically
script
VALUE="PONG"
echo "START" >> /var/log/stupid-test.log
if [ "$VALUE" == "PONG" ]; then
echo "GOOD PONG" >> /var/log/stupid-test.log
fi
if [ "$VALUE" != "PONG" ]; then
echo "BAD PONG" >> /var/log/stupid-test.log
fi
if [ "$VALUE" == "PING" ]; then
@skeggse
skeggse / identity-regex
Created January 27, 2014 22:41
A regular expression which finds javascript functions that return their first value. Doesn't handle comments.
function\s*[^\(]*\(\s*([\$a-z][\$a-z0-9]*)\s*\)\s*\{\s*return\s+\1\s*;?\s*\}
@skeggse
skeggse / locate.js
Created February 5, 2014 21:13
Binary Search Generator Thingy
function* locate(low, high) {
var mid;
if (high === Infinity || high === undefined) {
mid = 1;
for (;;) {
if ((yield mid) > 0) {
mid <<= 1;
} else {
high = mid << 1;
break;
@skeggse
skeggse / ignore.js
Created March 3, 2014 23:26
npm git ignore node_modules: ignores npm modules in the node_modules directory by consulting the devDependencies field in the package.json
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var hasOwn = Object.prototype.hasOwnProperty;
// seaches recursively upwards to find the package.json
function load(start, name) {
var exists, full;
do {
@skeggse
skeggse / nonce.js
Created March 3, 2014 23:56
Generate crypto-random hex from command line because /dev/urandom isn't good enough for some reason
#!/usr/bin/env node
var crypto = require('crypto');
var chars = parseInt(process.argv[2], 10) || 32;
var blockSize = 1024 * 1024;
function sync(count) {
console.log(crypto.randomBytes(Math.ceil(count / 2)).toString('hex').slice(0, count));
}
@skeggse
skeggse / md5.sh
Created April 9, 2014 20:15
recursive md5 implementation with md5sum fallback, bash only
#!/bin/bash
if [ "$#" -eq 0 ]; then
md5sum "$@"
exit 0
fi
recursive=0
exclude=0
sum=0