Skip to content

Instantly share code, notes, and snippets.

View banister's full-sized avatar
🇳🇱

John Mair banister

🇳🇱
View GitHub Profile
class UserCreator
def initialize(listener)
@listener = listener
end
def create(attributes)
user = User.new(attributes)
if user.save
# send email
@whylom
whylom / README.md
Created December 4, 2014 23:43
A parser for Heroku log messages

A parser for Heroku log messages

This parser uses the Parslet to define rules for parsing a log message in the simple key=value format used by Heroku, eg:

at=error code=H12 desc="Request timeout" method=GET path="/foo" dyno=web.3 connect=1ms service=30000ms status=503 bytes=0

Given a message in the above format, the parser returns a hash of the key/value pairs:

#include <stdio.h>
//; def int(*args); end
//; def main(*args, &block);
//; Object.class_eval { define_method("foo", &block) }; foo; end
//; def argc; end
//; def char; 3; end
//; def argv; 3; end
int main(int argc, char ** argv) {
# http://gist.github.com/16885
# $ ./script/console
# Loading development environment (Rails 2.1.0)
# >>
# >> User.whatis :create!
# File: /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:876
# 872: end
# 873:
# 874: # Creates an object just like Base.create but calls save! instead of save
module YCombinator
def y_comb(&generator)
->(x){
->(*args){
generator.(x.(x)).(*args)
}
}.(->(x){
->(*args){
generator.(x.(x)).(*args)
}
typedef struct {
VALUE *pc; /* cfp[0] */
VALUE *sp; /* cfp[1] */
VALUE *bp; /* cfp[2] */
rb_iseq_t *iseq; /* cfp[3] */
VALUE flag; /* cfp[4] */
VALUE self; /* cfp[5] / block[0] */
VALUE klass; /* cfp[6] / block[1] */
VALUE *lfp; /* cfp[7] / block[2] */
VALUE *dfp; /* cfp[8] / block[3] */
@myobie
myobie / scope.rb
Created September 28, 2010 01:25
module Scope
module ScopeMethods
def helpers(&block)
instance_eval(&block)
end
end
def scope(path, &block)
(@path_parts ||= []) << path
module Recipe
def eggs(num=nil)
num ? @eggs = num : @eggs
end
def vinegar(num=nil)
num ? @vinegar = num : @vinegar
end
end
VALUE
rb_singleton_class_clone(VALUE obj)
{
VALUE klass = RBASIC(obj)->klass;
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
struct clone_method_data data;
/* copy singleton(unnamed) class */
@osdezwart
osdezwart / kode.rb
Created October 31, 2010 12:06
kode.rb Autoindenting of ruby code (Kode::Indenter)
=begin
/***************************************************************************
* Copyright (C) 2006, Paul Lutus *
* Copyright (C) 2008, Antono Vasiljev *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *