Skip to content

Instantly share code, notes, and snippets.

@abesto
abesto / simple_redis_profile.rb
Created March 1, 2012 13:53 — forked from gtd/simple_redis_profile.rb
By sampling keys from your redis databases, this script tries to identify what types of keys are occupying the most memory.
#!/usr/bin/env ruby
# Evaluates a sample of keys/values from each redis database, computing statistics for each key pattern:
# keys: number of keys matching the given pattern
# size: approximation of the associated memory occupied (based on size/length of value)
# percent: the proportion of this 'size' relative to the sample's total
#
# Copyright Weplay, Inc. 2010. Available for use under the MIT license.
#
# Changes in this fork (abesto) by Zoltán Nagy <abesto@abesto.net>
@abesto
abesto / bcrypt.php
Created August 3, 2011 12:17 — forked from dzuelke/bcrypt.php
How to use bcrypt in PHP to safely store passwords (PHP 5.3+ only)
<?php
// secure hashing of passwords using bcrypt, needs PHP 5.3+
// see http://codahale.com/how-to-safely-store-a-password/
// salt for bcrypt needs to be 22 base64 characters (but just [./0-9A-Za-z]), see http://php.net/crypt
// 2a is the bcrypt algorithm selector, see http://php.net/crypt
// 12 is the workload factor (around 300ms on a Core i7 machine), see http://php.net/crypt
function bcrypt($message, $salt, $cost=12)
{
if (preg_match('~[./0-9A-Za-z]{22}~', $salt) === 0) throw new RuntimeException('bcrypt expects a salt of 22 digits of the alphabet [./0-9A-Za-z]');
@abesto
abesto / coffescript-slotsig.coffee
Created May 28, 2011 22:05
Slots and signals for CoffeeScript
##
# Slots and signals implementation for classes
# (Porting to using simple functions should be almost trivial
##
class Connection
constructor: (@sender, @signal, @receiver, @slot) ->
connections = [] # List of connections
strict = true