Skip to content

Instantly share code, notes, and snippets.

View brynary's full-sized avatar

Bryan Helmkamp brynary

View GitHub Profile

2010 Modularity Olympics

This is a contest, open to programming languages from all nations, to write modular and extensible code to solve the following problem: Implement a service that can run queries on a database.

The Challenge

Sounds simple right? Wrong! A programmer without control over the source-code of that service must be able to later add enhancements such as statistics collecting, timeouts, memoization, and so forth. There are a few more requirements:

  1. the “enhancements” must be specified in a configuration object which is consumed at run-time (e.g., it could be based on user-input).
  2. The enhancements are ordered (stats collecting wraps timeouts, not the other way around) but it must be possible to reverse the order of the enhancements at run-time.
  3. The enhancements must be “surgical” and not “global”. That is, it must be possible to simultaneously have two query services, one reversed and one not reversed, and even have a query service without any enhancements.
FROM ubuntu
MAINTAINER Code Climate <ops@codeclimate.com>
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y curl libssl-dev libssl0.9.8 autoconf build-essential
RUN mkdir -p /app/vendor/ruby-1.9.3 && cd /app/vendor/ruby-1.9.3 && curl "https://s3.amazonaws.com/heroku-buildpack-ruby/ruby-1.9.3.tgz" -s -o - | tar zxf -
class FooController < ApplicationController
before_filter :api_authenticate
# ...
def api_authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
end
end
class ActiveUserPolicy
LOGIN_PERIOD = 14.days
class Query
def initialize(relation = User.scoped)
@relation = relation
end
def find_each(&block)
@relation.
$ git ls-remote git://github.com/floere/picky.git
fatal: remote error: access denied or repository not exported: /d/nw/d8/cc/43/828623/828623.git
@brynary
brynary / code_locator.rb
Created July 19, 2012 17:39
This code was used by Code Climate to figure out where classes, modules and methods live
def in_module(name, file, line, last_line)
if Sexp === name then
name = case name.first
when :colon2 then
name = name.flatten
name.delete :const
name.delete :colon2
name.join("::")
when :colon3 then
name.last.to_s
def assert_select(*args, &block)
# Start with optional element followed by mandatory selector.
arg = args.shift
@selected ||= nil
if arg.is_a?(HTML::Node)
# First argument is a node (tag or text, but also HTML root),
# so we know what we're selecting from.
root = arg
arg = args.shift
@brynary
brynary / readme.md
Created September 27, 2011 15:53 — forked from ngauthier/readme.md
%h4 Utility Account Summary
%table.data-table
= @user_metrics.utility_accounts_summary.each_count do |name, count|
%tr
%th= name
%td= count
4: CC vm/llvm/jit.cpp
virtual memory exhausted: Cannot allocate memory
virtual memory exhausted: Cannot allocate memory
virtual memory exhausted: Cannot allocate memory
rake aborted!
Error compiling
(See full trace by running task with --trace)
Error: gcc -Ivm -Ivm/test/cxxtest -I. -pipe -Wall -fno-omit-frame-pointer -ggdb3 -Werror -DRBX_PROFILER -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O2 -DHAS_EXECINFO -DHAS_READLINE -DNDEBUG -D_GNU_SOURCE -fomit-frame-pointer -fPIC -Ivm/external_libs/llvm/include -DENABLE_LLVM -Ivm/external_libs/udis86 -Ivm/external_libs/libffi/include -Ivm/external_libs/libgdtoa -Ivm/external_libs/onig -Ivm/external_libs/libtommath -I/usr/local/include -I/opt/local/include -c -o vm/llvm/artifacts/jit.cpp.o vm/llvm/jit.cpp