Skip to content

Instantly share code, notes, and snippets.

View mattsta's full-sized avatar
🐢
Moving slowly and fixing things

Matt Stancliff mattsta

🐢
Moving slowly and fixing things
View GitHub Profile
@mattsta
mattsta / GETEX.lua
Last active August 29, 2015 13:57
Sample "GETEX" Redis function returning GET values as multibulk instead of a simple string. Returns a Redis error on error or a 1.) Value when given a string key.
local val,err = redis.pcall('get', KEYS[1])
if err then
return err
else
return {val}
end
@mattsta
mattsta / PGETEX.lua
Last active August 29, 2015 13:57
Sample "PGETEX" Redis function returning GET values combined with PTTL. Returns error if non-string key, nil on no key, or a multi-bulk reply of 1.) Value 2.) PTTL.
local val = redis.call('get', KEYS[1])
if val then
return {val, redis.call('pttl', KEYS[1])}
else
return false
end
@mattsta
mattsta / hn-comments-on-death.txt
Last active August 29, 2015 13:57
Word frequency of comments about a post about someone dying soon. Words obtained from this comment thread: https://news.ycombinator.com/item?id=7390638
(world)matt@ununoctium:~/repos/wf% python text.py
Words occuring more than 3 times:
Number is the count of times the word occured in the data.
3: gdp, limited, cobra, :(, global, cheap, soon, rest, produced, kill, looks,
earth, disease,, saved, worked, party,, happiness., certainly, work., pray,
$500k, months., either., 0, preparing, asking, stefantalpalaru, 300bps, easy,
inherited, folks, sorry, full,, disproportionate, opt, ago,, sick, ilovecookies,
little,, dependent, celebrities, advocate, begging, choice, young., joint,
suffering, wishes, example, one., fall, report, using, more., chongli, kids,,
massively, about,, loss, term, crops, problems,, problems., solution, anything,,
@mattsta
mattsta / hn-comments-on-work-drama
Last active August 29, 2015 13:57
Word frequency of comments about a post about someone being mentally abused at work. Words obtained from this comment thread: https://news.ycombinator.com/item?id=7408055
(world)matt@ununoctium:~/repos/wf% python text.py drama | fold -s
===============================================================================
Count of sentence ending words:
72: it.
35: sexism.
31: them.
24: people.
@mattsta
mattsta / redis-cluster-solaris-11-bring-up
Created March 21, 2014 15:40
Solaris 11 Redis Cluster Bring-Up
# Bring in dependencies if needed:
sudo pkg install ruby
sudo gem install redis
# Start 9 servers on 127.0.0.1 and 9 servers on net0's IP address
cd redis/src
for dir in {1..9}; do mkdir $dir; pushd $dir; rm -f *.conf *.rdb; ../redis-server --bind 127.0.0.1 --cluster-enabled yes --port 700$dir & popd; done
IP=`/sbin/ifconfig net0 |grep inet |awk '{printf $2}'`
for dir in {21..29}; do mkdir $dir; pushd $dir; rm -f *.conf *.rdb; ../redis-server --bind $IP --cluster-enabled yes --port 70$dir & popd; done
@mattsta
mattsta / redis-cluster-linux-bring-up
Last active August 29, 2015 13:57
Redis Cluster Linux Bring-Up
# Launch 18 redis cluster instances on one machine using two IPs
cd redis/src
for dir in {1..9}; do mkdir $dir; pushd $dir; rm -f *.conf *.rdb; ../redis-server --bind 127.0.0.1 --cluster-enabled yes --port 700$dir & popd; done
IP=`/sbin/ifconfig eth0 |grep "inet addr" | tail -1 |awk '{printf $2}' |awk -F: '{printf $2}'`
for dir in {21..29}; do mkdir $dir; pushd $dir; rm -f *.conf *.rdb; ../redis-server --bind $IP --cluster-enabled yes --port 70$dir & popd; done
./redis-trib.rb create --replicas 1 127.0.0.1:{7001..7009} $IP:{7021..7029}
@mattsta
mattsta / hmset.sh
Last active August 29, 2015 14:00
test a redis pathology with hmset
#!/bin/bash
ARGS="-c 10 -n 1"
PATH=~/repos/redis/src
redis-benchmark $ARGS eval '
for i=0,50000 do
local key = string.format("data/%019d/xxxxxxxxxxxxxxxxxx", i)
redis.call("HMSET", key, "AAAAAAAAAAA:current", "AA", "AAAAAAAAAAA:current-time", "Thu May 01 11:08:34 BST 2014", "AAAAAAAAAAA:target", "AA", "AAAAAAAAAAA:target-time", "Thu May 01 11:08:34 BST 2014", "aaaaaaaaaaaaaaaaaaaa:current", "aa", "aaaaaaaaaaaaaaaaaaaa:current-time", "Thu May 01 11:08:34 BST 2014", "aaaaaaaaaaaaaaaaaaaa:target", "aa", "aaaaaaaaaaaaaaaaaaaa:target-time", "Thu May 01 11:08:34 BST 2014", "bbbbb:current", "bbbbbbbbbbbbbbbbbbbbbbbbb", "bbbbb:current-time", "Thu May 01 11:08:34 BST 2014", "bbbbb:target", "bbbbbbbbbbbbbbbbbbbbbbbbb", "bbbbb:target-time", "Thu May 01 11:08:34 BST 2014", "cccccccccccccccccccccc:current", "cc", "cccccccccccccccccccccc:current-time", "Thu May 01 11:08:34 BST 2014", "cccccccccccccccccccccc:target", "cc", "cccccccccccccccccccccc:target-time", "Thu May 01 11:08:34 BST 2014", "ddddddddd
@mattsta
mattsta / bench.pl
Created June 22, 2014 05:41
Quick Redis speed comparison script
#!/usr/bin/perl
use warnings;
use strict;
use IO::All;
use IO::Socket::UNIX qw( SOCK_STREAM );
use Benchmark ':hireswallclock';
use Redis;
use RedisDB;
@mattsta
mattsta / size_parse.c
Created September 11, 2014 03:29
Quick redis integer size parsing tests
/* Usage: ./size_parse INTEGER [1-5] */
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
@mattsta
mattsta / clang-O0.s
Created September 16, 2014 21:30
Comparing geohash assembly output based on compiler optimization levels
.section __TEXT,__text,regular,pure_instructions
.section __DWARF,__debug_info,regular,debug
Lsection_info:
.section __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
.section __DWARF,__debug_aranges,regular,debug
.section __DWARF,__debug_macinfo,regular,debug
.section __DWARF,__debug_line,regular,debug
Lsection_line:
.section __DWARF,__debug_loc,regular,debug