Skip to content

Instantly share code, notes, and snippets.

class Module
alias_method :include_without_hooks, :include
def include(*modules)
include_before_hook(*modules)
include_without_hooks(*modules)
include_after_hook(*modules)
end
def include_before_hook(*modules)
/* Example DataDapper Model */
class User {
struct Properties {
DD_Property!(int,"id") id;
DD_Property!(string,"username") username;
DD_Property!(double,"score") score;
}
Properties properties;
import std.stdio;
class KdTree {
private int _dimensions;
int dimensions() {
return _dimensions;
}
KdNode *rootNode;
# anybody already using an Object monkey-patch like the one below:
class Object
def send_chain(v)
this = self
v.each { |k| this = this.send(*k) }
this
end
end
> ruby -rmath_functions.rb -e "puts MathFunctions.factorial(2)"
2
> ruby --test -rmath_functions.rb
.
Finished in 1.000706 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
module MappedProperty
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def mapped_property(name, geocoder = "Location")
class_eval <<-END, __FILE__, __LINE__
property :#{name}, String
property :#{name}_lng, Float
Lacking a social network that leaves us:
1. owners of our own content,
2. managers of own privacy, and
3. just as capable of discovering the serendipities within our social graph.
We set forth to build an online network that:
1. decentralizes the control of content by placing it firmly with its
individual users,
class ApplicationController < ActionController::Base
before_filter :compound_date_values
protected
def compound_date_values(h=params,prefix=[])
to_fix = {}
h.each do |k, v|
if v.is_a? Hash
@foysavas
foysavas / helpers.rb
Created January 31, 2011 18:12
Carrierwave, DataMapper, & Sinatra starring in "Imagine the Possibilities"
def is_ajax_request?
if respond_to? :content_type
if request.xhr?
true
else
false
end
else
false
end
@foysavas
foysavas / haml_converter.rb
Created February 29, 2012 17:45 — forked from radamant/haml_converter.rb
Haml, Sass, and Scss conversion for jekyll
module Jekyll
require 'haml'
class HamlConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /haml/i
end