This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "trie.h" | |
template <typename T> Trie<T>::Node& | |
Trie<T>::Node::operator [](char const* aString) | |
{ | |
Node* node; | |
unsigned long s, e, i, n; | |
unsigned char r, l, c, d; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
while (<>) { | |
s/\t/|/g; # Convert Tabs to Pipes | |
s/\r?\n/[]\r\n/g; # Add [] at EOL and Convert to CRLF | |
s/^\|+\[\]\r\n//g; # Remove Empty Lines | |
print; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
util = require 'util' | |
after = (time, args..., callback) -> setTimeout callback, time, args... | |
class Game | |
score: 0 | |
score_step: 20 | |
constructor: (@client, @difficulty = 800) -> | |
@send 'HELO :Welcome to Pong!' | |
@send 'HELP :When you receive a PING <code>,' | |
@send 'HELP :reply quickly with PONG <code>,' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- Which allows you to do cool stuff like this: --> | |
<%= stylesheet_link_tag *controller.ancestry %> | |
<%= javascript_include_tag *controller.ancestry %> | |
<!-- So from within BarController, the stylesheets would look like this: --> | |
<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def missing(list) | |
min, max, sum = list.reduce([f = list.first, f, 0]) do |(l, h, s), n| | |
[n < l ? n : l, n > h ? n : h, s + n] | |
end | |
max * (max + 1) / 2 - min * (min - 1) / 2 - sum | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry.config.should_load_plugins = false | |
Pry.config.editor = proc { |file, line| "subl -w #{file}:#{line}" } | |
Pry.prompt = [ | |
proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, | |
proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " } | |
] | |
Pry.plugins['doc'].activate! | |
class BasicObject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'yard' | |
libs = {} | |
gems = {} | |
base = ENV['GEM_PATH'].split(':')[1][%r{^.+(?=/.+@global$)}] rescue nil | |
if base | |
Gem.paths = { | |
'GEM_PATH' => Dir["#{base}/ruby-*"].join(':'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Prepare ################################################################### | |
# Remove RVM | |
rvm implode | |
# Ensure your homebrew is working properly and up to date | |
brew doctor | |
brew update | |
## Install ################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-spec timestamp(atom(), binary(), object()) -> object(). | |
%% Facebook Timestamp (eg. <<"2011-11-21T22:37:44+0000">>) | |
timestamp(Field, <<Year:4/binary, $-, Month:2/binary, $-, Day:2/binary, $T, | |
Hour:2/binary, $:, Minute:2/binary, $:, Second:2/binary, Offset:5/binary>>, Acc = #fb_object{}) -> | |
Date = {?BIN_TO_INT(Year), ?BIN_TO_INT(Month), ?BIN_TO_INT(Day)}, | |
Time = {?BIN_TO_INT(Hour), ?BIN_TO_INT(Minute), ?BIN_TO_INT(Second)}, | |
DateTime = case Offset of | |
<<"+0000">> -> % UTC | |
{Date, Time}; | |
_ -> |
OlderNewer