Skip to content

Instantly share code, notes, and snippets.

View ariejan's full-sized avatar

Ariejan de Vroom ariejan

View GitHub Profile
SELECT FROM_UNIXTIME(CEILING(UNIX_TIMESTAMP(created_At)/600)*600) AS timeslice,
COUNT(id) AS count
FROM export_articles
GROUP BY timeslice
ORDER BY timeslice
@ariejan
ariejan / snippet.xml
Created November 25, 2009 10:01
A light-weight Ruby/Haml/Rspec theme for TextMate
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Epic</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@ariejan
ariejan / blah.rb
Created November 20, 2009 15:57
RSpec + Mocha + Catching raised exceptions = FAIL
class Blah
def self.go
begin
Blah.export
rescue => e
logger.error(e)
end
logger.info("Blah#go done")
end
class Feed
has_many :imports
# SQL:
# SELECT feeds.*, COUNT(imports.id) AS import_count
# FROM `feeds`
# LEFT OUTER JOIN imports ON imports.feed_id = feeds.id
# GROUP BY imports.feed_id
# ORDER BY import_count DESC
# LIMIT 5
class YourModel < ActiveRecord::Base
validates_format_of :email, :with => RFC822::EmailAddress
end
@ariejan
ariejan / template.rb
Created September 4, 2009 21:51
Rails 2.3.x template
# This Rails 2.3.x template will create a new git-based Rails project
# with Cucumber, RSpec and Remarkable pre-installed and ready to go.
#
# (C) 2009 under the MIT License by Ariejan de Vroom <[email protected]>
#
# USAGE:
# rails -d mysql -m http://gist.github.com/181167.txt APP_NAME
# Delete unnecessary files
@ariejan
ariejan / README
Created August 28, 2009 08:44
Easily report app version and revision numbers.
You must be using git and capistrano to deploy your app. Capistrano will place a file in your Rails.root named 'REVISION'. Tested with the following capistrano setting:
set :scm, :git
set :deploy_via, :remote_cache
# This little nugget will remove an existing rake task. This allows you to
# redefine tasks.
#
# remove_task :test
# task :test => [:spec, :features]
#
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
# Use ApiKey.generate to generate a new API key
class ApiKey < ActiveRecord::Base
validates_presence_of :key
validates_uniqueness_of :key
def self.generate(description = "No description")
key = Digest::SHA1.hexdigest("--#{Time.now}--#{description}--")
ApiKey.create(:description => description, :key => key)
end
%! program = pdflatex
\documentclass[9pt,twoside,pageany]{memoir}
% Sets the papersize.
% \settrimmedsize{4.25in}{6.875in}{*}
% Sets the papersize.
\setstocksize{17.463cm}{10.795cm}