Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View athoune's full-sized avatar

Mathieu Lecarme athoune

View GitHub Profile
@athoune
athoune / gist:649973
Created October 27, 2010 20:57
javascript can be as nice as Erlang for handling cascade callback
MultiPart.prototype.copy = function(writer, callback) {
var mp = this;
var parts = this.parts;
if(this.part != '') { parts.push(this.part); }
parts.push(CRLF + "--" + this.boundary + "--");
parts.reverse();
var BLOCKSIZE = 32*1024;
var readFile = function(fd, total, writer) {
var buffer = new Buffer(BLOCKSIZE);
fs.read(fd, buffer, 0, BLOCKSIZE, null, function(err, bytesRead) {
@athoune
athoune / gist:954308
Created May 3, 2011 21:33
mapreduce with PHP
require 'lib/worker.php';
function getTitle($url) {
$html = file_get_contents("http://$url");
if($html == FALSE) {
throw new Exception("can't fetch url");
}
preg_match('/<title>(.*)<\/title>/i', $html, $matches);
return html_entity_decode($matches[1]);
}
@athoune
athoune / gist:1182313
Created August 30, 2011 22:47
future the nth time
require 'eventmachine'
class NFuture
include EM::Deferrable
def initialize(times, &block)
@times = times
self.callback(&block)
end
def one_more_time(*arg)
@athoune
athoune / gist:1220462
Created September 15, 2011 20:57
Orthodox Event Machine API + Fiber variants
require "em-http-request"
require "em-synchrony"
class Weather
include EventMachine::Deferrable
attr_reader :code, :date, :temp, :humidity, :wind_speed
def _feed code, raw
rough = raw.split('#')
@code = code
@athoune
athoune / gist:1232493
Created September 21, 2011 16:10
Install Storm with macbrew

Install

Homebrew packages

brew install zeromq leiningen zookeeper

Jzmq

@athoune
athoune / gist:1499150
Created December 19, 2011 22:13
Playing with tire analyzer for french language
#encoding: utf-8
require 'rubygems'
require 'tire'
#
# Playing with analyzers and its parameters.
# Witch fits best for the french language?
#
# $ rvm use 1.9.2
# $ gem install tire
@athoune
athoune / gist:1599957
Created January 12, 2012 11:23
autocomplete with tire
#encoding: utf-8
require 'rubygems'
require 'tire'
require 'json'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/object/to_param'
conf = {
settings: {
number_of_shards: 1,
@athoune
athoune / gist:1600559
Created January 12, 2012 13:35
crash ES with the ! character
#encoding: utf-8
require 'rubygems'
require 'tire'
require 'json'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/object/to_param'
Tire.configure { logger 'elasticsearch.log', :level => 'debug' }
Tire.index 'ponctu' do
@athoune
athoune / gist:1629799
Created January 17, 2012 23:40
trouble with multi_field with tire
#encoding: utf-8
require 'rubygems'
require 'tire'
#require 'json'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/object/to_param'
Tire.configure { logger 'elasticsearch.log', :level => 'debug' }
tire = Tire.index 'path' do
delete
@athoune
athoune / gist:1852426
Created February 17, 2012 10:09
Installing python kyotocabinet on OSX