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
#!/bin/bash | |
# From http://chrismccord.com/blog/2013/01/09/better-heroku-db-push-and-db-pull/ | |
# | |
# Postgres equivalent to heroku db:push. | |
# Pushes local database up to heroku application database. | |
# | |
# Requirements: psql --version >= 9.2.2 | |
# | |
# Usage: |
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
output = %x[heroku apps] | |
repos = output.split("\n").select{|line| line.length > 0 and line[0..2] != "===" }.map{|line| line.split[0] } | |
repos.each do |repo| | |
unless Dir.exists?(repo) | |
puts %x[git clone [email protected]:#{repo}.git] | |
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
cd /tmp | |
wget http://apache.mirrors.pair.com/httpd/httpd-2.4.2.tar.bz2 | |
tar xzvf httpd-2.4.2.tar.bz2 | |
cd httpd-2.4.2 | |
./configure | |
make | |
sudo cp support/ab /usr/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
# http://en.wikipedia.org/wiki/F1_score | |
# true positives, false positives, false negatives | |
def f1_score(tp, fp, fn) | |
precision = tp / (tp + fp).to_f | |
recall = tp / (tp + fn).to_f | |
2.0 * precision * recall / (precision + recall) | |
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 EmailValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
record.errors[attribute] << (options[:message] || "is not an email") unless | |
value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i | |
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
/* | |
* Preload images that aren't visible on page load | |
* Works for images and background images | |
* | |
* $("#img1, #div2").preload() | |
*/ | |
$.fn.preload = function() { | |
this.each( function() { | |
src = $(this).attr("src"); |
NewerOlder