Skip to content

Instantly share code, notes, and snippets.

View smarnach's full-sized avatar
🦀

Sven Marnach smarnach

🦀
  • Mozilla
  • Preetz, Germany
View GitHub Profile
@smarnach
smarnach / get_logs.md
Last active April 30, 2021 07:56
Parse AWS EKS audit logs for APIs removed in Kubernetes 1.16

This command can be used to retrieve pre-filtered logs from AWS:

aws logs filter-log-events \
    --log-group-name /aws/eks/<cluster_name>/cluster \
    --log-stream-name-prefix kube-apiserver-audit \
    --start-time <time_since_epoch_in_ms> \
    --filter-pattern '"v1beta1"' \
    --region <region>
@smarnach
smarnach / day05.rs
Created January 4, 2019 22:36
Advent of Code Day 5
fn annihilate(polymer: &[u8], remove: u8) -> Vec<u8> {
let mut result = Vec::new();
for &c in polymer {
if c == remove || c ^ 32 == remove {
continue;
}
if result.is_empty() || result.last().unwrap() ^ c != 32 {
result.push(c);
} else {
result.pop();
@smarnach
smarnach / consul-iptables.py
Created March 16, 2018 13:56
Setting up netfilter rules to forward traffic targetted at a local port to a Consul service
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Run with
# sudo consul watch -type=service -service=redis ./consul-iptables.py
import json
import subprocess
import sys
def main():
---
# Example sandbox configuration
# for single server community
# installs
- name: Bootstrap instance(s)
hosts: all
gather_facts: no
become: True

A comment on https://nedbatchelder.com/text/names.html

Myth: Python assigns mutable and immutable values differently.

While it is true that Python's assignment semantics are the same for both mutable and immutable types, the results look different for augmented assignments. E.g. the code

a = [1, 2, 3]

b = a

As of: 2015-08-19

This is how to set up a combined devstack/insights virtualbox.

Run these commands on your host computer, in a new "combined-devstack" folder:

mkdir combined-devstack
cd combined-devstack
curl -L https://raw.githubusercontent.com/edx/configuration/master/vagrant/release/analyticstack/Vagrantfile &gt; Vagrantfile
>>> import ctypes
>>> buffer = (ctypes.c_char * 5)(*"abcde")
>>> ctypes.cast(buffer, ctypes.c_char_p)
c_char_p(3073075392)
class A(object):
def __init__(self, i):
self.i = i
def __radd__(self, other):
return self.i
a = [A(42)]
# Test with built-in sum()
print(sum(a))
In [1]: import numpy
In [2]: a = numpy.array([0.5, 1.3, 2.4, 10.3, 10.8, 10.2, 7.6, 3.2, 2.9])
In [3]: numpy.unwrap(2.0 * a) / 2.0
Out[3]:
array([ 0.5 , 1.3 , 2.4 , 0.87522204, 1.37522204,
0.77522204, 1.31681469, 0.05840735, -0.24159265])
import timeit
import numpy
import scipy.ndimage.morphology
def f0(a, kernel):
b = numpy.convolve(a, kernel, mode="same") > 1
b[1:] |= b[:-1]
b[:-1] |= b[1:]
return b