Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
dakatsuka / default.rb
Created December 13, 2011 06:19
change tcp keepalive (for EC2) / Chef recipe
template "/etc/network/if-up.d/tcp_keepalive_time" do
source "/etc/network/if-up.d/tcp_keepalive_time.erb"
owner "root"
group "root"
mode "0744"
end
script "change tcp keepalive" do
interpreter "bash"
user "root"
@reidmorrison
reidmorrison / collection.rb
Last active September 28, 2015 21:19
Mongo Reconnect logic for Connection Failures. Deprecated, moved to: https://github.com/reidmorrison/mongo_ha
#
# NOTE: This gist is now deprecated and has been moved into a gem: https://github.com/reidmorrison/mongo_ha
#
require 'mongo/collection'
module Mongo
class Collection
alias_method :find_one_original, :find_one
def find_one(*args)
@fdv
fdv / gist:1591412
Created January 10, 2012 21:49
Setup ElasticSearch with 3 networks and an IPVS configuration
We had to deploy ElasticSearch in a particular environment, where our hosts would be connected to Internet and access 2 different subnets, but with some restrictions. This makes our setup somehow tricky as we need the following:
eth0: external IP, listening on the Internet. There are iptables rules blocking every connection there on ports 9200 and 9300.
eth1: RFC1918 IP address.
lo:0: a single RFC1918 address used on every node for IPVS / IPFail for load balancing and fail over purpose.
Why is this setup tricky?
1. By default, ElasticSearch will listen on eth0 if it exists and is up. Shutting down eth0 and setting it up will just break your setup. Add iptables rules and you'll really be in trouble. Using unicast and a list of IPs won't be enough to solve the issue.
@nono
nono / gist:1600053
Created January 12, 2012 11:48 — forked from athoune/gist:1599957
autocomplete with tire
#encoding: utf-8
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,
number_of_replicas: 0,
// Underscore mixing for partial functions and async calls.
// Based on this microsoft post: http://msdn.microsoft.com/en-us/scriptjunkie/gg575560
_.mixin({
// Turn a normal function into an asynchronous version.
// It will return a function that expect's the last argument
// to be a callback expecting (err, result) as arguments.
wrapAsync: function(fn) {
return function() {
var args = _(arguments).toArray();
@kyledrake
kyledrake / gist:2120107
Created March 19, 2012 17:24
Rainbows! config file for use with EventMachine
# This is a configuration script for using Rainbows with EventMachine. I'm providing it incase somebody finds it useful. But honestly, you
# should stop using EventMachine and use threads instead. The ThreadPool version of this is also in my gist list, and I recommend taking a look at that instead.
# NO, SERIOUSLY, STOP USING EVENTMACHINE.
Rainbows! do
name = 'yourappname'
use :EventMachine
client_max_body_size nil # This is set in nginx
# keepalive_timeout 1
@cpsubrian
cpsubrian / README.md
Created May 2, 2012 19:47
Tiered config example with nconf

Startup a service that depends on amino

./bin/myservice --conf=/path/to/my/conf

Startup a service using the default conf path

./bin/myservice

@bensomers
bensomers / rails_routing_invalid_chars_fix.rb
Created May 29, 2012 19:08
3.0.x monkeypatch for fixing Invalid Char 500s
# Fix for a Rails - Ruby 1.9 bug
# Rails Router, now that it's UTF-8 default, blows up when routing requests
# with invalid chars in the URL; it should properly return a 400 error
# Have to monkey-patch the fix in, since it's not scheduled for release until
# Rails 4.0.
# Adapted Andrew White (pixeltrix)'s fix at
# https://github.com/rails/rails/commit/3fc561a1f71edf1c2bae695cafa03909d24a5ca3,
# but edited to work in 3.0.x.
# 3.1.x, 3.2.x compatibility unknown
require 'action_dispatch/routing/route_set'
# Unicorn self-process killer
require ::File.expand_path('../lib/unicorn/unicorn_killer', __FILE__)
use UnicornKiller::MaxRequests, 10240 + Random.rand(10240)
use UnicornKiller::Oom, 96 * 1024 + Random.rand(32) * 1024
# Out-Of-Band GC
require 'unicorn/oob_gc'
use Unicorn::OobGC
@daithiw44
daithiw44 / gist:3032376
Created July 2, 2012 09:50
Nodejs Anagram Website Scraper with express and Domains, update to previous example gist: 1335009
// Updated example to utilize 'basic' Domains with express.
// Website Scraper that scrapes off a site (without permission I may add)
// had seen some screen scraping examples using jQuery this example is jQuery-less.
var express = require('express'),
request = require('request'),
jsdom = require('jsdom'),
builder = require('xmlbuilder').create(),
sys = require('util'),
createDomain = require('domain').create,
app = express.createServer();