Skip to content

Instantly share code, notes, and snippets.

@tigris
tigris / rails3.log
Created August 19, 2013 07:26
rails caching bug
Site -> has_many :pages
> Rails.cache.fetch('test') { a = Array.new ; Site.all.each{|s| a.push(s) if s.pages.count > 1 } ; a }
Site Load (0.7ms) SELECT "sites".* FROM "sites"
(0.7ms) SELECT COUNT(*) FROM "pages" WHERE "pages"."site_id" = 2
(0.7ms) SELECT COUNT(*) FROM "pages" WHERE "pages"."site_id" = 1
=> [#<Site id: 2, designer_id: 4, url: "http://tigris.id.au/", created_at: "2012-09-11 01:18:07", updated_at: "2012-09-11 01:18:07">, #<Site id: 1, designer_id: 1, url: "http://tigris.id.au/", created_at: "2012-09-02 16:39:54", updated_at: "2013-08-01 03:15:47">]
> Rails.cache.fetch('test') { a = Array.new ; Site.all.each{|s| a.push(s) if s.pages.count > 1 } ; a }
=> [#<Site id: 2, designer_id: 4, url: "http://tigris.id.au/", created_at: "2012-09-11 01:18:07", updated_at: "2012-09-11 01:18:07">, :@new_record, false]
@tigris
tigris / _test.rb
Last active December 18, 2015 04:39
Bug in Mail::Address
#!/usr/bin/env ruby
# encoding: utf-8
require 'bundler/setup'
require 'mail'
def formatted_email(name, email)
address = Mail::Address.new(email)
address.display_name = name
address.format
source 'http://rubygems.org'
gem 'rails', '4.0.0.beta1'
gem 'sqlite3'
@tigris
tigris / README.md
Last active December 14, 2015 11:28
laptop re-install notes

How to backup and upgrade Dan's laptop

TODO before backup

  • Export virtual machines to ~/Documents

Files to backup before start

  • ~/.purple (pidgin config)
  • ~/.ievms (no configs, but super large so downloading again would be annoying)
@tigris
tigris / README.md
Created September 17, 2012 14:17
Ruby Net::FTP screwing encoding?

I don't get why when I upload (ftp.put) a copy of the same file, then download that copy, ruby thinks the content is different? Obviously something in Net::FTP is screwing with my ISO-8859-1 character in the file? I dunno, still trying to track it down.

@tigris
tigris / Gemfile
Created August 7, 2012 08:41
Demonstrate bundler following symlinks
# /tmp/foo/Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'unicorn'
@tigris
tigris / attributes.rb
Created August 3, 2012 12:27 — forked from shapeshed/unicorn
Unicorn / Monit setup
default['unicorn']['before_fork'] = %Q(
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
old_pid = '#{node['unicorn']['pid']}.oldbin'
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill('QUIT', File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
puts 'Old master alerady dead'
end
@tigris
tigris / gist:3000630
Last active October 6, 2015 13:28
Sublime Text 2 user prefs
{
"auto_complete_commit_on_tab": true,
"auto_match_enabled": false,
"color_scheme": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme",
"fold_buttons": false,
"hot_exit": false,
"ignored_packages":
[
"Vintage"
],
@tigris
tigris / chef_solo_bootstrap.sh
Created April 30, 2012 02:16 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo + Git
#!/usr/bin/env bash
GITHUB_USER="tigris"
GITHUB_PROJECT=...
GIT_BRANCH="master"
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libyaml-dev libreadline-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
@tigris
tigris / autolink.rb
Created June 16, 2011 07:25
twitter-text-rb failure on double greater than