Skip to content

Instantly share code, notes, and snippets.

@drbrain
drbrain / keybase.md
Created March 13, 2014 04:41
keybase proof

Keybase proof

I hereby claim:

  • I am drbrain on github.
  • I am drbrain (https://keybase.io/drbrain) on keybase.
  • I have a public key whose fingerprint is D202 62C3 D7D2 DEE2 F0E1 CEA6 D672 5168 3BC8 CE00

To claim this, I am signing this object:

rubygems/lib/rubygems/commands/dependency_command.rb:59: ss, = fetcher.spec_for_dependency dependency
rubygems/lib/rubygems/platform.rb:75: os, = arch
rubygems/lib/rubygems/request_set/lockfile.rb:230: type, = get until @tokens.empty? or peek.first == :section
rubygems/lib/rubygems/request_set/lockfile.rb:240: _, name, = get :text
rubygems/lib/rubygems/request_set/lockfile.rb:261: _, version, = get :text
rubygems/lib/rubygems/request_set/lockfile.rb:281: _, data, = get :text
rubygems/lib/rubygems/request_set/lockfile.rb:295: _, name, column, = get :text
rubygems/lib/rubygems/request_set/lockfile.rb:303: type, data, = get [:text, :requirement]
rubygems/lib/rubygems/request_set/lockfile.rb:331: _, repository, = get :text
rubygems/lib/rubygems/request_set/lockfile.rb:336: _, revision, = get :text
require "all_your_base"
require "benchmark/ips"
require "minitest/autorun"
require "securerandom"
BASE62_CHARS = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D",
"E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
@drbrain
drbrain / gist:7ee7ff73a6f43fcb0ecc
Created January 27, 2015 19:59
If your nm output looks like this your ruby is OK
$ nm -a `ruby -rsocket -e 'puts $".grep(/socket.bundle/)'` | grep gethostbyname
U _gethostbyname
000000000000e770 t _sock_s_gethostbyname
000000000000e770 - 01 0000 FUN _sock_s_gethostbyname
0000000000010440 - 01 0000 FUN _tcp_s_gethostbyname
0000000000010440 t _tcp_s_gethostbyname
@drbrain
drbrain / gist:aec8b24fc75d3e65ac86
Last active August 29, 2015 14:15
no leap second here either
$ uname
FreeBSD
$ jot 3 1341100799 | xargs -n 1 date -r
Sat Jun 30 23:59:59 UTC 2012
Sun Jul 1 00:00:00 UTC 2012
Sun Jul 1 00:00:01 UTC 2012
@drbrain
drbrain / README.md
Last active August 29, 2015 14:19
Parentheses don't make code readable by themselves

I've heard people argue "parentheses make code more readable" or "parentheses make code less ambiguous". Parentheses neither help nor hinder ambiguity or readability, your style decisions beyond use of () do that.

Here's a bug we introduced in our application that was allowed through by a coding style that preferred parentheses. If you follow a coding style that omits all unneccesary parentheses (only those that suppress warnings, which I prefer) this bug would have been impossible.

The bug is simple but subtle. The environment-specific data wasn't fetched from config/two.yml because a ) was in the wrong place. Neither my coworker who wrote it, another coworker who reviewed it, nor my own review of the line caught it.

Without parentheses, though, there is no way to introduce this class of bugs because you can't chain off of intermediate results without introducing a local variable.

The main difference between the two examples is not the use of parentheses, it's the style in which the code is wri

enc/ascii.c:OnigEncodingDefine(ascii, ASCII) = {
enc/big5.c:OnigEncodingDefine(big5, BIG5) = {
enc/big5.c:OnigEncodingDefine(big5_hkscs, BIG5_HKSCS) = {
enc/big5.c:OnigEncodingDefine(big5_uao, BIG5_UAO) = {
enc/cp949.c:OnigEncodingDefine(cp949, CP949) = {
enc/emacs_mule.c:OnigEncodingDefine(emacs_mule, Emacs_Mule) = {
enc/euc_jp.c:OnigEncodingDefine(euc_jp, EUC_JP) = {
enc/euc_kr.c:OnigEncodingDefine(euc_kr, EUC_KR) = {
enc/euc_tw.c:OnigEncodingDefine(euc_tw, EUC_TW) = {
enc/gb18030.c:OnigEncodingDefine(gb18030, GB18030) = {
@drbrain
drbrain / output
Created October 27, 2011 01:41 — forked from nahi/gist:1318550
buffer size: 1048576, reading 16348
#!/bin/bash
# git-cleanup-repo
#
# Author: Rob Miller <rob@bigfish.co.uk>
# Adapted from the original by Yorick Sijsling
KEEP_BRANCHES='(master|staging|ci-[0-9]+)$'
git checkout master &> /dev/null
@drbrain
drbrain / Output
Last active December 1, 2015 17:29
{:times_2=>2}
{:times_2=>4}
{:add_pairs=>6}
{:times_2=>6}
{:times_2=>8}
{:add_pairs=>14}
{:times_2=>10}
{:times_2=>12}
{:add_pairs=>22}
{:times_2=>14}