Skip to content

Instantly share code, notes, and snippets.

View nicoolas25's full-sized avatar

Nicolas Zermati nicoolas25

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / range_mixer.rb
Created July 4, 2012 12:00
Some class that may be useful for dealing with time ranges.
# This class assumes that you have ranges associated to a value
# and that you want to merge those values. This is, for instance,
# useful to count overlaps of date ranges.
#
# Example of uses:
#
# rm = RangeMixer.new(0..10, 0)
# rm.add(0..5){ |memo| memo + 1 }
# rm.add(0..5){ |memo| memo + 4 }
#
@nicoolas25
nicoolas25 / user.rb
Created November 13, 2012 13:40
Allow only one connection before confirmation with Devise.
module OneConnectionBeforeConfirm
extend ActiveSupport::Concern
included do
before_create :generate_confirmation_token
after_create :send_on_create_confirmation_instructions
end
# This actions are not properly trigerred because of the rest of our modifications.
before_create :generate_confirmation_token
@nicoolas25
nicoolas25 / fineuploader-3.0.patch
Created December 4, 2012 09:26
Patch to make dragonfly happy with fineuploader 3.0. (for 3.1 see the paramsInRequestBody option)
--- fineuploader-3.0.js 2012-11-16 21:30:02.000000000 +0100
+++ fineuploader-3.0.patched.js 2012-12-04 10:21:56.799781578 +0100
@@ -1796,7 +1796,15 @@
var protocol = this._options.demoMode ? "GET" : "POST"
var form = qq.toElement('<form method="' + protocol + '" enctype="multipart/form-data"></form>');
- var queryString = qq.obj2url(params, this._options.endpoint);
+ // Params arn't given through form's action anymore but appened into it.
+ var queryString = qq.obj2url({}, this._options.endpoint);
+ for (paramName in params) {
@nicoolas25
nicoolas25 / benchmark.rb
Last active December 21, 2015 07:28
Compare an access speed between an instance variable and an accessor.
require 'benchmark'
n = 5000000
class A
def initialize(attribute)
@attribute = attribute
end