Skip to content

Instantly share code, notes, and snippets.

View nicoolas25's full-sized avatar

Nicolas Zermati nicoolas25

View GitHub Profile
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 June 28, 2015 12:53
Custom relation with caching and preloading (ActiveRecord)
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 August 29, 2015 14:07
Monkey patch to save queries with keen.io
Keen.save_query('message_by_weekday', {
analysis_type: 'count',
event_collection: 'message_received',
group_by: 'time.wday',
})
@nicoolas25
nicoolas25 / equiset.rb
Last active August 29, 2015 14:07
A small class that allows to loop over a changing set of values
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
@nicoolas25
nicoolas25 / new_job_article.md
Last active August 29, 2015 14:07
Nouvel emploi

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

@nicoolas25
nicoolas25 / write_article.md
Last active August 29, 2015 14:05
Écrire

É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 August 29, 2015 14:04
Follow line by line the output of a subprocess.
require 'timeout'
cmd = [
'sleep 3 ; echo "toto" ; sleep 3 ; echo "toto"',
'find /*',
'find /tmp'
]
begin
output, input = IO.pipe
@nicoolas25
nicoolas25 / subdir.rb
Created January 16, 2014 16:33
Using a subdirectory with mina.
# 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 November 22, 2013 10:51
Add the :required_mark option to the labels. (Rails 4)
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 October 31, 2013 12:12
Use Rails's Javascript remote calls on div.
(function($){
$(document).on('rails:attachBindings', function(){
$.rails.buttonClickSelector = $.rails.buttonClickSelector + ', div[data-remote]';
return true;
});
})(jQuery);