Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
@dkubb
dkubb / my.cnf
Created April 5, 2011 23:00
My strict .my.cnf
[client]
socket = /tmp/mysql.sock
default-character-set = utf8
# XXX: how can the connection collation be set to utf8_unicode_ci
[mysqld]
port = 3306
socket = /tmp/mysql.sock
@knowtheory
knowtheory / prettyprint.js
Created April 11, 2011 05:44
A pretty printer for Javascript objects that looks like Ruby's pp formatter. In use on Rhino, untested elsewhere.
function pp(object, depth, embedded) {
typeof(depth) == "number" || (depth = 0)
typeof(embedded) == "boolean" || (embedded = false)
var newline = false
var spacer = function(depth) { var spaces = ""; for (var i=0;i<depth;i++) { spaces += " "}; return spaces }
var pretty = ""
if ( typeof(object) == "undefined" ) { pretty += "undefined" }
else if ( typeof(object) == "boolean" ||
typeof(object) == "number" ) { pretty += object.toString() }
else if ( typeof(object) == "string" ) { pretty += "\"" + object + "\"" }
@postmodern
postmodern / dm_find_validation_errors.rb
Created April 15, 2011 08:43
Quick and Dirty way to find DataMapper Validation errors.
require 'pp'
invalids = ObjectSpace.each_object(DataMapper::Resource).select { |obj| !obj.saved? && !obj.valid? }
pp invalids.map { |obj| [obj.class, obj.errors.to_hash] }
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
@dbi
dbi / edit.html.mustache
Created May 4, 2011 09:31
Rails form helper for mustache spike/proof of concept
<!-- A scaffolded edit view converted to mustache -->
<h1>Editing post</h1>
{{#form}}
{{#errors?}}
<div id="error_explanation">
<h2>{{error_header}}</h2>
</div>
<ul>
@ryanb
ryanb / rails_3_1_rc4_changes.md
Created May 6, 2011 01:10
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 RC4

  • The new rake task assets:clean removes precompiled assets. [fxn]

  • Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]

  • Fixed database tasks for jdbc* adapters #jruby [Rashmi Yadav]

  • Template generation for jdbcpostgresql #jruby [Vishnu Atrai]

@solnic
solnic / rounded_corners_table.sass
Created May 6, 2011 10:40
Here's how to do a table with rounded corners in CSS3
@import compass/reset
@import compass/css3/border-radius
table
border: none
border-collapse: separate
th, td
padding: 5px
thead
background-color: #f2f6fa
@d11wtq
d11wtq / connection_pool_adapter.rb
Created May 6, 2011 13:45
Sample database.yml for multiple slaves/masters with DataMapper
module DataMapper
module Adapters
class ConnectionPoolAdapter < AbstractAdapter
def initialize(name, options)
super
assert_kind_of 'options', @options[:pool], Array
raise ArgumentError, "The are no adapters in the adapter pool" if @options[:pool].empty?
@amiel
amiel / sweeper.rb
Created May 6, 2011 21:49
DataMapper::Sweeper
module DataMapper
# DataMapper::Sweeper provides an observer to model changes that have access
# to the controller invoking the changes.
#
# The api for DataMapper::Sweeper is similar to DataMapper::Observer, but
# there is one important difference: in DataMapper::Observer .before and
# .after blocks are evaluated in the context of the resource instance.
# However, DataMapper::Sweeper .before and .after blocks are evaluated in the
# context of an instance of your Sweeper class, and missing methods are
require 'sinatra/base'
class MyApp < Sinatra::Base
@@my_app = {}
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
class FooController < MyApp
map '/foo'