Skip to content

Instantly share code, notes, and snippets.

View elhu's full-sized avatar

Vincent Boisard elhu

View GitHub Profile
@elhu
elhu / README.txt
Created February 5, 2014 11:15
Net::ReadTimeout weirdness
Some weird stuff about NetHTTP, the timeout is twice what it should be.
To test things out:
$> gem install sinatra
$> ruby server.rb
$> ruby client.rb
@elhu
elhu / gist:1136890
Created August 10, 2011 14:19
jquery events
$(document).ready(function() {
console.log("document loaded.");
$(document).ajaxStart(function() {
console.log(".ajaxStart fired!");
});
$(document).ajaxComplete(function() {
console.log(".ajaxComplete fired!");
});
});
@elhu
elhu / gist:3208072
Created July 30, 2012 16:09
em-http-request HTTP Digest Auth middleware
module EventMachine
module Middleware
require 'digest'
require 'securerandom'
require 'cgi'
class DigestAuth
def initialize(opts = {})
@nonce_count = -1
@opts = {}
@elhu
elhu / gist:3973143
Created October 29, 2012 11:50
Method missing with module
def method_missing(method, *args, &block)
begin
super
rescue NoMethodError => e
warn("Warning: Unknown field or method #{method} for object #{self.inspect}\nBacktrace:\n#{e.backtrace.join("\n")}")
end
end
@elhu
elhu / gist:4065174
Created November 13, 2012 10:48
MongoDB question
class Band
include Mongoid::Document
store_in collection: "artists", database: "music", session: "secondary"
end
class BandsController < ApplicationController
before_filter :switch_database
after_filter :reset_database
private
# Setup step
stub(Version.just_updated).paginate(:page => nil, :per_page => 50){ [@version_2, @version_3, @version_4] }
stub(Version.just_updated).paginate(:page => 2, :per_page => 50){ [@version_4, @version_3, @version_2] }
stub(Version.just_updated).paginate do |args|
raise args.inspect
end
# Test
should "raise an exception" do
pp Version.just_updated.paginate(:page => 3, :per_page => 50) #=> []
@elhu
elhu / java1:elasticsearch.yml
Last active December 18, 2015 15:39
ElasticSearch unicast discovery problem
# from java1
cluster.name: dimelo
network.bind_host: 0.0.0.0
network.publish_host: 10.10.4.8
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["java1.dimelo:9200", "java2.dimelo:9200"]
@elhu
elhu / gist:5806022
Created June 18, 2013 14:52
Ferret with ruby 2.0.0p195
jenkins@ci [ideas_feature_remove-iconv] > gem install ferret
Building native extensions. This could take a while...
ERROR: Error installing ferret:
ERROR: Failed to build gem native extension.
/var/lib/jenkins/.rbenv/versions/2.0.0-p195/bin/ruby extconf.rb
creating Makefile
make
compiling STEMMER_stem_ISO_8859_1_dutch.c
@elhu
elhu / wrong argument type Proc (expected Proc)
Last active December 23, 2015 21:59
Errors occurring on Passenger 4 Enterprise 4.0.14
Backtrace:
On line #20 of app/views/layouts/application.html.erb
17: <%= execute_extensions_view_method :head %>
18: <%= custom_head_section %>
19: </head>
20: <% body_tag do %>
21: <%= admin_toolbar %>
22: <%= header %>
23: <% deprecated_doc4 yield(:document_class_for_sidebar) || 'yui-t7' do %>
@elhu
elhu / Gemfile
Last active January 4, 2016 00:19
ruby-band basic
source 'https://rubygems.org'
gem 'sinatra'
gem 'ruby-band'