Skip to content

Instantly share code, notes, and snippets.

View joshua's full-sized avatar
🌮

Joshua Suggs joshua

🌮
View GitHub Profile
def set_locale
locale = params[:locale].to_s
if !locale.blank?
cookies[:preferred_lang] = { :value => locale, :expires => 10.years.from_now }
session[:update_lang] = locale # remember preferred setting for this session
else
locale = cookies[:preferred_lang]
end
@nicksieger
nicksieger / thread_dump_on_quit.rb
Created August 29, 2012 14:38
kill -QUIT thread dump in Ruby. Seems like I need this and forget exactly how to do it.
trap("QUIT") do
Thread.list.each do |t|
$stderr.puts
$stderr.puts t.inspect
$stderr.puts t.backtrace.join("\n ")
end
end
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@gruber
gruber / gist:1063605
Created July 4, 2011 16:48
Simple Inbox Archiving Script for Apple Mail
-- See article here: http://daringfireball.net/2007/07/simple_inbox_sweeper
-- The following should be one long line:
set _description to "All unflagged, read messages in each IMAP account
inbox will be moved to the “Archive” mailbox corresponding to that
account. This action is not undoable."
tell application "Mail"
display alert "Archive read messages from IMAP inboxes?" buttons ¬
{"Cancel", "Archive"} cancel button 1 message _description
@karmi
karmi / geo_distance_filter_in_tire.rb
Created June 28, 2011 14:13
Geo Distance Filter Support in Tire/ElasticSearch
require 'tire'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/time/zones'
# Tire.configure { logger STDERR, level: 'debug' }
class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end
Tire.index 'venues' do
@dpk
dpk / gist:646570
Created October 26, 2010 09:05
View Generated Source in BBEdit
-- based on John Gruber's original Safari Source in BBEdit script
-- http://daringfireball.net/2003/01/safari_source_in_bbedit
-- and duct tape
tell application "Safari" to set theSource to do JavaScript "window.document.documentElement.outerHTML" in document 1
tell application "BBEdit"
activate
make new text window with properties ¬
{contents:theSource, source language:"HTML"}
@scottlowe
scottlowe / .bashrc
Created September 1, 2010 22:33
Part of a recipe for fronting Glassfish with Nginx
# ~/.bashrc: executed by bash(1) for non-login shells.
# If not running interactively, don't do anything
#[ -z "$PS1" ] && return
if [[ -n "$PS1" ]] ; then
# don't put duplicate lines in the history. See bash(1) for more options
#export HISTCONTROL=ignoredups
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
@bkeating
bkeating / howto-filemerge-git-osx.md
Created March 11, 2010 21:36
HOWTO: Using FileMerge (opendiff) with Git on OSX

HOWTO: Using FileMerge (opendiff) with Git on OSX

FileMerge (opendiff) can really come in handy when you need to visually compare merging conflicts. Other times it's just a nice visual way to review your days work.

The following method works by creating a simple bash script (git-diff-cmd.sh) that sets us up with the proper command line arguments for Git to pass off files to FileMerge.

# Pipe Ars Technica's live Apple event coverage into a Campfire room.
# http://arstechnica.com/apple/news/2010/01/tablet-live-event-liveblog.ars
#
# Usage:
# $ gem install -r hpricot tinder
# $ ruby -rubygems ars_live.rb -ssl mysubdomain myroomid myapikey
require "hpricot"
require "open-uri"
require "tinder"
@EmmanuelOga
EmmanuelOga / r191.txt
Created December 26, 2009 22:42
curb, typhoeus, net:http, em-http quick benchmark
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
curb (0.6.2.1)
em-http-request (0.2.5)
eventmachine (0.12.10)
typhoeus (0.1.13)
user system total real Memory (Kb)
4kb std
0.000000 0.000000 3.010000 ( 22.408594) 24,484