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
class RetriableRedis | |
# Wraps a redis connection, automatically retrying commands | |
# if the connection is refused | |
# Redis across our AWS instances is stable, but AutoSSH isn't | |
# perfect, this works around that for minor blips | |
# It'd be great if we consolidate around a single AWS acct. and get | |
# rid of SSH, but with EY that isn't easy | |
attr_accessor :connection | |
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
tion.rb:724:in `gsub': invalid byte sequence in US-ASCII (ArgumentError) | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:724:in `to_yaml' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:78:in `block (2 levels) in write_package' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:73:in `block (3 levels) in add_gem_contents' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_writer.rb:83:in `new' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:67:in `block (2 levels) in add_gem_contents' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:65:in `wrap' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:65:in `block in add_gem_contents' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_writer.rb:113:in `add_file' | |
from /usr/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:63:in `add_gem_contents' |
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
> h = Hash.new({}); h[1][1] = 'a'; h[2][2] = 'b'; puts h[1]; h | |
1a2b | |
=> {} | |
irb(main):013:0> h | |
=> {} | |
irb(main):014:0> h[1] | |
=> {1=>"a", 2=>"b"} |
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
(defn ^{:connection (atom nil)} | |
redis-exec | |
"Executes a redis command with a default connection" | |
[command] | |
(let [connection (:connection (meta #'redis-exec))] | |
(compare-and-set! connection | |
nil | |
(redis-client {:host "localhost"})) | |
(@connection command))) |
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
find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x |
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
find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x |
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 (addFlagging) { | |
flaggings.add(flaggingUserId); | |
} { | |
flaggings.remove(flaggingUserId); | |
} |
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
task :clockwork => :environment do | |
Clockwork.every(10.seconds, "events.update_viewers") { | |
Resque.enqueue(ViewerCountWorker) | |
} | |
Clockwork.run | |
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
# A typical piece of data | |
> mixed_data = {"id"=>18929882, "title"=>"Lorem Ipsum", "author"=>"Sit Dolor"} | |
# JSON stores the data in a reasonable amount of space... | |
> mixed_data.to_json.length | |
=> 58 | |
# But messagepack does much better | |
> MessagePack.pack(mixed_data).length | |
=> 44 | |
# That's a pretty big difference! But its even more efficient with numbers | |
> numerical_array = [1223, 2190, 1980092, 8932191892, 98321982189] |
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 'ffi-rzmq' | |
CTX = ZMQ::Context.new 1 | |
class ZBufferedStream | |
attr_reader :bind_to, :buffer_uri, :ingress | |
def initialize(name,bind_to) | |
@bind_to = bind_to | |
@buffer_uri = "inproc://#{name}" |