Skip to content

Instantly share code, notes, and snippets.

View shaxbee's full-sized avatar

Zbigniew Mandziejewicz shaxbee

  • Chiang Mai, Thailand
View GitHub Profile
@shaxbee
shaxbee / intersect_values.py
Last active December 28, 2015 15:29
Given two dictionaries containing key -> list of values mapping create intersection mapping common keys to dot product of values.
from itertools import product
def intersect_values(left, right):
intersection = left.viewkeys() & right.viewkeys()
return {key: list(product(left[key], right[key])) for key in intersection}
assert intersect_values({'A': [1, 2], 'B': [5]}, {'A': [3, 7]}) == {'A': [(1, 3), (1, 7), (2, 3), (2, 7)]}
@shaxbee
shaxbee / ordsample.py
Created March 8, 2014 03:46
Ordered random sample generator
def ordered_sample(population, k):
"""
Generate k-sized ordered random sample of population
Implementation of Kramer algorithm.
"""
x = 0
size = len(population)
for i in xrange(k):
x = size - int((size - x) * (random.random() ** (1.0 / (k - i))))
@shaxbee
shaxbee / flatten.py
Last active August 29, 2015 14:09 — forked from mrluanma/flatten.py
How to flatten a python nested list(tuple) - generator
#!/usr/bin/env python3
import collections
def flatten(t):
"""
Generator flattening the structure
>>> list(flatten([2, [2, (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
@shaxbee
shaxbee / sscontext.go
Created April 27, 2016 03:47
Wrapper for grpc ServerStream providing context override
package streamutil
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
)
struct serverStreamWithContext {
grpc.ServerStream
ctx context.Context
@shaxbee
shaxbee / protogen.pl
Last active June 27, 2016 02:44
Protobuf GRPC compiler driver
#!/usr/bin/env perl
use strict;
use warnings;
use File::Which;
use File::Spec;
use File::Basename;
use Env qw(GOPATH);
use Getopt::Long;
@shaxbee
shaxbee / client-binding.txt
Created February 27, 2018 20:18
Client Binding
title Client Binding
Client -> Client: generate client key & certificate request
Client -> Server: send certificate request with device id
Server -> Server: generate client certificate
Server -> Client: send client certificate
loop request
Client -> Server: make request using client certificate
Server -> Client: reply
@shaxbee
shaxbee / authorization_ok.md
Created September 7, 2021 13:24
Envoy Authorization Flow - OK
sequenceDiagram
    participant Client
    participant Envoy
    participant ACL
    participant JWKS Server
    participant Backend

    loop Keys
 ACL->>JWKS Server: Fetch JWKS