Skip to content

Instantly share code, notes, and snippets.

#!/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)
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 November 18, 2013 18:24
Output of `bashprof ruby --version` (using rbenv)
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 April 11, 2013 23:48
Simple file/stream encryption using OpenSSL

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 January 30, 2017 01:40
`super` in Bash
#!/usr/bin/env bash
source super.bash
foo() {
echo hello
}
super_function foo
foo() {
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
#!/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.
#
#!/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
# 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 January 10, 2012 19:31
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}"