This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# BOM=`echo -ne '\xEF\xBB\xBF'` | |
# echo "$BOM$(cat $1)" > $1 | |
(printf '\xEF\xBB\xBF'; cat $1) > $1.enc; mv -f $1.enc $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCompany::Migration < ActiveRecord::Migration | |
def self.add_column(*args) | |
begin | |
super | |
rescue => e | |
if e.message =~ /Duplicate/ | |
puts "WARNING, a migration line was skipped due to it already existing: #{e.message}" | |
else | |
raise e | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pmarreck$ rvm --trace requirements | |
+ [[ -n '' ]] | |
+ export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > ' | |
+ PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > ' | |
+ /scripts/cli : __rvm_parse_args() 769 > [[ -z '' ]] | |
+ /scripts/cli : __rvm_parse_args() 769 > [[ -n '' ]] | |
+ /scripts/cli : __rvm_parse_args() 771 > [[ 0 -eq 1 ]] | |
+ /scripts/cli : __rvm_parse_args() 771 > [[ -n '' ]] | |
+ /scripts/cli : __rvm_parse_args() 19 > [[ -n requirements ]] | |
+ /scripts/cli : __rvm_parse_args() 21 > rvm_token=requirements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We have a website with a lot of subdomains, each corresponds to a Site object, and the Site model/DB gets hit A LOT even though it rarely changes. | |
# We were looking at ways to optimize/cache this. | |
def current_site(memoize = true) | |
# (assumes "subdomain" and "domain" are available from URL information, this code may need to be tweaked) | |
@current_site = nil unless memoize | |
@current_site ||= Site.allocate.init_with('attributes' => | |
Rails.cache.fetch("Site#{subdomain}.#{domain}") do | |
Site.find_by_subdomain_and_domain(domain, subdomain).attributes | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HOMEBREW CONFIG | |
# Move /usr/local/bin to the front of PATH by subbing it out and prepending | |
export PATH=/usr/local/bin:${PATH/\/usr\/local\/bin:/} | |
# add my user bin to PATH | |
export PATH=$PATH:~/bin | |
# stop checking for mail | |
unset MAILCHECK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, install the Sublime package SublimeExternalCommand with the Package Control sublime package. | |
# Then add the following file in your ~/bin (or somewhere in your PATH, note that you may have to change some paths later here) and call it "rubyhashflip" and chmod +x it: | |
#!/usr/bin/env ruby | |
begin | |
require 'hash_syntax' | |
rescue LoadError | |
puts `gem install hash_syntax 2>&1` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require 'delegate' | |
# ExtraAttributes: An object that lets you sneak as many return values as you want | |
# through a single scalar-looking return value. | |
# Any return values set are immutable. | |
# Example usage: | |
# def some_method | |
# ExtraAttributes.new(200, debug: 'from some_method') | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module StringUtils | |
# Unindents a multiline string, | |
# even if the first line is not the one with the least whitespace. | |
# Best used with heredocs like this: <<-EOS.unindent ... | |
# Note that if there are lines that are just newlines that | |
# those will not break the next minimum indent length due to (?!\n) in the regex. | |
# This is to get around editors which auto strip trailing whitespace on lines. | |
# Otherwise any stripped whitespace on a blank line would kill the unindenting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
# Get Sublime to use your rvm ruby... Change your ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build | |
# (for ST3: ~/Library/Application Support/Sublime Text 3/Packages/User/Ruby.sublime-build) to this, replacing YOURUSERNAME. | |
# I am still looking to optimize this further... For example, avoiding hardcoding by using something like $HOME, although | |
# I have yet to get any form of that to work. | |
{ | |
"working_dir": "${project_path}", | |
"cmd": [ | |
"/Users/YOURUSERNAME/.rvm/bin/rvm-auto-ruby", "-Ilib:test", "$file" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HashUtils | |
# Pass in indexes as an array of keys | |
# def traverse(indexes) | |
# k = indexes.shift | |
# unless k.nil? | |
# v=self[k] | |
# if v.is_a?(Hash) | |
# !indexes.empty? ? v.traverse(indexes) : v | |
# else | |
# indexes.empty? ? v : nil |