This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourModel < ActiveRecord::Base | |
validates_format_of :email, :with => RFC822::EmailAddress | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blah | |
def self.go | |
begin | |
Blah.export | |
rescue => e | |
logger.error(e) | |
end | |
logger.info("Blah#go done") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MagicWorker | |
def self.perform(*args) | |
logger.info("This is a stub worker.") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ master ★ $ time rake spec | |
. | |
Finished in 0.385567 seconds | |
1 example, 0 failures | |
real 2m19.023s | |
user 0m34.373s | |
sys 0m5.892s |