Skip to content

Instantly share code, notes, and snippets.

@vladiim
vladiim / Factorizer module
Created May 19, 2012 00:28
# `factorize` allows Classes to create new class methods it does this by # calling public_method(:new) on the class rather than directly calling new # therebye ensuring single responsibility is followed
module Factorizer
# `factorize` allows Classes to create new class methods it does this by
# calling public_method(:new) on the class rather than directly calling new
# therebye ensuring single responsibility is followed
def factorize(klass, *attrs)
klass = Object.const_get(klass)
klass_source(klass).call(*attrs)
end
module Decorator
def initialize(component)
@component = component
end
def method_missing(meth, *args)
if @component.respond_to? meth
@component.send(meth, *args)
else
module Component
def decorate_with(*decorators)
decorators.inject(self) do |object, decorator|
decorator.new(object)
end
end
end
@vladiim
vladiim / Config log
Created June 12, 2012 07:48
Output from ~/Library/Logs/Homebrew/config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by R configure 2.15.0, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure --prefix=/usr/local/Cellar/r/2.15.0 --with-aqua --enable-R-framework --with-lapack
## --------- ##
## Platform. ##
~/Desktop% brew install -v R
==> Downloading http://cran.r-project.org/src/base/R-2/R-2.15.0.tar.gz
Already downloaded: /Library/Caches/Homebrew/r-2.15.0.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/r-2.15.0.tar.gz
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> ./configure --prefix=/usr/local/Cellar/r/2.15.0 --with-aqua --enable-R-framework --with-lapack
./configure --prefix=/usr/local/Cellar/r/2.15.0 --with-aqua --enable-R-framework --with-lapack
checking build system type... x86_64-apple-darwin11.4.0
% brew --config
HOMEBREW_VERSION: 0.9
HEAD: 79772aa31d4af4247c08c647f76004b9f94d8d59
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: dual-core 64-bit penryn
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
@vladiim
vladiim / gist:2947624
Created June 18, 2012 09:21
Capybara find order

:nth-child selector.

EG, a list of dates are in a <ul> with the id #dates:

page.should have_selector("ul#dates li:nth-child(1)", content: @date1.content) page.should have_selector("ul#dates li:nth-child(2)", content: @date2.content)

@vladiim
vladiim / R PostGres
Created July 6, 2012 06:22
R PostGres
# https://github.com/eBioGit/R-by-example/blob/master/database%20interface/RpostgreSQL.R
############# EXEMPEL PostgreSQL ##############
# Calling R in command mode
# R --no-save < RpostgreSQL.R
library("DBI")
library("RPostgreSQL")
############## SETS LOGIN INFORMATION ##############
@vladiim
vladiim / UK_MP_Spending.R
Created August 29, 2012 07:23
Scraping UK MP data
library(XML)
# URL of interest:
mps <- "http://news.bbc.co.uk/2/hi/uk_politics/8044207.stm"
# parse the document for R representation:
mps.doc <- htmlParse(mps)
# get all the tables in mps.doc as data frames
@vladiim
vladiim / autocompleteSeletor.js
Created September 2, 2012 22:27
Errata for MSTWJ Book 2
listElement: function(value) {
return $("<li>").attr("id", this.determineId("element_" + value))
.text(this.universe[value]);
},
linkElement: function(value) {
return $("<a href='#'>").addClass("delete-button")
.attr("id", this.determineId("delete_" + value))
.text(" Delete");
},