Skip to content

Instantly share code, notes, and snippets.

View fnchooft's full-sized avatar

Fabian N.C. van 't Hooft fnchooft

View GitHub Profile
@fnchooft
fnchooft / getmsgpackasjson.lua
Created February 1, 2017 00:24 — forked from fritzy/getmsgpackasjson.lua
Redis scripts to set JSON in, store as MSGPack, and get JSON out.
--EVAL 'this script' 1 some-key
local key = KEYS[1];
local value = redis.call('GET', key);
local jvalue = cjson.encode(cmsgpack.unpack(value));
return jvalue;
@fnchooft
fnchooft / Redis_Stats.md
Created February 1, 2017 00:30 — forked from thomasdarimont/Redis_Stats.md
Example for computing various running statistics with Lua in Redis backed by a hash

Running statistics with Redis and Lua

This is an example for computing running statistics with Lua backed by a hash in Redis. We support counting, average (with and without exponential smoothing), stddev, variance, min, max, sum of observed values. An example for approximating a running median can be found here: https://gist.github.com/thomasdarimont/fff68191d45a001b2d84

Data structure

We use a hash for storing various statistic value under the key "stats_value" in redis. Note: If you need a specific alpha value for smoothing the average, then set the desired alpha -> e.g. alpha 0.7. If alpha is 0.0 then no smoothing is applied.

alias.lol=log --oneline --decorate --all --graph --date-orde
alias.lo=log --oneline --decorate --graph --date-order
merge.tool=meld
diff.tool=meld
diff.guitool=meld
#GIT
PS1='[${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[00m\]$(__git_ps1)]\$ '
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=1
alias l='ls -CF'
alias o='gvfs-open'
alias v='ls -lh'
alias vv="du --max-depth=1 -k | sort -nr | cut -f2 | xargs -d '\n' du -sh"
alias ducks='du -ck | sort -nr | head'
alias nocomment='grep -Ev '\''^(#|$)'\'''
@fnchooft
fnchooft / gist:f95dd13c76b9c8ed38abb29159cf1cd5
Created February 2, 2017 11:21
Bash function for history lookups
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=100000
HISTFILESIZE=200000
function h() {
if [ -z "$1" ]
then
history
else
history | grep "$@"
@fnchooft
fnchooft / gist:a3f0231596f2514807b937d2f5632bb9
Created February 13, 2017 00:32 — forked from klovadis/gist:5170446
Two Lua scripts for Redis to turn HGETALL and HMGET into dictionary tables
-- gets all fields from a hash as a dictionary
local hgetall = function (key)
local bulk = redis.call('HGETALL', key)
local result = {}
local nextkey
for i, v in ipairs(bulk) do
if i % 2 == 1 then
nextkey = v
else
result[nextkey] = v
@fnchooft
fnchooft / SPUBLISH.lua
Created February 17, 2017 17:16 — forked from alexanderscott/SPUBLISH.lua
Redis Lua script to publish a message to all SET member channels
-- @desc: Publish a message to all SET member channels
-- @usage: redis-cli EVAL "$(cat SPUBLISH.lua)" 1 <setKey> <message>
-- @return: number of SET member channels
local function SPUBLISH(key, msg)
local members = redis.call("SMEMBERS", key)
for _,member in ipairs(members) do
redis.call("PUBLISH", member, msg)
end
@fnchooft
fnchooft / xmltest.erl
Created April 24, 2017 22:45 — forked from afternoon/xmltest.erl
Examples of generating XML with Erlang's xmerl library.
-module(xmltest).
-compile(export_all).
-include_lib("xmerl/include/xmerl.hrl").
%% @doc Helper function to generate XML from a data structure and print it
serialize(Data) ->
Xml = lists:flatten(xmerl:export_simple(Data, xmerl_xml)),
io:format("~s~n", [Xml]).
@fnchooft
fnchooft / table.filter.lua
Created June 8, 2017 09:55 — forked from FGRibreau/table.filter.lua
Lua table.filter (JavaScript Array::filter equivalent)
-- table.filter({"a", "b", "c", "d"}, function(o, k, i) return o >= "c" end) --> {"c","d"}
--
-- @FGRibreau - Francois-Guillaume Ribreau
-- @Redsmin - A full-feature client for Redis http://redsmin.com
table.filter = function(t, filterIter)
local out = {}
for k, v in pairs(t) do
if filterIter(v, k, t) then out[k] = v end
end
@fnchooft
fnchooft / GitHub Flavored Asciidoc (GFA).adoc
Created December 4, 2017 17:42 — forked from dcode/GitHub Flavored Asciidoc (GFA).adoc
Demo of some useful tips for using Asciidoc on GitHub

GitHub Flavored Asciidoc (GFA)