Redis is my favourite key/value store; it’s flexible, easy to set up and insanely fast. [EventMachine][] is a popular Ruby library for doing asynchronous I/O using an event loop. Bindings already [exist][em-redis] for accessing a Redis server using EM’s async-I/O (courtesy of Jonathan Broad), but unfortunately the resulting code has to use [Continuation-Passing Style][cps] via Ruby blocks. A very basic example of what that looks like follows:
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
Show hidden characters
| { | |
| "line_numbers": true, | |
| "gutter": true, | |
| "draw_centered": false, | |
| "wrap_width": 0, | |
| "word_wrap": false, | |
| "scroll_past_end": true | |
| } |
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 DNS change to Rubygems.org is causing lingering issues. Namely, | |
| # rubygems.org and production.s3.rubygems.org are still pointing to | |
| # the old address. See: | |
| # http://twitter.com/#!/gemcutter/status/30666857698557952 | |
| # The symptoms: | |
| # $ gem install benelux --version 0.5.17 | |
| # ERROR: Could not find a valid gem 'benelux' (= 0.5.17) in any repository | |
| # ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) |
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 TheBell | |
| include HTTParty | |
| #debug_output $stdout | |
| base_uri 'http://api.thbll.com/ring-the-bell/SITENAME' | |
| def self.ring | |
| post("/PASSPHRASE/", :body => {}) | |
| end | |
| 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
| # Author: Pieter Noordhuis | |
| # Description: Simple demo to showcase Redis PubSub with EventMachine | |
| # | |
| # Requirements: | |
| # - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby | |
| # - a browser with WebSocket support | |
| # | |
| # Usage: | |
| # ruby redis_pubsub_demo.rb | |
| # |
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
| # Power law (log tail) distribution | |
| # Copyright(C) 2010 Salvatore Sanfilippo | |
| # this code is under the public domain | |
| # min and max are both inclusive | |
| # n is the distribution power: the higher, the more biased | |
| def powerlaw(min,max,n) | |
| max += 1 | |
| pl = ((max**(n+1) - min**(n+1))*rand() + min**(n+1))**(1.0/(n+1)) | |
| max-1-pl.to_i |
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 'digest/sha1' | |
| class String | |
| def hash | |
| Digest::SHA1.hexdigest self | |
| end | |
| def bit | |
| unpack('B*').first | |
| 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
| # $ tweet "your message" | |
| # | |
| # See: http://solutious.com/blog/2009/07/13/bash-twitter/ | |
| # | |
| # Contributors | |
| # * @defunkt for the initial version | |
| # * @anildigital and @grundprinzip for curl-fu | |
| # * @solutious for the SSL sexytime | |
| # See: http://curl.netmirror.org/docs/caextract.html |
This gist describes a working Rudy configuration for running the Bonnie64 benchmark on EC2.
- Install Rudy
- Follow the Getting Started guide up to and including "Create Accounts Configuration".
- Download this gist
git clone git://gist.github.com/123400.git bonnie64-aws-test
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
| In response to all the responses to: | |
| http://twitter.com/rtomayko/status/1155906157 | |
| You should never do this in a source file included with your library, | |
| app, or tests: | |
| require 'rubygems' | |
| The system I use to manage my $LOAD_PATH is not your library/app/tests |