Skip to content

Instantly share code, notes, and snippets.

Sam Stephenson sstephenson

Block or report user

Report or block sstephenson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tweetstorm.rb
#!/usr/bin/env ruby
# Usage: tweetsplit.rb < tweetstorm.txt
# https://twitter.com/CoralineAda/status/869204799027372032
# 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)
View proxyMethod.coffee
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
sstephenson / bashprof.94736.log
Created Nov 18, 2013
Output of `bashprof ruby --version` (using rbenv)
View bashprof.94736.log
1384798995.146761
program=/Users/sam/.rbenv/shims/ruby --version
command=set -e
subshell=0
function=main
filename=/Users/sam/.rbenv/shims/ruby
lineno=2
1384798995.147108
program=/Users/sam/.rbenv/shims/ruby --version
command=[ -n "$RBENV_DEBUG" ]
@sstephenson
sstephenson / Simple Encryption.md
Created Apr 11, 2013
Simple file/stream encryption using OpenSSL
View Simple Encryption.md

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
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 <sstephenson@gmail.com>
Subject: Re: ruby-build hint
Date: Sun, 10 Feb 2013 12:25:56 -0600
To: Michał Papis <mpapis@gmail.com>
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 http://example.com/file.tar.gz
# $ curl-progress http://example.com/file.tar.gz > 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
#!/bin/sh
#
# 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)
Process.kill("KILL", Process.pid)
}
end
end
@sstephenson
sstephenson / test_case.coffee
Created Jan 10, 2012
Tiny CoffeeScript testing
View test_case.coffee
#!/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.