This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift(File.expand_path('f')) | |
x = 0 | |
y = 0 | |
require 'benchmark' | |
Benchmark.bm do |b| | |
step = 500 | |
(0..4).each do |n| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
# Provide access to helper methods from outside controllers and views, | |
# such as in Presenter objects. Rails provides ActionController::Base.helpers, | |
# but this does not include any of our application helpers. | |
def self.all_helpers | |
@all_helpers_proxy ||= begin | |
# Start with just the rails helpers. This is the same method used | |
# by ActionController::Base.helpers | |
proxy = ActionView::Base.new.extend(_helpers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Yields the given models wrapped in Loader::Table objects that can be | |
# used to write SQL. The block should return an array with the SQL as | |
# the first element, and variable substitutions as the rest. | |
# | |
# Example | |
# using_sql(Article) {|a| | |
# ["SELECT #{a.*} FROM #{a} WHERE #{a.id} = ?", 1] | |
# } | |
def using_sql(*models) | |
opts = models.extract_options! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2fb8432982b7e8ffc4c05f912f47cd9ca7261427 Mon Sep 17 00:00:00 2001 | |
From: Xavier Shay <[email protected]> | |
Date: Sun, 1 May 2011 10:25:18 +1000 | |
Subject: [PATCH] Disable some edge cases in requiring to speed it up. | |
--- | |
load.c | 1 + | |
1 files changed, 1 insertions(+), 0 deletions(-) | |
diff --git a/load.c b/load.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell #-} | |
import Yesod | |
import Text.Hamlet | |
import Database.Persist | |
import Database.Persist.MongoDB | |
import Database.MongoDB | |
import Data.ByteString.Lazy.UTF8 | |
import Control.Monad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mix this module into a DataMapper::Resource to get fast, indexed full | |
# text searching. | |
# | |
# class Post | |
# include DataMapper::Resource | |
# include Searchable | |
# | |
# property :title, String | |
# property :body, Text | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trying to isolate some performance problems with collection rendering in a rails app. | |
# | |
# FAIL | |
# | |
# Need to move to a bare rails app next. | |
# | |
# Run this RUBY_PROF or BENCHMARK = 1 in your env. | |
require 'rubygems' | |
require 'dm-core' | |
require 'dm-migrations' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Because I can't figure out how the fuck to get SQL out of datamapper itself | |
class PGEngine < Arel::Visitors::PostgreSQL | |
attr_accessor :engine | |
def initialize(engine) | |
super | |
self.engine = engine | |
end | |
def connection_pool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
require 'dm-migrations' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test | |
class Group | |
include DataMapper::Resource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code to interpret javascript style hashes, without having to source them from | |
# a different file (as happens when you use the operator table. The key | |
# does not have to be surrounded in quotes. | |
# | |
# {key: "my value} | |
# Resolver is a proxy object needed to figure out the key of a pair. | |
Resolver := Object clone | |
Resolver resolve := method( | |
# Jiggery-pokery to extract name and value from the message without eval-ing it |