Skip to content

Instantly share code, notes, and snippets.

View jferris's full-sized avatar

Joe Ferris jferris

  • thoughtbot, inc.
  • Cambridge, MA
View GitHub Profile
@jferris
jferris / empty.hs
Created March 31, 2016 20:41
Empty Operator
(?) :: Foldable t => t a -> t a -> t a
a ? b
| null a = b
| otherwise = a
@jferris
jferris / asoundrc
Created March 8, 2016 14:47
Lennart!!!!
pcm.dmixed {
type asym
playback.pcm {
type dmix
ipc_key_add_uid true
ipc_key 5678293
ipc_perm 0660
ipc_gid audio
slave {
@jferris
jferris / combine.rb
Created March 3, 2016 16:44
Combine ranges
def combine_ranges(ranges)
if ranges.empty?
[]
else
first, *rest = ranges
rest.reduce([first]) do |result, current|
previous = result.pop
if previous.max + 1.day >= current.min
result << previous.min..current.min
else
@jferris
jferris / example_spec.rb
Created November 11, 2015 21:03
Use string comparisons for better spec failure messages
describe Person do
describe "#billable" do
it "returns people with a billable role" do
billable = create(:role, billable: true)
unbillable = create(:role, billable: false)
create(:person, name: "BillableOne", role: billable)
create(:person, name: "BillableTwo", role: billable)
create(:person, name: "Unbillable", role: unbillable)
result = Person.billable
@jferris
jferris / 02-apple-keyboard.conf
Created November 9, 2015 17:05
Apple Keyboard Configuration for Xorg on Arch
Section "InputClass"
Identifier "Apple Keyboard"
MatchProduct "Apple Inc. Apple Keyboard"
Option "XkbOptions" "altwin:swap_alt_win,ctrl:nocaps"
EndSection
@jferris
jferris / clean-html-entities.sh
Created October 7, 2015 20:56
"Programming"
#!/bin/zsh
original=$(cat)
print "$original" > /tmp/mutt_message
ascii=$(print "$original" | recode utf-8..iso-8859-1 2>&1)
if echo "${ascii}" | egrep --silent "recode: Invalid input"; then
message=$(cat /tmp/mutt_message)
@jferris
jferris / example.rb
Created April 15, 2015 15:29
Partially applied instance methods in Ruby
class User
def initialize(name)
@name = name
end
def greet(greeting, info)
"#{greeting}, #{@name}! FYI, #{info}."
end
end
> let a = [1]
> let b = [2]
> a + b
<interactive>:5:1:
No instance for (Num [t0]) arising from a use of ‘it’
In a stmt of an interactive GHCi command: print it
> (on (+) head) a b
3
@jferris
jferris / PKGBUILD
Last active August 29, 2015 14:08
Package build for ruby-build 20141113
# Maintainer: Vincent Demeester <vincent@sbr.io>
# Contributer: Alex Ogier <alex.ogier@gmail.com>
pkgname=ruby-build
pkgver=20141113
pkgrel=1
pkgdesc="Compile and install Ruby"
arch=('any')
url="http://github.com/sstephenson/ruby-build"
license=('MIT')
optdepends=('git: install ruby from git')
@jferris
jferris / compose.rb
Created October 29, 2014 18:32
Compose Functions in Ruby
class String
def blank?
self == ""
end
end
class Symbol
def *(other)
lambda { |instance| instance.__send__(other).__send__(self) }
end