Skip to content

Instantly share code, notes, and snippets.

View delano's full-sized avatar
👋
Let's talk about building teams

Delano delano

👋
Let's talk about building teams
View GitHub Profile
@delano
delano / .bashrc
Created July 8, 2009 21:37 — forked from defunkt/.bashrc
# $ 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
require 'digest/sha1'
class String
def hash
Digest::SHA1.hexdigest self
end
def bit
unpack('B*').first
end

A (Nicer) Redis Client for EventMachine

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:

# 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
# 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
#
@delano
delano / gist:837654
Created February 21, 2011 20:22
thbll.com integration in Ruby
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
#
@delano
delano / gist:845643
Created February 26, 2011 21:29
Fix for "Errno::ETIMEDOUT: Operation timed out - connect(2)" when installing gems
# 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)
@delano
delano / Distraction Free.sublime-settings
Created December 17, 2012 01:34
SublimeText2 Preferences
{
"line_numbers": true,
"gutter": true,
"draw_centered": false,
"wrap_width": 0,
"word_wrap": false,
"scroll_past_end": true
}
---
# ^^^ 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.
[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