Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
@mbj
mbj / design.md
Created November 22, 2012 22:28
dm-session mapper interface

Mapper interfaces as used by dm-session

Mapper#loader(body)   => [Loader]      # Loader for specific body
Mapper#dumper(object) => [Dumper]      # Dumper for object
Mapper#execute(command)                # command is an instance of DataMapper::Session::Command::{Insert,Update,Delete}

Loader#identity       => [Identity]    # Any mapper specific object that implements#hash
Loader#object         => [Object]      # The loaded domain object
@mbj
mbj / foo.rb
Created November 6, 2012 23:33
dm-2 heckle spec style helper
class Foo
def bar
:baz
end
end
@xaviershay
xaviershay / controller_source.rb
Created October 9, 2012 04:56
What if we used dependency injection for Rails controller code?
class ControllerSource
Response = Struct.new(:controller, :injector) do
def redirect_to(path, *args)
controller.redirect_to(controller.send("#{path}_path", *args))
end
def render(*args)
ivars = {}
if args.last.is_a?(Hash) && args.last.has_key?(:ivars)
ivars = args.last.delete(:ivars)
@dkubb
dkubb / git-remove-merged.sh
Last active March 8, 2023 17:24 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
git remote update &&
git remote prune origin &&
git branch -r --merged origin/master |
awk -F"/" '!/(>|master)/ {print $2}' |
xargs -rL1 git push origin --delete
@dkubb
dkubb / eager_repository.rb
Last active May 13, 2019 21:10
Eager Loading DataMapper Associations
require 'memoist'
# Usage:
#
# customers = Customer.preload(Customer.orders.line_items.item)
#
# customers.each do |customer|
# customer.orders.each do |order|
# order.line_items.each do |line_item|
# line_item.item # yay, no more N+1, only 4 queries executed !
@mbj
mbj / mapper.rb
Created May 22, 2012 18:41
Experimental mapper, with much to verbose setup.
# This is a mapper I created when I was in hurry/spiking using:
# github.com/mbj/mapper (a stupid try-to-be-most-generic mapper implementation, to be rewritten)
# github.com/mbj/session (a database session/IdentityMap that can possibly work with any (document) mapper)
# the Session thing is more or less stable, and I like it!
# This code is not used anymore, it was replaced by a non generic application specific mapper to elasticsearch.
# Also this code never went to production.
# The whole point of this literal mess was to transform a tree of objects into a document that could be stored within mongo.
# The virtus object tree should be reconstructed 1:1.

Recently, we've been working on extracting Ember conventions from applications we're working on into the framework. Our goal is to make it clearer how the parts of an Ember application work together, and how to organize and bootstrap your objects.

Routing

Routing is an important part of web applications. It allows your users to share the URL they see in their browser, and have the same things appear when their friends click on the link.

The Ember.js ecosystem has several great solutions for routing. But, since it is such an important part of most web applications, we've decided to build it right into the framework.

If you have already modeled your application state using Ember.StateManager, there are a few changes you'll need to make to enable routing. Once you've made those changes, you'll notice the browser's address bar spring to life as you start using your app—just by moving between states, Ember.js will update the URL automatically.

@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
@hassox
hassox / base_app.rb
Created February 21, 2012 10:37
Mounted sinatra apps with http_router_sinatra
require 'sinatra/base'
require 'http_router_sinatra'
# With this simplistic approach, Sinatra apps must be leaf nodes in the rack graph
# Mounter nodes may be nested arbitrarily deeply however.
# Include Warden to authenticate whole sub-branches of the graph
class Mounter < HttpRouter
def mount(path, app)
route = add(path).partial.to(app)
mounter = app.respond_to?(:url_mount) ? app : nil
@wycats
wycats / ruby-mixins.rb
Created November 10, 2011 09:23
Shows how Ruby mixins work together with `super`
##
## with raw object
##
# create a new object
o = Object.new
# define methods on the object (precisely, the object's singleton)
class << o
def hello(thing)