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 / README
Created August 15, 2024 17:32 — forked from nkabardin/README
Erlang xmerl-based simple xml parsing
# Example xml
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<application id="test">
<platform id="vk">
<appId>123</appId>
<secretKey>secret</secretKey>
<packages>
<package id="vk0" price="100" points="3" />
@fnchooft
fnchooft / xlsx_file.livemd
Created April 23, 2024 01:33
Livebook Example for XLSX - Some data transformations are needed

XSLX - files new action

Mix.install([
  {:kino, "~> 0.12.0"},
  {:xlsx_reader, "~> 0.8.3"}
])

Section

@fnchooft
fnchooft / ErlangCode_to_XML
Last active November 9, 2021 22:55
From Erlang Code - via edoc - to a XML-representation
In order to use the Erlang-syntax as interface descriptions ( using types, records, fields , etc),
I needed an XML-representation for the module.
You might have heard for the AbstractCode which can be generated from the module, for instance like this:
```
{ok, {rec, [{abstract_code, Abs}]}} = beam_lib:chunks("rec.beam", [abstract_code])2> rp(Abs).
```
But that is not exactly what I wanted. While talking during CodeBeam about this the OTP team told me that edoc
already does this for you, and right they are:
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
@fnchooft
fnchooft / sid_tools.erl
Created March 2, 2020 13:01
Sid encoding....
-module(sid_tools).
-compile([export_all]).
% https://github.com/core-wg/comi/blob/master/draft-ietf-core-comi.md
% https://tools.ietf.org/html/rfc4648#section-5
-define(CHARSET64,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_").
sid_encoded(Sid) ->
Chars = [
(Sid bsr 60) band 16#3F,
@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)

@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 / 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 / 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 / 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