Skip to content

Instantly share code, notes, and snippets.

View olivierlacan's full-sized avatar

Olivier Lacan olivierlacan

View GitHub Profile
@mlangenberg
mlangenberg / ams_cache.rb
Last active August 29, 2015 13:58
One approach to cache ActiveModelSerializer representations with ActiveRecord objects
class User < ActiveRecord::Base; end;
class Post < ActiveRecord::Base; end;
class Comment < ActiveRecord::Base; end;
class AuthorSerializer < ActiveModel::Serializer
attributes :id, :name :created_at, :updated_at
end
class PostSerializer < ActiveModel::Serializer
attributes :id, :body :created_at, :updated_at
#!/usr/bin/env bash
main() {
if [ ! -p .test-commands ]; then
mkfifo .test-commands
fi
while true; do
cmd=$(cat .test-commands)
if [[ $cmd == "" ]]; then
diff --git i/hash.c w/hash.c
index 007508a..6f39e47 100644
--- i/hash.c
+++ w/hash.c
@@ -2402,6 +2402,28 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
return ary;
}
+static int
+hash_comprised_i(VALUE key, VALUE value, VALUE arg)
@olivierlacan
olivierlacan / Hash#contain?.patch
Last active August 29, 2015 14:00 — forked from nobu/Hash#comprized?.diff
Proposed implementation for Hash#contains? created by Nobu and slightly tweaked for semantics. Details here: http://olivierlacan.com/posts/proposal-for-a-better-ruby-hash-include/
diff --git i/hash.c w/hash.c
index 007508a..6f39e47 100644
--- i/hash.c
+++ w/hash.c
@@ -2402,6 +2402,28 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
return ary;
}
+static int
+hash_contain_i(VALUE key, VALUE value, VALUE arg)
require 'redcarpet'
desc "generate index.html from README.md"
file "index.html" => "README.md" do |task|
puts "Processing README.md to generate a new index.html..."
# `r` means we're using the "read" mode with the file
# we need a String for Redcarpet, it doesn't accept File objects.
string = File.open(task.prerequisites.first, 'r') { |file| file.read }
markdown = ::Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
@joshed-io
joshed-io / example_group.rb
Created July 14, 2011 01:16
Easiest possible RSpec Performance Test w/ Scenarios
# here's a quick recipe to run a performance test
# with this method, you can:
#-> easily choose the examples you want included from your existing specs
#-> define the target number of total iterations you'd like, no limit
#-> tune the transaction mix by specifying frequency metadata for each example
#-> be happy that the transaction mix is fairly homogeneous over the test interval
# (ideally you'd run this with acceptance (webrat/capybara) specs, but you
# could employ this technique for any rspec test)
@olivierlacan
olivierlacan / syntax_highlighting.py
Created August 31, 2011 14:47 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
# ======================================================================================= #
# NOTE: This is relatively outdated, you should use the DetectSyntax package
# from Package Control instead: http://wbond.net/sublime_packages/community#sort-installs
# ======================================================================================= #
# Instructions: put this inside of the following folder on a Mac:
# /Users/<yourusername>/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/
# ======================================================================================= #
import sublime, sublime_plugin
import os
require "rack/contrib/try_static"
use Rack::TryStatic, :root => "build", :urls => %w[/], :try => ['index.html', '/index.html']
require "rack/contrib/static_cache"
use Rack::StaticCache, :urls => ['/'], :root => 'build'
@ErneX
ErneX / gist:3179774
Created July 26, 2012 01:42
OS X Mountain Lion clean install & Rails
OS X Mountain Lion clean install Rails development environment setup using MySQL, imagemagick, homebrew and rvm. Rough steps, your mileage or your needs may vary:
- Install XCode from the App Store.
- Launch XCode > Preferences > Downloads > Install the Command Line Tools
- Install XQuartz version 2.7.2 http://xquartz.macosforge.org/trac/wiki/X112.7.2
- Install git, I used git-osx-installer version 1.7.11.3 http://code.google.com/p/git-osx-installer/downloads/list
- Install Ruby 1.9.3 with rvm, run this command on a terminal and follow the instructions: curl -L https://get.rvm.io | bash -s stable --ruby
- Install MySQL using the DMG installer, I used version 5.1.63 found here http://dev.mysql.com/downloads/mysql/5.1.html I use this to get the files needed for the mysql2 gem to install, I don't install the prefpane or the init script since I use MAMP as my MySQL server on my Mac.
- Install homebrew: https://github.com/mxcl/homebrew/wiki/installation
- Install ghostscript, from a terminal: brew install ghosts
@kneath
kneath / controllers.rb
Created October 18, 2012 21:26
Given a controller in need of refactoring into multiple controllers, how can I redirect to new controller actions based upon a feature flag?
# Given a controller in need of refactoring into multiple controllers, how
# can I redirect to new controller actions based upon a feature flag?
#
# The current code "works" but doesn't exercise the controller action.
#
# Rails 2.3 or 3.0 methods accepted
class BetterController
def overview
# .. a small amount of auth/permissions code