Skip to content

Instantly share code, notes, and snippets.


Sam Stephenson sstephenson

View GitHub Profile
View tweetstorm.rb
#!/usr/bin/env ruby
# Usage: tweetsplit.rb < tweetstorm.txt
# Sam Stephenson / 2017-05-29
# Tweet-sized version:
# puts $<.read.split(/\s+/).reduce(nil){|(*cs,c),w|n=[c,w].compact*" ";cs+(n.size>140?[c,w]:[n])}*"\n"
def chunks_for(words, chunk_size)
class X.Example extends X.Object
@proxyMethod "attachmentManager.manageAttachment"
# Equivalent to:
# manageAttachment: ->
# @attachmentManager.manageAttachment.apply(@attachmentManager, arguments)
@proxyMethod "delegate?.compositionDidChangeDocument"
# Equivalent to:
# compositionDidChangeDocument: ->
# @delegate?.compositionDidChangeDocument?.apply(@delegate, arguments)
sstephenson / bashprof.94736.log
Created Nov 18, 2013
Output of `bashprof ruby --version` (using rbenv)
View bashprof.94736.log
program=/Users/sam/.rbenv/shims/ruby --version
command=set -e
program=/Users/sam/.rbenv/shims/ruby --version
command=[ -n "$RBENV_DEBUG" ]
sstephenson / Simple
Created Apr 11, 2013
Simple file/stream encryption using OpenSSL
View Simple

Simple file/stream encryption using OpenSSL

Create and store a 512-byte random encryption key named secret:

$ mkkey secret

Encrypt the contents of file with the secret key and write it to file.enc:

$ encrypt secret < file > file.enc
sstephenson / super.bash
Last active Jan 30, 2017
`super` in Bash
View super.bash
#!/usr/bin/env bash
source super.bash
foo() {
echo hello
super_function foo
foo() {
View gist:4751426
From: Sam Stephenson <>
Subject: Re: ruby-build hint
Date: Sun, 10 Feb 2013 12:25:56 -0600
To: Michał Papis <>
Hi Michał,
Thanks for the email.
You're right that `[[` is not POSIX sh-compliant. Nor are the following
View curl-progress
#!/usr/bin/env bash
# Wraps curl with a custom-drawn progress bar. Use it just like curl:
# $ curl-progress -O
# $ curl-progress > file.tar.gz
# All arguments to the program are passed directly to curl. Define your
# custom progress bar in the `print_progress` function.
View git-semver-tags
# Usage: git semver-tags [-p|--pre]
# Lists semver tags in the repository in order from newest to oldest.
# Useful for e.g. programmatically finding the latest release tag:
# `git semver-tags | head -n 1`.
# Tag names must be valid according to the SemVer 1.0.0 specification
View test_interrupt.rb
# Sledgehammer approach for ^Cing rake test runs
if Rails.env.test?
if `ps -wwp #{Process.ppid}` =~ /ruby/
trap("INT") {
Process.kill("KILL", Process.ppid)
sstephenson /
Created Jan 10, 2012
Tiny CoffeeScript testing
#!/usr/bin/env coffee
class TestCase
@run: (print, callback) ->
tests = (new this testName for testName in @getTestNames())
results = []
passed = true
print "1..#{tests.length}"
You can’t perform that action at this time.