Skip to content

Instantly share code, notes, and snippets.

Avatar

Vincent Durand madwork

View GitHub Profile
@madwork
madwork / thin.god
Created Apr 12, 2012
Config file for god that configures watches for each instance of a thin server
View thin.god
# == God config file
# http://god.rubyforge.org/
# Authors: Gump and michael@glauche.de
#
# Config file for god that configures watches for each instance of a thin server for
# each thin configuration file found in /etc/thin.
# In order to get it working on Ubuntu, I had to make a change to god as noted at
# the following blog:
# http://blog.alexgirard.com/ruby-one-line-to-save-god/
#
View Rakefile
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << 'lib'
t.libs << 'spec'
t.pattern = 'spec/**/*_spec.rb'
t.verbose = true
t.warning = false
end
View gist:3974516
module Urlize
def urlize
self.gsub(/[^[:alnum:]\-\s\_]/, '').split(/[\s\-\_]+/).delete_if{|i| i.empty?}.join('-').downcase
end
end
View manager.rb
class Manager
def self.configure(&block)
::Template.new(&block)
end
end
class Template
attr_reader :assets, :events
def initialize(&block)
@madwork
madwork / .pryrc
Last active Dec 11, 2015
Mac OS X 10.8 : RVM + Homebrew + Ruby 1.9.3 + .pryrc
View .pryrc
require 'benchmark'
# textmate as editor
Pry.config.editor = 'mate -w'
Pry.config.color = true
Pry.config.pager = true
# alias 'q' for 'exit'
Pry.config.commands.alias_command 'q', 'exit-all'
@madwork
madwork / contact.rb
Last active Dec 12, 2015
nested attributes with dynamic form
View contact.rb
class Contact < ActiveRecord::Base
has_many :responses
has_many :dynaforms, through: :responses
attr_accessible :email, :responses_attributes
accepts_nested_attributes_for :responses
def self.new_with_dynaforms
new.tap do |contact|
@madwork
madwork / exporter.rb
Last active Dec 14, 2015
Simple CSV Exporter
View exporter.rb
require 'iconv'
class Exporter
def initialize(separator = ';')
@separator = separator
@header = []
@body = []
end
@madwork
madwork / README.md
Last active Dec 14, 2015
Various method to add dynamic accessors (getters/setters)
View README.md

Various method to add dynamic accessors (getters/setters)

Make it yourself way

foo = Foo1.new
foo.build1 :a, :b
foo.a = 1
foo.a

foo = Foo1.new
@madwork
madwork / bench.rb
Created Mar 12, 2013
String prepend FTW
View bench.rb
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("String::prepend") { "foo".prepend "tmp/" }
x.report("File.join") { File.join "tmp", "foo" }
end
puts
Benchmark.bm do |x|
x.report("String::prepend") { 1000000.times{"foo".prepend "tmp/"} }
@madwork
madwork / install.sh
Last active Dec 14, 2015
Max OS X 10.8 + chruby + Ruby 2.0
View install.sh
brew install chruby readline openssl libyaml
brew link openssl --force
export ARCHFLAGS="-arch x86_64"
export CFLAGS="-g -O2"
export LDFLAGS="-L/usr/local/lib -L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/opt/readline/include"
mkdir ~/.rubies
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz