Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
# 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'
@dkubb
dkubb / my.cnf
Created January 24, 2011 21:33
Sample MySQL configuration with strict defaults
[client]
socket = /opt/local/var/run/mysql5/mysqld.sock
default-character-set = utf8
# XXX: how can the connection collation be set to utf8_unicode_ci?
[mysqld]
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
@michael
michael / bare-couch.js
Created January 27, 2011 13:44
A super-lightweight wrapper that treats CouchDB like a key/value store.
var BareCouch = require('bare-couch');
var db = BareCouch("http://username:password@yourhost:5984/users");
// Get A document (@rev is optional)
db.get('frank@37-c0b8d2436', function(err, doc) {
// The doc, unless there wasn't an error
});
// Set A document
db.set({"_id": "frank", "name": "Frank", "email": "[email protected]", _rev: "37-c0b8d2436"}, function(err, doc) {
// requires jQuery
function humanDuration(milliseconds) {
var remainder = milliseconds;
var times = [
(remainder /= 1000) % 60, // seconds
(remainder /= 60) % 60, // minutes
(remainder /= 60) % 24, // hours
(remainder /= 24), // days
@botanicus
botanicus / .gitignore
Created February 14, 2011 14:41
Puller: it updates repository on the server after push to GitHub. Useful for example for CI via CIJoe. Just add your_server/puller to Post Receive URLS (in GH administration for the repo).
.rvmrc
.bundle
Gemfile.lock
*.log
@lenary
lenary / gitconfig.ini
Created February 18, 2011 01:21
a special excerpt of my gitconfig
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
@knowtheory
knowtheory / Dead simple legacy data access with DataMapper.mdown
Created February 18, 2011 03:57
See how DataMapper is perfect for extracting data from legacy stores without backflips, kungfu, or dangerous acrobatics. You can even use your data extraction models directly in web apps without any fuss.

Abstract

Ruby and Rails are well known for greenfield development, and sits amongst the top choices for startups. However, the expanded world of open data sources, and enterprise Ruby, there's a lot more to life than dreaming up new web apps. But when (not if) you deal with pre-existing data, why spend all your time writing brittle one off shims to translate your data from your legacy store? Why not rely on a robust and well designed Ruby library like DataMapper? DataMapper will let you write readable and natural Ruby code to access data of all types. Your legacy models will be a delight to work with. Use them directly in your web app if you like!

Technically speaking, DataMapper allows for different modeling tasks than ActiveRecord or Sequel. DataMapper is highly customizeable, allowing users to override and redefine naming conventions, key and field mappings at whatever granularity users may desire (from individual fields all the way up to global table mapping). This ability coupled with DataM

@postmodern
postmodern / gix_require_benchmark.rb
Created March 10, 2011 05:04
Benchmark each require in your Ruby code.
require 'rubygems'
require 'rbtree'
class Req
attr_accessor :path, :time, :requires, :exception
def initialize(path)
@path = path
@requires = []
@time = 0
end
@dkubb
dkubb / ev.rb
Created March 16, 2011 22:13
Poor-man's Embedded Value
class User
include DataMapper::Resource
property :id, Serial
property :username, String, :required => true, :unique => true
property :address_street_address, String
property :address_location, String
property :address_subdivision, String
property :address_country, String
@solnic
solnic / TODO.markdown
Created March 25, 2011 13:02
This gist shows the status of EmbeddedValue development in dm-core and my notes
  • Integration Model shared specs for Resource/EV:

    • DataMapper::Model::Core
    • DataMapper::Model::Property
    • DataMapper::Model::Hook
    • DataMapper::Model::Relationship
  • Integration Resource shared specs for Resource/EV:

  • DataMapper::Resource::Attributes