http://robots.thoughtbot.com/implementing-multi-table-full-text-search-with-postgres
https://github.com/textacular/textacular/blob/master/lib/textacular.rb
require 'csv' | |
def memstats | |
size = `ps -o size= #{$$}`.strip.to_i | |
end | |
memstats #4900 | |
CSV.open('visitors.csv', headers: true) do |csv| | |
visitors = csv.each # Enumerator | |
memstats # 5164 |
var tweet = "Currently chilling out at W1B 2EL, then on to WC2E 8HA or maybe even L1 8JF! :-)"; | |
// Here's a simple regex that tries to recognise postcode-like strings. | |
// See http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation | |
// for the rules on how UK postcodes are formatted. | |
var postcode_regex = /[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/g; | |
var postcodes = tweet.match(postcode_regex); | |
console.log(postcodes); |
require 'ostruct' | |
require 'open-uri' | |
require 'json' | |
class TemperatureApiError < StandardError | |
end | |
class CheeError < StandardError | |
end |
class Episode | |
def self.lazy_accessor(*names) | |
names.each do |name| | |
attr_writer name | |
define_method(name) do | |
load | |
instance_variable_get("@#{name}") | |
end | |
end | |
end |
MULTIPLE_OF_3 = ->(n){ (n % 3).zero? } | |
MULTIPLE_OF_5 = ->(n){ (n % 5).zero? } | |
MULTIPLE_OF_3_AND_5 = ->(n){ MULTIPLE_OF_3[n] && MULTIPLE_OF_5[n] } | |
(1..100).each do |num| | |
case num | |
when MULTIPLE_OF_3_AND_5 | |
puts "FizzBuzz" | |
when MULTIPLE_OF_3 | |
puts "Fizz" |
module Search | |
@children = [] | |
def self.included(base) | |
@children << base | |
end | |
def self.query(val) | |
@children.each do |child| | |
child.query(val) |
class GenericParser | |
def parse(parser) | |
puts "The parser class received the parse method" | |
parser.parse | |
end | |
end | |
class JSONParser | |
def parse | |
puts "An instance of the JSONParser receives the parse message" |
module Pagination | |
def paginate(page = 1, items_per_page = size, total_items = size) | |
@page = 1 | |
@items_per_page = items_per_page | |
@total_items = total_items | |
end | |
attr_reader :page, :items_per_page, :total_items | |
def total_pages |
class Fizzbuzz | |
def initialize(number) | |
@number = number | |
end | |
def self.count(number) | |
count = new(number) | |
count.output_data[count.selector.to_s] | |
end |