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
public static TResult Aggregate<TSource, TAccumulate, TResult>( | |
this IEnumerable<TSource> source, | |
TAccumulate seed, | |
Func<TAccumulate, TSource, TAccumulate> func) |
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
def counter(start=0, increment=1) | |
count = nil | |
lambda do | |
count.nil? ? count = start : count += increment | |
end | |
end | |
result = counter(2,3) | |
puts result.call |
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 AppServer | |
attr_accessor :admin_password, :port | |
end | |
class Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password | |
def initialize | |
@app_server = AppServer.new | |
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 PostcodeValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless value =~ /^([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 | |
record.errors[attribute] << (options[:message] || "invalid postcode") | |
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
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 |
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
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
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
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
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(), |
OlderNewer