View intercept-stdout.js
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 _ = require('underscore'), | |
util = require('util'); | |
// intercept stdout, passes thru callback | |
// also pass console.error thru stdout so it goes to callback too | |
// (stdout.write and stderr.write are both refs to the same stream.write function) | |
// returns an unhook() function, call when done intercepting | |
module.exports = function interceptStdout(callback) { | |
var old_stdout_write = process.stdout.write, | |
old_console_error = console.error; |
View remove-unwanted-networks.sh
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
networksetup -listpreferredwirelessnetworks en0 | tail -n +2 | awk '{$1=$1};1' > ./wifi-networks-all.txt | |
cp ./wifi-networks-all.txt ./wifi-networks-keep.txt | |
# ... manually remove networks we DON'T want from wifi-networks-keep.txt ... | |
grep -Fvxf ./wifi-networks-keep.txt ./wifi-networks-all.txt > ./wifi-networks-remove.txt | |
networksetup -listallhardwareports | |
# ^ find wifi - probably `en0` |
View php: output to downloaded csv.php
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
<?php | |
// force download of CSV | |
// simulate file handle w/ php://output, direct to output (from http://www.php.net/manual/en/function.fputcsv.php#72428) | |
// (could alternately write to memory handle & read from stream, this seems more direct) | |
// headers from http://us3.php.net/manual/en/function.readfile.php | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/csv'); | |
header("Content-Disposition: attachment; filename=FILENAME.csv"); | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
View elevators.js
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
/* | |
Elevator algorithm | |
by Ben Buckman, for a job interview process 7/18/12 | |
*/ | |
// == INSTRUCTIONS == | |
// Iterate through the elevators list and return the elevator that is: | |
// closest, AND | |
// moving in the right direction (or idle), | |
// - [ben] this could mean 2 things: |
View ca10-results.rb
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 ruby | |
require 'net/http' | |
require 'json' | |
# Periodically check the vote tallies in CA-10 | |
# (Nov 2018 midterms, Jash Harder vs Jeff Denham) | |
class CA10Checker | |
URL = 'https://api.sos.ca.gov/returns/us-rep/district/10' |
View logged-bash-script-example.sh
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 | |
# concept from http://stackoverflow.com/a/3403786/267224 | |
############# | |
# log to file | |
LOGFILE=/home/user/log/script.log | |
exec > >(tee -a $LOGFILE) | |
exec 2>&1 | |
############ |
View pig-latin.js
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
/* | |
Pig Latin interpreter | |
by Ben Buckman, July 20 2012 | |
Rules: | |
- All words beginning with a consonant have their first letter moved to the end of word followed by 'ay'. | |
Example: Hello -> Ellohay | |
- All words beginning with a vowel have their first letter moved to the end moved to the word followed by 'hay'. | |
Example: Another -> Notherahay |
View 1-process-uncaughtException.js
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
// this catches the error (good) but still crashes (bad) | |
// was process.uncaughtException already deprecated? | |
// (shouldn't have been yet - http://nodejs.org/api/process.html#process_event_uncaughtexception) | |
process.on('uncaughtException', function(error) { | |
return console.error("CAUGHT uncaughtException", error); | |
}); | |
throw new Error("A big error!"); |
View 1--messed-up-scope.coffee
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
_ = require 'lodash' | |
class CrazyParentView | |
events: | |
'mousedown .thing': -> | |
class CrazyChildView extends CrazyParentView | |
constructor: -> |
View results-docusign-sentinel.log
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
Using test hash test-sentinel-662038 | |
sentinel client [no role] [no port] got 'end' { '0': undefined, '1': undefined, '2': undefined, '3': undefined } | |
sentinel client [no role] [no port] got 'connect' {} | |
sentinel client master 5379 got 'ready' {} | |
---- knock 1 ---- | |
1 Set? true | |
1 check integrity: all good | |
---- knock 2 ---- | |
2 Set? true | |
2 check integrity: all good |
NewerOlder