Skip to content

Instantly share code, notes, and snippets.

View blambeau's full-sized avatar

Bernard Lambeau blambeau

View GitHub Profile
@blambeau
blambeau / gist:1172939
Created August 26, 2011 07:58
Sloppy and tidy in Viiite
# A benchmark pioneered by @tenderlove
# @see https://gist.github.com/1170106
class Sloppy
def sloppy; @sloppy; end
end
class Tidy
def initialize; @tidy = nil; end
def tidy; @tidy; end
@blambeau
blambeau / hello.coffee
Created February 17, 2011 10:50
An example of syntax
class Hello extends Brick
constructor: ->
# Cell for the current view
@current = new Cell
# View handler for #content
@content = new View
selector:
@blambeau
blambeau / tutorial_d_in_ruby.rb
Created January 28, 2011 13:48
Relational algebra on apache logs, thanks to veritas
require 'veritas/physical/logs'
file = File.expand_path('../access.log', __FILE__)
LOGS = Veritas::Physical::Logs.new(file, [:apache, :combined])
# How many hits per page ??
(debug (summarize LOGS, :path, :count => (count '*')))
# What pages have not been found ??
NOT_FOUND = (restrict LOGS, ->(t){ t[:http_status].eq(404) })
@blambeau
blambeau / not_so_flexible_require
Created January 14, 2011 16:30
How [NOT] to require external dependencies
#
# This method allows requiring dependencies with some flexibility.
#
# Implemented algorithm makes greedy choices about the environment:
# 1. It first attempts a simple <code>Kernel.require(name)</code> before
# anything else (even bypassing version requirement)
# 2. If step 1 fails with a LoadError then it falls back requiring the
# gem with specified version (defaults to >= 0) and retries step 1.
# 3. If step 2 fails with a NameError, 'rubygems' are required and step
# 2 is retried.