Skip to content

Instantly share code, notes, and snippets.

View Ubuntu reduce TIME_WAIT and set socket recycle and reuse
sudo vi /etc/sysctl.conf
# Add the following to sysctl.conf:
# Decrease TIME_WAIT seconds
net.ipv4.tcp_fin_timeout = 30
# Recycle and Reuse TIME_WAIT sockets faster
net.ipv4.tcp_tw_recycle = 1
@taiju
taiju / underscore.partition-full-params.js
Created Aug 27, 2012
partition method full params for underscore.js
View underscore.partition-full-params.js
var partitionIterator = function(array, n, step, pad, is_all, result) {
if (_.size(array) < n) {
if (_.isNull(pad) && is_all) return (_.isEmpty(array)) ? result : result.concat([array]);
else if (!_.isNull(pad) && !is_all) return result.concat([array.concat(_.take(pad, n - _.size(array)))]);
else return result;
}
else return partitionIterator(_.rest(array, step), n, step, pad, is_all, result.concat([_.take(array, n)]));
};
_.mixin({
@szimek
szimek / a.md
Created Jun 29, 2012 — forked from rkh/a.md
View a.md

This allows you to use the following video streaming services outside of the US from your Mac without having to use a proxy or VPN, so no big bandwidth issues:

  • Netflix
  • Hulu / HuluPlus
  • CBS
  • ABC
  • MTV
  • theWB
  • CW TV
  • Crackle
@jlong
jlong / uri.js
Created Apr 20, 2012
URI Parsing with Javascript
View uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
View gist:981520
# Bulk API design
#
# resources :posts
class PostsController < ActiveController::Base
# GET /posts/1,4,50,90
# post_url([ @post, @post ])
def show_many
@posts = Post.find(params[:ids])
end
View shared_connection.rb
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end