Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@ndbroadbent
ndbroadbent / .gitattributes
Created January 11, 2012 08:35 — forked from tpope/.gitattributes
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundleinstall
db/schema.rb merge=railsschema
@sj26
sj26 / README.md
Created January 19, 2012 07:41
Run MailCatcher in the background, always, on OS X

Place me.mailcatcher.plist into ~/Library/LaunchAgents, then run launchctl load ~/Library/LaunchAgents/me.mailcatcher.plist.

If you use pow, echo 1080 > ~/.pow/mailcatcher and go to http://mailcatcher.dev, otherwise use http://localhost:1080.

Currently pow doesn't seem to pass websockets through correctly. Looking into this.

@panicsteve
panicsteve / gist:1641705
Created January 19, 2012 18:26
Form letter template for acquired startups
Dear soon-to-be-former user,
We've got some fantastic news! Well, it's great news for us anyway. You, on
the other hand, are fucked.
We've just been acquired by:
[ ] Facebook
[ ] Google
[ ] Twitter
@pat
pat / gist:1776846
Created February 9, 2012 02:47
SSL Redirection RSpec Matcher
RSpec::Matchers.define(:redirect_to_ssl) do
description { 'redirect to same page using the HTTPS protocol' }
match { |status|
response.redirect_url == request.url.gsub(/^http:/, 'https:')
}
end
# in spec/requests or similar...
get('/admin/sign_in').should redirect_to_ssl
@sj26
sj26 / php_postgresql.rb
Created February 22, 2012 12:21
Homebrew formula for PHP PostgreSQL extensions
require 'formula'
require 'net/http'
# This is an odd formula which adapts itself to whatever version of PHP
# is installed with the current version of OS X to install the missing
# PostgreSQL extension.
class PhpPostgresql < Formula
homepage 'http://www.php.net/'
# author: Samuel Cochran <sj26@sj26.com>
@sj26
sj26 / uploader_input.rb
Created March 13, 2012 02:50
Formtastic input for carrierwave uploaders
# A formtastic input which incorporates carrierwave uploader functionality.
#
# Intelligently adds the cache field, displays and links to the current
# value if there is one, adds a class to the wrapper when replacing an
# existing value, allows removing an existing value with the checkbox
# taking into account validation requirements.
#
# There are several options:
#
# * Toggle the replacement field with `replaceable: true/false`.
@sj26
sj26 / rspec_with_translations.rb
Created March 14, 2012 03:42
Temporarily swap in I18n translations for a context
module RSpecWithTranslations
def with_translations *args, &block
translations = args.extract_options!
args = args.presence || ["with translations"]
context *args do
around do |example|
begin
old, I18n.backend = I18n.backend, I18n::Backend::KeyValue.new(translations)
example.call
@funny-falcon
funny-falcon / perf_and_gc.diff
Created May 4, 2012 08:47
Ruby-1.9.3-p194 performance patch
diff --git a/common.mk b/common.mk
index eb89a2b..59cdfe4 100644
--- a/common.mk
+++ b/common.mk
@@ -630,7 +630,8 @@ file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \
gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \
{$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \
{$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \
- {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h
+ {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h \
@garybernhardt
garybernhardt / selectable_queue.rb
Last active November 23, 2022 12:42
A queue that you can pass to IO.select.
# A queue that you can pass to IO.select.
#
# NOT THREAD SAFE: Only one thread should write; only one thread should read.
#
# Purpose:
# Allow easy integration of data-producing threads into event loops. The
# queue will be readable from select's perspective as long as there are
# objects in the queue.
#
# Implementation:
@miketaylr
miketaylr / shebang
Created January 29, 2013 21:03
shebang quine
#!/bin/cat