Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@lperichon
lperichon / gist:836107
Created February 20, 2011 17:05
Fix DelayedJob - Spree conflict
module Searchlogic
module NamedScopes
# Handles dynamically creating named scopes for ordering by columns. Example:
#
# User.ascend_by_id
# User.descend_by_username
#
# See the README for a more detailed explanation.
module Ordering
module InstanceOverrideMethods
@JeanMertz
JeanMertz / syntax_highlighting.py
Created April 18, 2011 08:39
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@thijsc
thijsc / gist:1391107
Created November 24, 2011 11:08
Select item from chosen js select with Capybara and Selenium
def select_from_chosen(item_text, options)
field = find_field(options[:from])
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("$('##{field[:id]}').val('#{option_value}')")
end
@turadg
turadg / subdomains.rb
Last active January 21, 2024 19:45 — forked from rtekie/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@archfear
archfear / fix_whitespace.rake
Last active December 27, 2015 17:59
Pre-commit hook for git which removes trailing whitespace, converts tabs to spaces and adds a newline to the end of the file if missing.
script_file = File.join(Rails.root, "script", "git_fix_whitespace.sh")
desc "Remove trailing whitespace and convert tabs to spaces"
task :fix_whitespace do
`sh #{script_file} -f`
end
namespace :fix_whitespace do
desc "Installs a git pre-commit hook which removes trailing whitespace and converts tabs to spaces"
task :install, :force do |t, args|
@patrickhammond
patrickhammond / android_instructions.md
Last active March 29, 2024 20:14
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@cryptix
cryptix / fotos.go
Created June 15, 2014 16:03
revel image upload example
package controllers
import (
"bytes"
"image"
"image/gif"
"image/jpeg"
"image/png"
"io"
"net/http"
@nk9
nk9 / largestFiles.py
Last active November 14, 2023 09:47
Python script to find the largest files in a git repository.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python script to find the largest files in a git repository.
# The general method is based on the script in this blog post:
# http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
#
# The above script worked for me, but was very slow on my 11GB repository. This version has a bunch
# of changes to speed things up to a more reasonable time. It takes less than a minute on repos with 250K objects.
#
@pathouse
pathouse / README.md
Created July 13, 2014 17:53
Server Logging in Go

Server Event Logging in Go

Inspo

Many thanks to https://github.com/jadekler/git-go-websiteskeleton who got me started in this direction. Jadekler was in turn inspired by https://gist.github.com/cespare/3985516. Ultimately, this implementation has a lot more in common with cespare's. There are a few minor differences. I mainly wrote this one to teach myself exactly what was going on (hence all the comments) and to demonstrate the inclusion of the gorilla/mux framework without using Jadekler's technique of two separate http muxes.