Skip to content

Instantly share code, notes, and snippets.

# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@mnot
mnot / sun buffering goes wild
Created August 11, 2011 02:32
The raw HTTP of a GET response from http://www.sun.com/ (before the Oracle acquisition), reproduced here in its entirety.
HTTP/1.1 200 OK
Server: Sun-Java-System-Web-Server/7.0
Date: Mon, 07 Dec 2009 07:25:34 GMT
P3p: policyref="http://www.sun.com/p3p/Sun_P3P_Policy.xml", CP="CAO DSP COR CUR ADMa DEVa TAIa PSAa PSDa CONi TELi OUR SAMi PUBi IND PHY ONL PUR COM NAV INT DEM CNT STA POL PRE GOV"
Cache-control: public
Set-cookie: JROUTE=W2VMz2yu926eYGvP; Path=/
X-powered-by: JSP/2.1
Set-cookie: JSESSIONID=80765ae114eab08df95a11208c62; Path=/
Content-type: text/html;charset=UTF-8
Via: 1.1 https-www
@KenMacD
KenMacD / cmd.md
Created October 7, 2011 02:41
GPG Offline Master Key
require 'slop'
optspec = <<-SPEC
ruby foo.rb [options]
---
n,name= Set your name
a,age= Set your age
v,verbose Enable verbose mode
debug Enable debug mode
SPEC
@davatron5000
davatron5000 / gist:2254924
Created March 30, 2012 20:57
Static Site Generators

Backstory: I decided to crowdsource static site generator recommendations, so the following are actual real world suggested-to-me results. I then took those and sorted them by language/server and, just for a decent relative metric, their Github Watcher count. If you want a heap of other projects (including other languages like Haskell and Python) Nanoc has the mother of all site generator lists. If you recommend another one, by all means add a comment.

Ruby

(function($){
var insertAtCaret = function(value) {
if (document.selection) { // IE
this.focus();
sel = document.selection.createRange();
sel.text = value;
this.focus();
}
else if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
@mislav
mislav / readme.md
Last active December 13, 2015 19:18
Update script for your Twitter archive
  1. Get your Twitter archive;
  2. Save this script as an executable in the root folder of your tweets archive;
  3. Execute the script from anywhere (e.g. a cron job).

It auto-installs grailbird_updater in an isolated location. Thanks, @DeMarko!

@pragdave
pragdave / gist:4981930
Created February 19, 2013 00:13
The Ruby 2 prepend() method makes method chaining a lot easier.
module SystemHook
private
def system(*args)
super.tap do |result|
puts "system(#{args.join(', ')}) returned #{result.inspect}"
end
end
end
class Object
@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() {
@DanielleSucher
DanielleSucher / one_char.sh
Last active December 17, 2015 22:59 — forked from aprescott/gist:5683945
Bash script to find all single-character commits in a git repository
first_commit=$(git log --pretty=format:%H | tail -1)
git rev-list --all --no-merges |
while read commit; do
if [ $commit == $first_commit ]; then break; fi;
IFS_backup=$IFS
IFS=$'\n'
diff_lines=( $(git diff --numstat --minimal -U0 --word-diff=porcelain $commit^ $commit | grep -E '^(\+[^+]|-[^-]).*$') )
IFS=$IFS_backup