Skip to content

Instantly share code, notes, and snippets.

View mathie's full-sized avatar

Graeme Mathieson mathie

View GitHub Profile
@mathie
mathie / gist:1111
Created July 22, 2008 16:00 — forked from st23am/gist:1098
def test
str = "this is a test of new pastie"
# print out the test msg
puts str
end
# Replaces accented characters with their ascii equivalents.
def transliterate(string)
Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
end
# The iconv transliteration code doesn't function correctly
# on some platforms, but it's very fast where it does function.
if "foo" != Inflector.transliterate("föö")
def transliterate(string)
string.mb_chars.normalize(:kd). # Decompose accented characters
mathie@Tullibardine ~ (master) $ irb
>> class Foo
>> def bar
>> "bar"
>> end
>> end
=> nil
>> Foo.new.bar
=> "bar"
>> class Foo

This is pretty much off the top of my head right now. If it doesn't sound entirely crazy, please get back to me and I'll refine it!

"It's not the code, stupid!"

In all the businesses I've been involved in, as an employee, a consultant and even my own business, one thing I've consistently seen, which ... surprises the engineer in my heart: technical issues rarely cause show stopping problems. Most often, it boils down to people. I'd like to tell a few (true, but carefully sanitised) stories about start ups I've been involved in, some of the non-technical issues they've had and what I've learned from them. Then, hopefully, the folks listening to the talk don't have to make the same mistakes I've made. :-)

Couple of specific examples:

  • If your management team doesn't get along, it's just not going to work. (This will be an interesting one to anonymise, but it's a fun story!)
class Neat < ActiveRecord::Base
class << self
def new(params = {})
if self == Search
if params.with_indifferent_access.include?(:evil_quota)
Evil.new(params)
elsif params.include?(:doom_level)
Doomed.new(params)
else
super
@mathie
mathie / gist:147702
Created July 15, 2009 13:25
Changing the locale on Ubuntu
ubuntu@domU-12-31-39-02-68-C2:~$ sudo vim /var/lib/locales/supported.d/local
ubuntu@domU-12-31-39-02-68-C2:~$ cat /var/lib/locales/supported.d/local
en_US ISO-8859-1
en_US.UTF-8 UTF-8
en_GB ISO-8859-1
en_GB.UTF-8 UTF-8
ubuntu@domU-12-31-39-02-68-C2:~$ sudo dpkg-reconfigure locales
Generating locales...
en_GB.ISO-8859-1... done
en_GB.UTF-8... done
15 * * * * /u/apps/btmh/current/script/runner -e production Feed.update_all_feeds
# FIXME: For some deeply boring reason, in order to deploy to the staging
# server, you currently have to change the application name to foobarapp_staging,
# rather than foobarapp. I'm working on fixing it, but it turns out to be more
# complex than it ought to have been.
set :application, "foobarapp_staging"
after 'staging' do
raise "Please change the top of config/deploy.rb so that it reads 'set :application, \"foobarapp_staging\"' and try again." unless application == 'foobarapp_staging'
end
after 'production' do
mathie@Tullibardine Git $ rvm use 1.8.6
mathie@Tullibardine Git $ ruby --version
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-darwin10.0.0]
mathie@Tullibardine Git $ irb
Warning, Bond is not available. 'gem install bond' to enable it.
Warning, Hirb is not available. 'gem install hirb' to enable it.
ruby-1.8.6-p383 > require 'iconv'
=> true
ruby-1.8.6-p383 > Iconv
=> Iconv
task :prevent_brainfart_apocalypse do
raise "You're running in production" if Rails.env.production?
end
protect_me_from_myself_tasks = %W(db:setup)
protect_me_from_myself_tasks.each do |task_name|
Rake::Task[task_name].prerequisites.insert 0, 'prevent_brainfart_apocalypse'
end