Skip to content

Instantly share code, notes, and snippets.

View alassek's full-sized avatar

Adam Lassek alassek

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.

require 'twitter'
user = "sferik"
query = /rimm/i
(1..16).each do |page|
Twitter.user_timeline(user, :page => page, :count => 200).each do |tweet|
puts tweet.id.to_s + ": " + tweet.text if query.match(tweet.text)
end
end
@mislav
mislav / Gemfile
Created August 31, 2011 21:48
How to integrate Compass with Rails 3.1 asset pipeline
group :assets do
gem 'sass-rails', '~> 3.1.0'
gem 'coffee-rails', '~> 3.1.0'
gem 'uglifier'
gem 'compass'
end
@alassek
alassek / typeIntent.js
Created September 14, 2011 22:13
Trigger change event without hitting enter, like Google Live Search
/*
* Copyright (c) 2011 Lyconic, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@sgreenfield
sgreenfield / pull-it.js
Last active September 29, 2015 22:38
Quick and Dirty Bookmarklet for Github Pull Requests *** FF 20 Security prevents bookmarklets. about:config => security.csp.enable: false
javascript:(function(){var%20$commits=$('.commits-condensed%20td.message'),title=$.trim($commits.last().text())+'...',pullBody='';$commits.each(function(){pullBody+=$.trim($(this).text())+'%20%20';});$('.title.required').val(title);$('#pull_body').val(pullBody);$('.form-actions .button.primary').removeAttr('disabled');})();
@technoweenie
technoweenie / gist:2155760
Created March 22, 2012 04:03
track meta data with resque jobs, like when it was queued.
module Resque
def push_with_meta(queue, item)
if item.respond_to?(:[]=)
item[:meta] = {:queued_at => Time.now.to_f}
end
push_without_meta(queue, item)
end
class Job
# Returns a Hash of the meta data related to this Job.
@r38y
r38y / application_controller.rb
Created May 17, 2012 18:21 — forked from robotmay/application_controller.rb
Examples of low level caching
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter do
@categories = Rails.cache.fetch("global/categories", expires_in: 10.minutes) do
Category.where("posts_count > 0").all
end
end
end
@dre1080
dre1080 / varbinary_migration_columns_initializer.rb
Created August 24, 2012 14:18
Setup varbinary columns or any other unsupported data type in rails migrations
# Provide varbinary columns in a Migration.
# Probably a better way to do this?
#
# Usage:
# => t.varbinary :column, :limit => 20, ....[options]
#
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil)
return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym
@johnkpaul
johnkpaul / app.js
Created August 4, 2012 18:45
IE9- and Backbone.history's pushState
//in your application, rather than using window.location to get the current url
App.getLocation = function(){
return window.location.protocol + '//' + window.location.host
+ '/' + Backbone.history.options.root + Backbone.history.getFragment()
}
@carlzulauf
carlzulauf / thin.rb
Last active December 17, 2015 01:19
Thin initd script. Spawns thin daemons from a config directory using a specific non-privileged user (`carl`).
#!/usr/bin/env ruby
# thin init script
# install to /etc/init.d/thin
# crazy debian LSB header stuff
### BEGIN INIT INFO
# Provides: thin
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs