Skip to content

Instantly share code, notes, and snippets.

View forked_specs.rb
module ForkedSpecs
def forked_specs(*specs)
ActiveRecord::Base.clear_all_connections!
pids = []
specs.each do |spec|
pids << fork do
ActiveRecord::Base.establish_connection
spec.call
end
@nicoolas25
nicoolas25 / loadable_model.rb
Created Jun 28, 2015
Custom relation with caching and preloading (ActiveRecord)
View loadable_model.rb
require "active_support/concern"
require "loadable/relation"
module Loadable
module Model extend ActiveSupport::Concern
module ClassMethods
def loadable(name, options)
loadable_relations[name] = build_relation(name, options)
define_reader(name)
@nicoolas25
nicoolas25 / example.rb
Last active Aug 29, 2015
Monkey patch to save queries with keen.io
View example.rb
Keen.save_query('message_by_weekday', {
analysis_type: 'count',
event_collection: 'message_received',
group_by: 'time.wday',
})
@nicoolas25
nicoolas25 / equiset.rb
Last active Aug 29, 2015
A small class that allows to loop over a changing set of values
View equiset.rb
require 'set'
require 'thread'
# A thread safe pool of values that can change.
class EquiSet
def initialize
@sorted_set = SortedSet.new
@mutex = Monitor.new
end
View new_job_article.md

Nouvel emploi

Cet été je quittais une petite société de service de moins de 10 personnes pour rejoindre un éditeur qui compte une petite trentaine de personnes. Il y a deux semaines, je prenais mon poste et voici brièvement un petit bilan de ces premiers pas.

La structure

Avant tout, il faut savoir que mon ancien poste et mon nouveau poste ne sont

View write_article.md

Écrire

J'aime écrire. Qu'il s'agisse de sujet technique où non, je trouve que c'est un très bon moyen d'organiser sa réflexion autour d'une thématique donnée. Synbioz m'a offert l'oportunité de publier des articles sur son [blog][synbioz-blog] et je vais maintenant continuer l'aventure de mon coté.

Plutôt qu'un blog, je vais publier mes billets via des [Gists][mes-gists]. Mon objectif premier étant d'écrire, ce système me semble suffisant. Toutefois vos commentaires sont les bienvenus.

@nicoolas25
nicoolas25 / subprocess_monitor.rb
Last active Aug 29, 2015
Follow line by line the output of a subprocess.
View subprocess_monitor.rb
require 'timeout'
cmd = [
'sleep 3 ; echo "toto" ; sleep 3 ; echo "toto"',
'find /*',
'find /tmp'
]
begin
output, input = IO.pipe
@nicoolas25
nicoolas25 / subdir.rb
Created Jan 16, 2014
Using a subdirectory with mina.
View subdir.rb
# encoding: utf-8
#
# This extension allows you to select a subdirectory instead of a whole repository.
# It is useful when you're fetching a git project and your actual code is in a
# subdirectory.
#
namespace :subdir do
desc "Select a subdirectory as the root of your project"
@nicoolas25
nicoolas25 / action_view_ext.rb
Created Nov 22, 2013
Add the :required_mark option to the labels. (Rails 4)
View action_view_ext.rb
class ActionView::Helpers::FormBuilder
alias :original_label :label
# Add the :required_mark option to the label helper that add a mark before the content.
def label(method, content_or_options = nil, options = nil, &block)
if content_or_options && content_or_options.class == Hash
options = content_or_options
else
content = content_or_options
end
@nicoolas25
nicoolas25 / jquery_ujs_bindings.js
Created Oct 31, 2013
Use Rails's Javascript remote calls on div.
View jquery_ujs_bindings.js
(function($){
$(document).on('rails:attachBindings', function(){
$.rails.buttonClickSelector = $.rails.buttonClickSelector + ', div[data-remote]';
return true;
});
})(jQuery);