Because loading gems can take longer than you think
Now available as a gem - get it here
| /* | |
| * 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"); |
| 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 |
| # 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 |
| 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 |
| 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 |
| #!/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: |
Because loading gems can take longer than you think
Now available as a gem - get it here
| = javascript_include_tag "http://maps.googleapis.com/maps/api/js?sensor=false" | |
| #map style="height: 500px;" | |
| javascript: | |
| var pings = #{@pings.to_json(root: false).html_safe}; | |
| $(document).ready( function() { | |
| var mapOptions = { | |
| zoom: 13, |
| -- median | |
| -- http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html | |
| CREATE OR REPLACE FUNCTION array_median(numeric[]) | |
| RETURNS numeric AS | |
| $$ | |
| SELECT CASE | |
| WHEN array_upper($1,1) = 0 THEN null | |
| WHEN mod(array_upper($1,1),2) = 1 THEN asorted[ceiling(array_upper(asorted,1)/2.0)] | |
| ELSE ((asorted[ceiling(array_upper(asorted,1)/2.0)] + asorted[ceiling(array_upper(asorted,1)/2.0)+1])/2.0) END |
Checkout the blog post for the whole story.
Setup Bower and install components:
npm install -g bower
bower installBefore deploying to Heroku, switch to the multi buildpack: