This file contains 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
# {:a => [1], :b => [2]} => {:a => 1, :b => 2} | |
def flatten_hash_values(h) | |
Hash[h.map {|m, i| [m, i.first]}] | |
end |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Bar Chart</title> | |
<script type="text/javascript" src="javascript/d3.v2.min.js"></script> | |
<style type="text/css"> | |
.chart { | |
background: #00ccff; | |
margin: 10px; |
This file contains 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
require 'active_support/all' | |
(12.months.ago.to_i..0.months.ago.to_i).step(1.week).to_a.push(Time.new).each_cons(2) do |from, to| | |
puts "From #{Time.at(from).to_s} to #{Time.at(to).to_s}" | |
end | |
OUTPUT | |
====== | |
From 2012-08-28 08:11:55 +0100 to 2012-09-04 08:11:55 +0100 | |
From 2012-09-04 08:11:55 +0100 to 2012-09-11 08:11:55 +0100 |
This file contains 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
watch 'mongo app_db --eval "printjson(db.sessions.findOne({_id: ObjectId(\"51a62b06f9b19aac870000b1\")}))"' |
This file contains 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
xively.setKey( "YOUR API KEY HERE" ); | |
var startOfYesterday = moment().subtract("day", 1).startOf('day'); | |
var endOfYesterday = moment().startOf('day'); | |
console.log(startOfYesterday); | |
console.log(endOfYesterday); | |
var query = { | |
start: startOfYesterday.toJSON(), |
This file contains 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
install.packages('RCurl') | |
install.packages("ggplot2") | |
library(ggplot2) | |
library(RCurl) | |
# grab an api key from cosm and put it here | |
api_key = 'YOUR_API_KEY' | |
# your feed id | |
feed_id = '106267' |
This file contains 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
require "prawn" | |
def form(pdf, fields) | |
pdf.float do | |
pdf.bounding_box([5, pdf.cursor], width: 250, height: 200) do | |
fields.keys.each do |label| | |
pdf.pad(5) { pdf.text label } | |
end | |
end | |
end |
This file contains 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
require "prawn" | |
Prawn::Document.generate("form.pdf") do | |
move_down 5 | |
text "Application form", style: :bold, size: 25 | |
bounding_box([0,cursor], width: bounds.width, height: 120) do | |
fill_color "DCDCDC" | |
fill_rectangle [0, cursor], bounds.right, bounds.top | |
fill_color "000000" |
This file contains 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 Address < ActiveRecord::Base | |
attr_accessible :postcode | |
validates :postcode, :postcode => true | |
end |
This file contains 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 Address < ActiveRecord::Base | |
attr_accessible :postcode | |
validates_format_of :postcode, :with => /^([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s?[0-9][ABD-HJLNP-UW-Z]{2}|(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\ )?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$$/i, :message => "invalid postcode" | |
end |