Skip to content

Instantly share code, notes, and snippets.

View wagenet's full-sized avatar

Peter Wagenet wagenet

View GitHub Profile
@wagenet
wagenet / gist:75440
Created March 7, 2009 21:02
Path Expander
# OBSOLETE: See http://in.finitu.de/2009/04/25/use_route-param-for-rails-url-helper
module PathExpander
def self.included(base)
base.send :include, InstanceMethods
base.helper_method :expand_url, :expand_path
end
module InstanceMethods
def expand_url(path, options = {})
@wagenet
wagenet / better_default_scope.rb
Created March 18, 2009 15:30
Improved Nested Scopes, Including Blocks for Rails 2.3
# Based on http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1812-default_scope-cant-take-procs
ActiveRecord::Base.class_eval do
class << self
private
def find_last(options)
order = options[:order]
// FieldNotes
// ==========
// Author: Peter Wagenet
// Description: Provides descriptions in text fields, removing them when the field is
// active and when the form is submitted.
//
// Sample Usage:
// <script type="text/javascript" charset="utf-8">
// document.observe("dom:loaded", function(){
// new FieldNotes('id_of_form', {
@wagenet
wagenet / .autotest
Created April 25, 2009 17:08
Show Growl notifications from both autotest and autospec
# Show Growl notifications from both autotest and autospec
# Author: Peter Wagenet (http://in.finitu.de)
# URL: http://gist.github.com/101692
module Autotest::Growl
def self.growl title, msg, img, pri=0, sticky=""
command = "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
# puts command
system command
end
require 'proxy_block'
module WithoutTimestamps
def self.included(base)
base.send :extend, ClassMethods
base.send :include, InstanceMethods
class << base; proxy_block :without_timestamps; end
base.send :proxy_block, :without_timestamps
end
# Tasks to use with test_benchmark when it is installed as a gem
# Does not require you to install as a plugin or frozen gem or otherwise modify your project
# Author: Peter Wagenet (http://in.finitu.de)
# URL: http://gist.github.com/112225
begin
require 'rubygems'
gem 'timocratic-test_benchmark'
def find_file(fn)
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Apple Inc. and contributors.
// License: Licened under MIT license (see license.js)
// ==========================================================================
/*globals module ok equals same test MyApp */
var store, storeKey, json, hash, hash2;
module("SC.Store#createRecord", {
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Text Editor</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Peter Wagenet">
<!-- Date: 2010-05-12 -->
@wagenet
wagenet / model.js
Created May 13, 2010 19:41
SproutCore Rails DataSource
MyApp.MyModel.mixin({
resourcePathFor: function(action, storeKey, item) {
var id, path;
id = storeKey ? MyApp.store.idFor(storeKey) : null;
switch(action) {
case 'fetch':
case 'create':
path = 'items';
require 'uuid'
module ActiveRecord
module UUID
def self.included(base)
base.send :extend, ClassMethods
base.send :include, InstanceMethods
class << base
alias_method :uuid_exists?, :exists?