Skip to content

Instantly share code, notes, and snippets.

View rodw's full-sized avatar

Rod Waldhoff rodw

View GitHub Profile
@andris-silis
andris-silis / backbone.js-sync-setTimeout
Created April 27, 2012 08:16
extended backbone.js sync function. uses setTimeout to batch multiple saves on one model in one http request.
// decreases request count on rapid-fire one model saves
// extended backbone.js sync function. uses setTimeout to batch multiple saves on one model in one http request.
// if client side needs immediate answer from server for changes in model attributes,
// pass { immediate: true } in model save options if { wait: true } is not used already.
Backbone._sync=Backbone.sync
Backbone.sync = function(method, model, options){
var maxResetCount=5 // how many times to delay save
var saveBufferSize=3000 // for how many microseconds save is delayed
var immediate=options['wait'] || options['immediate'] || false
@rodw
rodw / directory-reader.coffee
Created October 10, 2013 02:52
Here's a little CoffeeScript routine that will recursively read the file-system, generating an object that represents a complete directory tree. This gist should be executable. You can run it with: `coffee directory-reader.coffee [FILENAME]` to dump a JSON representation of the object to stdout.
# Here's a little CoffeeScript routine that will recursively
# read the file-system, generating an object that represents
# a directory tree.
# The returned object will contain the following attributes:
#
# * `file` - the basename of the file.
# * `dir` - the directory containing the file.
# * `types` - an array containing zero or more of
# "File", "Directory", "SymbolicLink", "BlockDevice",
@DocumentAlchemy
DocumentAlchemy / powerpoint-to-pdf
Last active March 15, 2019 09:08
Shell script using https://documentalchemy.com API to convert a PowerPoint file into a PDF.
#!/bin/bash
# powerpoint-to-pdf <PPT-FILE> [<PDF-FILE>]
# Uses <https://documentalchemy.com/> to convert a PowerPoint document to PDF.
# SET YOUR DOCUMENT ALCHEMY API KEY HERE (OR PASS AS AN ENV VAR).
# SIGN UP AT <https://documentalchemy.com/> TO GET YOUR FREE API KEY.
DA_API_KEY=${DA_API_KEY:-"EDs2UQEprGn9aD4vg6HCPhFvgQFDahQgRzzIfocJ"}
# PRINT USAGE MESSAGE
show_help() {
@rodw
rodw / draw-histogram.sh
Created February 26, 2018 21:04
bash script that generates an ASCII-art histogram (bar chart) from input data.
#!/bin/bash
#-------------------------------------------------------------------------------
# draw-histogram - generates an ASCII-art histogram (bar chart) from input data.
#-------------------------------------------------------------------------------
# Expects a series of lines of the form `<category-name> <count>` to passed
# via stdin.
#
# Generates a table the looks something like the following:
#
# +-------+----+
@rodw
rodw / pid-file-daemon.sh
Created August 14, 2012 01:53
Bash script that uses a PID file to add daemon-like start/stop/status behavior to an arbitrary program.
#!/bin/bash
# Uses a PID file to add daemon-like behavior to an arbitrary program.
################################################################################
usage() {
echo "Usage: `basename $0` PROGRAM {start|stop|restart|force-stop|force-restart|status} [PIDFILE|PID]" >&2
echo "Where: PROGRAM is an executable file." >&2
echo " PIDFILE is the file that contains (or will contain) the PID." >&2
echo " PID is a process id to use in place of a PIDFILE." >&2
}
@ghaiklor
ghaiklor / v8-compile-javascript-example.cc
Last active February 1, 2022 13:25
Simple example how V8 can compile JavaScript source and run it
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
// Compile the source code.
@TooTallNate
TooTallNate / emitLines.js
Created February 10, 2012 01:11
Make any ReadableStream emit "line" events
/**
* 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) {
@lewisd32
lewisd32 / iptableflip.sh
Created April 15, 2015 18:20
Snippet of Unbounce script for restarting HAProxy with zero downtime
echo "Flipping tables! (╯°□°)╯︵ ┻━┻"
num_rules=3
real=3 # exposed to the ELB as port 443
test=4 # used to install test certs for domain verification
health=5 # used by the ELB healthcheck
blue_prefix=855
green_prefix=866
@jed
jed / LICENSE.txt
Created May 20, 2011 13:27 — forked from 140bytes/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Install s3fs on Mac OS X
1 - Install Homebrew - http://brew.sh/
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
2 - Use Homebrew to install s3fs + dependencies
brew install s3fs
3 - Do some custom stuff. I only used the first step from here -> https://gist.github.com/fukayatsu/3910097
sudo /bin/cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.2/Library/Extensions/fuse4x.kext /Library/Extensions