Skip to content

Instantly share code, notes, and snippets.

View damncabbage's full-sized avatar
🙅‍♀️
permanent omnishambles

Robin Howard damncabbage

🙅‍♀️
permanent omnishambles
View GitHub Profile

An ActiveRecord conundrum

I'm going to describe a weird problem I faced when using ActiveRecord today. To protect the innocent, I'm not going to talk about the app I'm actually working on but will instead discuss a hypothetical but isomorphic database design for a clone of the popular blogging platform Tumblr.

Tumblr lets you publish various different sorts of content. We might be tempted to shove all these types in a big STI table, but the types are all quite different from one another and so we give them their own tables.

Hi!

We're looking for a junior to mid level Javascript and/or Ruby developer to join our team at The Exchange Group.

The Exchange Group is best known for online bike marketplace, bikeexchange.com.au, which in the last couple of years has expanded to New Zealand and Germany. We've also added tinitrader.com.au, renoexchange.com.au and furnitureexchange.com.au to the mix.

The application is primarily Ruby on Rails 3.2, which we're planning on upgrading to 4.0 in the near future. We've brought in AngularJS to several sections of the site already: our new search is entirely Angular. As our application grows, we'll be reducing our reliance on a monolithic Rails application and splitting things into UI & API implementations; this is where you'll come in.

The successful applicant will:

#!/usr/bin/env ruby
changed = `git diff --numstat origin/master | awk '{ print $3 }' | grep -E '(\\.rb|\\.rake)$' | grep -v db/schema`
changed = changed.split("\n").select { |c| File.exist?(c) }
if changed.length > 0
system "bundle exec rubocop #{ARGV.join(' ')} #{changed.join(' ')}"
else
puts "No changes."
@mmb
mmb / pixelize.rb
Created January 11, 2011 03:35
convert image into retro 8-bit looking image
require 'RMagick'
# convert image intro retro 8-bit looking image
# http://matthewm.boedicker.org/
# find NES, SNES, etc. palette image on the web
palette = Magick::ImageList.new('/tmp/Palette_NTSC.png')
img = Magick::ImageList.new('/tmp/input.jpg')
@cararemixed
cararemixed / example.rb
Created May 13, 2011 17:54
Better routes
uri 'contacts', name: 'contacts' do
get 'contacts#index'
end
uri 'contacts/:id/addresses', name: 'contact_addresses' do
put 'contact_addresses#replace'
post 'contact_addresses#create'
delete 'contact_addresses#delete'
end
@benhoskings
benhoskings / application_controller.rb
Created September 1, 2011 00:04
A git ref in every response!
class ApplicationController < ActionController::Base
before_filter {
headers['X-Refspec'] = TC::Services.refspec
}
end
@rondale-sc
rondale-sc / ruby-hough.rb
Created September 21, 2011 23:05
The hough transform in ruby. Only looks for straight black lines.
begin
['oily_png', 'pp'].each do |g|
require g
end
rescue LoadError => e
puts "Could not load '#{e}'"; exit
end
class Hough
Convert = "/usr/local/bin/convert"
@mipearson
mipearson / GIVING_A_TALK.md
Created December 14, 2011 23:09
Prerequisites For Giving a Presentation at a User's Group

Prerequisites For Giving a Presentation at a User's Group

You've decided to get up in front of a bunch of strangers and talk about a topic for thirty to fifty minutes. You're going to convey your unique, personal experience and everybody is going to afterwards feel as if they've learned something new.

For most talks at user groups, this doesn't happen, and it's easily fixable.

You absolutely, no questions asked, need to:

  • Know what you're presenting: rehearse it to yourself, once, out loud. If that's too awkward for you it's going to be more awkward when you're back-pedalling and skipping sections in front of thirty to fifty of your peers. If you have demonstration content, test it from beginning to end, especially the bits that you assume will 'just work'.
@amouat
amouat / .conkyrc
Created January 6, 2012 20:11
Conky config for TODO system
#.conkyrc for TODOs
#
# Slightly modified version of basic config
#
# Adrian Mouat 2012
#
alignment top_right
background yes
border_width 1
default_color white
@jonathanclarke
jonathanclarke / Avoiding precompile if no assets change when synching to S3
Created February 13, 2012 03:13
Avoiding precompile if no assets change when synching to S3
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end