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 Time | |
def format_compact(precision = :second, inc_utc = true) | |
prec = [:year, :month, :day, :hour, :minute, :second].index precision | |
fmt_a = ["%Y","%m","%d","_%H","%M","%S"][0..prec] | |
fmt = fmt_a.join('') | |
self.strftime("#{fmt}#{'%Z' if inc_utc}") | |
end | |
def format_datestamp(inc_utc = true) | |
self.strftime("%Y%m%d#{'%Z' if inc_utc}") | |
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
lifebooker@lifebookers-Mac-mini-2[:~[$ /usr/bin/env HOMEBREW_TEMP=/Users/lifebooker/Developer/tmp /Users/lifebooker/Developer/bin/brew install wget | |
==> Downloading http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2 | |
File already downloaded in /Users/lifebooker/Library/Caches/Homebrew | |
==> Downloading patches | |
######################################################################## 100.0% | |
==> Patching | |
patch unexpectedly ends in middle of line | |
/usr/bin/patch: **** Only garbage was found in the patch input. | |
Error: Failure while executing: /usr/bin/patch -f -p1 -i 001-homebrew.diff | |
lifebooker@lifebookers-Mac-mini-2[:~[$ |
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 ruby | |
class Utf8Checker | |
def initialize(path = `pwd`.chomp) | |
@files = Dir["#{path}/**/**"] | |
@total_num = @files.count | |
puts "#{@total_num} files to process." | |
@num_left = @total_num | |
@valid = false | |
@err = false |
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
# 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
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 |