Skip to content

Instantly share code, notes, and snippets.

View ariejan's full-sized avatar

Ariejan de Vroom ariejan

View GitHub Profile
class YourModel < ActiveRecord::Base
validates_format_of :email, :with => RFC822::EmailAddress
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
@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
@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>
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
SELECT p.name, t.tag_name
FROM product p
LEFT JOIN tag t ON p.tag_id = t.id
1 | Product A | Ruby
1 | Product A | Rails
2 | Product B | Ruby
How can I change this query to return:
### SQL
# Use the below query in Sequel Pro => Export to XML
#
# This includes tags, not categories
#
# SELECT p.ID, p.post_date, p.post_content, p.post_title, p.post_name, GROUP_CONCAT(t.name SEPARATOR ', ') AS tags
# FROM wp_posts p
# LEFT JOIN wp_term_relationships tr ON tr.object_id = p.id
# LEFT JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
# LEFT JOIN wp_terms t ON tt.term_id = t.term_id
# Use MacPorts, least priority
# For the amazon-ec2 gem
export EC2_URL="https://eu-west-1.ec2.amazonaws.com"
# jEdit with large memory allocation
alias jedit='java -Xms512m -Xmx1024m -jar /Applications/jEdit.app/Contents/Resources/Java/jedit.jar'
## export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH=/Users/ariejan/.homebrew/bin:/opt/local/bin:/opt/local/sbin:$PATH:/usr/local/bin:/usr/local/sbin
class MagicWorker
def self.perform(*args)
logger.info("This is a stub worker.")
end
end
$ master ★ $ time rake spec
.
Finished in 0.385567 seconds
1 example, 0 failures
real 2m19.023s
user 0m34.373s
sys 0m5.892s