Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile
It's a subscription-based screencast site, where I post a new five- to
ten-minute screencast every week. For this, people pay a nominal fee
around $3 per month, giving them access to the full archives and new
screencasts as they happen. The style would be similar to the
screencasts I've posted on my blog: just me and the computer, recorded
in one take, although with much practicing. I'd focus not on new
languages and tools, but on the minute-to-minute mechanics of
effective programming practices, with an obvious bias toward the stack
and practices that I use.
tell application "Finder"
open file ((path to home folder as text) & "Dropbox:notes") using ((path to applications folder as text) & "MacVim.app")
end tell
tell application "MacVim"
activate
end tell
#define assert_equals(expected, actual)\
if (expected != actual) {\
printf("FAIL: %#Lx != %#Lx\n", (uint64_t)expected, (uint64_t)actual);\
exit(1); \
}
#define run_test(name)\
printf("%s\n", #name);\
name();
(set -e && ls content/*.markdown | while read p; do DATE=$(echo $p | cut -d '/' -f 2 | cut -d '-' -f 1-3); TARGET=$(echo $p | sed 's/-/\//' | sed 's/-/\//' | sed -E 's/[0-9]+-//' | perl -pe 's/^(.*\/.*\/.*\/)(.)(.*)$/\1\u\2\3/' | sed -E 's/-|_/ /g'); echo $TARGET; mkdir -p $(dirname $TARGET); echo "<\!-- $DATE -->" > $TARGET; cat $p >> $TARGET; rm $p; done)
A Whole New World
Few of us have participated in the creation of our
infrastructure—operating systems, compilers, terminals, editors, etc.,
even though many of us know how to build them in theory. Collectively,
we suffer from a learned helplessness around them: to build new
high-level tools, we'd also have to rebuild some of the
infrastructure, sometimes going all the way down to the kernel. We
can't imagine triggering such a large cultural and technological
shift, so we don't even try to build truly new tools for ourselves.
@garybernhardt
garybernhardt / gist:3319627
Created August 11, 2012 01:02
Isolation, Data & Dependencies
Isolated unit testing—mocking everything—is a controversial topic. We'll briefly review what it is today, why people like it, and its problems. Then, on to the real goal: a trip through behavior vs. data, mutation vs. immutability, how data shape affords parallelism, transforming interface dependencies into data dependencies, and what it might look like to unify all of these with a slightly tweaked version of OO. Fortunately, Ruby is sufficiently flexible that we can do the whole experiment without leaving it.
@garybernhardt
garybernhardt / gist:3180009
Created July 26, 2012 03:05
An excerpt from GCC's reload.c
static int
find_reusable_reload (rtx *p_in, rtx out, enum reg_class rclass,
enum reload_type type, int opnum, int dont_share)
{
rtx in = *p_in;
int i;
/* We can't merge two reloads if the output of either one is
earlyclobbered. */
if (earlyclobber_operand_p (out))
class Changes < Actor
out :timeline_tweets_out
takes :tweets_in, :friends_in
def before
@friends = @friends_in.pop
end
def pump
tweet = @tweets_in.pop
@garybernhardt
garybernhardt / wrap.rb
Created June 26, 2012 03:06
Probably a really bad implementation of word wrapping
class Wrap
def self.wrap(s, max_length)
raise ArgumentError.new("Maximum wrap length can't be 0") if max_length == 0
return [""] if s.rstrip.empty?
# Split into words and whitespace blocks
blocks = s.split /(\s+|\S+)\b/
lines = []
line = ""
@garybernhardt
garybernhardt / selectable_queue.rb
Last active November 23, 2022 12:42
A queue that you can pass to IO.select.
# A queue that you can pass to IO.select.
#
# NOT THREAD SAFE: Only one thread should write; only one thread should read.
#
# Purpose:
# Allow easy integration of data-producing threads into event loops. The
# queue will be readable from select's perspective as long as there are
# objects in the queue.
#
# Implementation: