Skip to content

Instantly share code, notes, and snippets.

@bf4
bf4 / binary.rb
Created February 15, 2016 16:48
trees
# http://www.mikeperham.com/2014/11/26/building-a-binary-tree-with-enumerable/
class Node
include Enumerable
include Comparable
attr_accessor :data, :left, :right
def initialize(data)
@data = data
end
@bf4
bf4 / script.sh
Created February 5, 2016 05:05
Summing shell exit codes
result=0
action() {
false
}
list='1 2 3'
for thing in $list; do
echo $thing
action
result+=$?
@bf4
bf4 / pipes_streams_exit_codes.bash
Last active February 12, 2016 23:09
pipes streams and echo codes
#!/usr/bin/env bash
# 2>&1 # stderr to stdout
# 1>&2 # stdout to stderr
# 2> # stderr
# > # stdout
# see http://www.tldp.org/LDP/abs/html/io-redirection.html
# exec 3>&1; bundle-audit -v >&3 3>&- | tee reports/bundle-audit.txt 3>&- ; exec 3>&-
# https://stackoverflow.com/questions/1221833/bash-pipe-output-and-capture-exit-status
# <command> | tee out.txt ; test "${PIPESTATUS[0]} -eq 0"
# ( set -o pipefail; command | tee out.txt ); ST=$?
@bf4
bf4 / .babelrc
Last active January 29, 2016 17:06
Crazy react webpack bower and gulp
{
"presets": ["react", "es2015"],
"ignore": [
"data/*.js"
]
}
@bf4
bf4 / recover.md
Created January 28, 2016 19:55
Recovering a rebased commit I can still see in the GitHub web interface

A stupid way to recover a commit that has been rebased and is now unreachable (ref):

  1. Given unreachable commit https://github.com/org/repo/commits/332a2b9f43f1f8d7730e0a01356ea183dfadd470
  2. See if you can compare them to any earlier commit you have https://github.com/org/repo/compare/f571415f4da9cc28edc83242e353966677dabcd2...332a2b9f43f1f8d7730e0a01356ea183dfadd470
  3. Push your local commit up to a recovery branch git checkout f571415f4da9cc28edc83242e353966677dabcd2; git checkout -b recovery; git push origin recovery
  4. See the patch commits https://github.com/org/repo/compare/recovery...332a2b9f43f1f8d7730e0a01356ea183dfadd470.patch and download as recovery.patch (you could curl unless it's private so blah blah)
  5. Apply the patch commits and push up. git am recovery.patch &amp;&amp; git push origin recovery
@bf4
bf4 / southwest.user.js
Created January 14, 2016 15:11 — forked from dbknickerbocker/southwest.user.js
Southwest Auto Check-In
// ==UserScript==
// @name Southwest Auto Check-In
// @namespace http://dbknickerbocker.blogspot.com
// @description Automatically check-in for Southwest flights
// @include https://southwest.com/flight/retrieveCheckinDoc*
// @include https://www.southwest.com/flight/retrieveCheckinDoc*
// @include https://southwest.com/flight/selectPrintDocument*
// @include https://www.southwest.com/flight/selectPrintDocument*
// @updateURL https://gist.github.com/dbknickerbocker/5730976/raw/southwest.user.js
// @author David B. Knickerbocker
@bf4
bf4 / app.rb
Created January 6, 2016 16:20
exceptionless timeouts using a selectable queue
require_relative "selectable_queue"
def run
queue = SelectableQueue.new
result = catch(:timeout) do
object = ->{ rand(5) }
puts "Starting background"
run_background_job(object, queue)
puts "Starting event loop"
run_event_loop(queue)
@bf4
bf4 / reminder.py
Created November 25, 2015 08:35 — forked from bmaca/reminder.py
A python program to remind you to take a break every hour on your 8 hour work shift ;)
import time
import webbrowser
total_breaks = 8
break_count = 0
while (break_count < total_breaks):
time.sleep(3600)
webbrowser.open("https://31.media.tumblr.com/288d6e631cd930de65547ef5044fefb8/tumblr_mlksb86paT1qbuvyto1_500.gif")
break_count = break_count + 1
@bf4
bf4 / ember_examples.md
Created November 24, 2015 17:12 — forked from rwjblue/ember_examples.md
Ember Examples
@bf4
bf4 / application.controller.js
Last active November 13, 2015 16:30
Manipulating query params
import Ember from 'ember';
export default Ember.Controller.extend({
application: Ember.inject.controller(),
queryParams: ['definedInController'],
appName:'Ember Twiddle',
definedInController: 'default'
});
// http://emberigniter.com/should-we-use-controllers-ember-2.0/
// http://guides.emberjs.com/v2.1.0/routing/query-params/