Skip to content

Instantly share code, notes, and snippets.

View nrk's full-sized avatar
🤔
はい、猫のように見えます。

Daniele Alessandri nrk

🤔
はい、猫のように見えます。
View GitHub Profile
@nrk
nrk / redis_hash_copy.php
Created November 8, 2011 10:50
Use Redis scripting to copy an hash to a new key.
<?php
require 'autoload.php';
$redis = new Predis\Client('tcp://127.0.0.1', 'dev');
// *** NOTE *** Lua's unpack() has a limit on the size of the table imposed by
// the number of Lua stack slots that a C function can use. This value is defined
// by LUAI_MAXCSTACK in luaconf.h and for Redis is set to 8000, which translates
// to an hash of 4000 elements since HGETALL returns a list that interleaves field
@nrk
nrk / gist:1305921
Created October 22, 2011 12:10 — forked from DoggettCK/gist:1305566
Code from "Enumerations and Strings - Stop the Madness!" (modified and added over time)
using System;
using System.Collections.Generic;
using System.Linq;
namespace Util
{
public static class Enums
{
#region Parse Methods
/// <summary>
@nrk
nrk / gist:1265565
Created October 5, 2011 20:19 — forked from mazur/gist:1003052
Build IronRuby on mono OSX/Ubuntu
#!/bin/bash
shopt -s extglob #Enables extglob
# OS: OSX 10.6.7 and Ubuntu 11.04
# Mono: 2.10.1
# Mono 2.10 is required since we need C# 4.0 support to compile IronRuby.
# C# 4.0 support can either be found in mono 2.10 or 2.6 compiled with special
# flags.
@nrk
nrk / RedisPublishHandler.php
Created August 24, 2011 14:01
A simple handler for Monolog that publishes log entries to Redis channels.
<?php
namespace Nrk\Monolog\Handler;
use Predis\Client;
use Monolog\Logger;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\AbstractProcessingHandler;
/**
@nrk
nrk / AliasBasedHashRing.php
Created August 20, 2011 16:44
Use a node alias instead of the ip:port pair when calculating the hash of a node in a cluster with Predis.
<?php
namespace Nrk;
use Predis\Distribution\HashRing;
// NOTE: this class won't work with a version of Predis prior to commit b30f495
class AliasBasedHashRing extends HashRing {
public function add($node, $weight = null) {
@nrk
nrk / command.txt
Created June 25, 2011 12:30
Getting SMART info out of a disk with smartctl on openindiana
smartctl -a /dev/rdsk/c1t1d0 -d sat,12
@nrk
nrk / lolwut.lua
Created June 20, 2011 06:46
Using pcall in Lua
local lol = {
wut = function(self, ...)
error("LOL WUT")
end,
}
-- this would normally be used like: lol:wut(1,2)
local s,e = pcall(lol.wut, lol, 1, 2)
print(s,e) -- false lol.lua:3: LOL WUT
@nrk
nrk / alchemydb.lua
Created June 14, 2011 09:11
Define AlchemyDB commands with redis-lua
require 'redis'
Redis.define_command('create_table', {
request = function(client, command, ...)
local args, arguments = {...}, {}
if #args ~= 2 then
print ('Usage: create_table tablename column_definitions');
return false;
end
table.insert(arguments, 'TABLE');
@nrk
nrk / 00_LICENSE
Created May 9, 2011 19:22
Streaming responses with Silex.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@nrk
nrk / gist:941578
Created April 26, 2011 00:50 — forked from shripadk/gist:652819
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'