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 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 file contains 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 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 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 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 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 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 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
--- | |
# ^^^ YAML documents must begin with the document separator "---" | |
# | |
#### Example docblock, I like to put a descriptive comment at the top of my | |
#### playbooks. | |
# | |
# Overview: Playbook to bootstrap a new host for configuration management. | |
# Applies to: production | |
# Description: | |
# Ensures that a host is configured for management with Ansible. |
This file contains 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
[unix_http_server] | |
file=/tmp/supervisor.sock ; path to your socket file | |
[supervisord] | |
logfile=/var/log/supervisord/supervisord.log ; supervisord log file | |
logfile_maxbytes=50MB ; maximum size of logfile before rotation | |
logfile_backups=10 ; number of backed up logfiles | |
loglevel=error ; info, debug, warn, trace | |
pidfile=/var/run/supervisord.pid ; pidfile location | |
nodaemon=false ; run supervisord as a daemon |