Skip to content

Instantly share code, notes, and snippets.

@athoune
athoune / gist:649973
Created Oct 27, 2010
javascript can be as nice as Erlang for handling cascade callback
View gist:649973
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
mapreduce with PHP
View gist:954308
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 Aug 30, 2011
future the nth time
View gist:1182313
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 Sep 15, 2011
Orthodox Event Machine API + Fiber variants
View gist:1220462
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 Sep 21, 2011
Install Storm with macbrew
View gist:1232493

Install

Homebrew packages

brew install zeromq leiningen zookeeper

Jzmq

@athoune
athoune / gist:1499150
Created Dec 19, 2011
Playing with tire analyzer for french language
View gist:1499150
#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 Jan 12, 2012
autocomplete with tire
View gist:1599957
#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 Jan 12, 2012
crash ES with the ! character
View gist:1600559
#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 Jan 17, 2012
trouble with multi_field with tire
View gist:1629799
#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 Feb 17, 2012
Installing python kyotocabinet on OSX
View gist:1852426