Skip to content

Instantly share code, notes, and snippets.

@suside
suside / UnionStringSerializer.fs
Created May 12, 2023 06:36
Union serialization provider for F#
let UnionToString (u: 'a) =
match FSharpValue.GetUnionFields(u, typeof<'a>) with
| case, _ -> case.Name
let StringToUnion<'a> (s: string) =
match FSharpType.GetUnionCases typeof<'a> |> Array.filter (fun case -> case.Name = s) with
| [| case |] -> FSharpValue.MakeUnion(case, [||]) :?> 'a
| _ -> failwithf "Unable to parse %A" s
type UnionStringSerializer<'a>() =

Keybase proof

I hereby claim:

  • I am suside on github.
  • I am suside (https://keybase.io/suside) on keybase.
  • I have a public key ASAsODTiM_SHOTd3E_seKD-PQc6eYSoKCyKppNDS9rObLwo

To claim this, I am signing this object:

@suside
suside / Makefile
Last active November 23, 2017 13:44
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
echo:
echo $(MAKEFILE_LIST)
echo $(lastword $(MAKEFILE_LIST))))
echo $(realpath $(lastword $(MAKEFILE_LIST))))
@suside
suside / HAProxy_and_K8s.md
Created April 20, 2017 12:08
Kubernetes + HAProxy sticky session affinity

Kubernetes + HAProxy sticky session affinity

  1. Make sure you have balance source in haproxy.
  2. Backend server section in haproxy config should have all your k8s nodes.
  3. sessionAffinity in k8s is irrelevant.
  4. Exposed k8s service need to have nodePort set and this annotation:

kubectl annotate service myService service.beta.kubernetes.io/external-traffic=OnlyLocal

This will cause internal k8s loadbalancer on nodeⁿ to route traffic only to pod on nodeⁿ. From Haproxy point of view it will look like nodeⁿ:nodePort === pod on nodeⁿ:port thus disabling k8s LB completly.

@suside
suside / logs.sh
Created September 21, 2016 08:48
journald logs disk usage group by/per unit/container
#!/bin/bash
echo "***************************** CONTAINERS *****************************"
for F in `journalctl -F CONTAINER_NAME`
do
echo "$(journalctl CONTAINER_NAME=$F | wc -c | awk '{ print $1/1024/1024"MB" }') $F"
done | sort -nrk 1 | column -c 2
echo "***************************** UNITS *****************************"
for F in `journalctl -F UNIT`
@suside
suside / index.js
Created June 6, 2016 10:46
One line RamdaJS template 'engine'
const R = require('ramda');
const _ = R.curry((tpl, data) => R.reduce((ac, k) => R.replace(`{{${k}}}`, data[k], ac), tpl, R.keys(data)));
_('Hello {{var}}', {var: 'world'}); // => Hello world
const compiled = _('{{var1}} {{var2}}');
compiled({var1: 'Hello', var2: 'world'}); // => Hello world
@suside
suside / scent.py
Created December 12, 2013 08:48
sniffer scent.py + django + remote eclipse auto open
import re
from subprocess import call
import requests
from sniffer.api import runnable
@runnable
def execute_tests(*args):
result = call(str(args[1] + ' --verbosity 2 --nologcapture --stop --with-xunit --xunit-file=/run/shm/test_output.xml').split(' ')) == 0
@suside
suside / bug65345.patch
Created October 15, 2013 13:02
Fix for Bug #65345 Segfault in xhprof_enable() Only for php 5.5.* https://bugs.php.net/bug.php?id=65345
diff --git a/extension/xhprof.c b/extension/xhprof.c
index f553a35..7db4f00 100644
--- a/extension/xhprof.c
+++ b/extension/xhprof.c
@@ -1775,35 +1775,7 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data,
BEGIN_PROFILING(&hp_globals.entries, func, hp_profile_flag);
}
- if (!_zend_execute_internal) {
- /* no old override to begin with. so invoke the builtin's implementation */
/*
Allows for ajax requests to be run synchronously in a queue
Usage::
var queue = new $.AjaxQueue();
queue.add({
url: 'url',
@suside
suside / guake.py
Created May 7, 2013 08:08
guake 2 screens
#! /usr/bin/python
# -*- coding: utf-8; -*-
"""
Copyright (C) 2007-2012 Lincoln de Sousa <lincoln@minaslivre.org>
Copyright (C) 2007 Gabriel Falcão <gabrielteratos@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.