Skip to content

Instantly share code, notes, and snippets.

View drdaeman's full-sized avatar
😺
I love cats

Aleksei Zhukov drdaeman

😺
I love cats
View GitHub Profile
@drdaeman
drdaeman / exec_notify.py
Created December 17, 2011 00:03
Listening to Netlink process events on x86_64 Linux systems (kludgy)
#!/usr/bin/env python
import socket
import os
import struct
if getattr(socket, "NETLINK_CONNECTOR", None) is None:
socket.NETLINK_CONNECTOR = 11
CN_IDX_PROC = 1
@drdaeman
drdaeman / rkt-fly-on-wsl.md
Last active January 19, 2022 10:28
Running Docker containers on Windows, natively, using rkt (WSL aka Bash on Windows)

Just a heads up for those who are looking into running Docker containers natively on WSL. While it's not usable for anything serious (even your toy project development), there is a way.

Nuances:

  • We'll be using rkt and not Docker. So, no docker-compose for you.
  • There will be some source code patching. Nothing serious, just a few lines.
  • Very limited isolation and networking capabilities. Think of always --privileged, --net-host and no DNS.

WSL doesn't have cgroups at the moment, and probably won't have them anytime soon, so no way Docker would work.

@drdaeman
drdaeman / osm_to_json.py
Created November 27, 2012 13:12
Extract all buildings from planet.osm and represent them as JSON dictionary of polygons
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The code is dirty.
from __future__ import print_function, unicode_literals
import xml.sax
class OSMHandler(xml.sax.ContentHandler):
def __init__(self):
self.osm_nodes = {}
@drdaeman
drdaeman / test_node_crypto.coffee
Created July 13, 2011 03:51
node.js crypto is broken
#!/usr/bin/env coffee
crypto = require "crypto"
#
# Rijndael128 test vector, ecb_tbl.txt, KEYSIZE=128, "ecb-tbl-128: I=1"
# - plaintext = 506812a45f08c889b97f5980038b8359
# - ciphertext = d8f532538289ef7d06b506a4fd5be9c9
# - key = 00010203050607080a0b0c0d0f101112
#
{ config, pkgs, ... }:
{
# Kubernetes configuration
# Insecure, for local development only, totally unsuitable for production
services.kubernetes = {
roles = ["master" "node"];
# Without explicitly defined keys things will break after reboot,
# as by default keys will be generated in /var/run/kubernetes.
@drdaeman
drdaeman / Dockerfile
Created January 9, 2018 16:06
Dockerfile to build oklog/oklog
FROM node:9 AS build-ui
RUN npm install -g elm --unsafe-perm=true --allow-root
COPY ./ui /app/ui
RUN cd /app/ui \
&& ([ ! -e elm-stuff ] || rm -rf elm-stuff) \
&& elm-make --yes src/Main.elm --output=scripts/oklog.js
# ============================================================================
@drdaeman
drdaeman / utils.py
Created May 10, 2017 15:40
Helpers for django-elasticsearch-dsl
import collections
import itertools
def get_result_models_lazy(results):
"""
Given a ``Response`` instance or any iterable with documents,
provides an iterable (a generator, to be exact) with matching
database model instances.
@drdaeman
drdaeman / rcompare.js
Last active January 8, 2017 22:50
RethinkDB-resembling type-aware value comparison (experiment)
const _ = require("lodash");
function inferTypeOf(value) {
// Given a value from RethinkDB, tries to infer its ReQL type.
// Returns a string value, similar to r.typeOf result, or an empty
// string if the type is not recognized or unsupported.
switch (typeof value) {
case "string":
return "STRING";
case "number":
@drdaeman
drdaeman / fields.py
Last active May 12, 2016 20:34
Experiment with django-money to have multiple money fields that share the single currency. May contain bugs, use with extreme caution.
from __future__ import absolute_import, unicode_literals
from djmoney.models.fields import MoneyField, MoneyFieldProxy
class CurrencyLockedMoneyFieldProxy(MoneyFieldProxy):
def __init__(self, field, currency_field_name=None):
super(CurrencyLockedMoneyFieldProxy, self).__init__(field)
if currency_field_name is not None:
self.currency_field_name = currency_field_name

Keybase proof

I hereby claim:

  • I am drdaeman on github.
  • I am drdaeman (https://keybase.io/drdaeman) on keybase.
  • I have a public key whose fingerprint is FE74 8B15 6F78 F2B3 360E 9C85 E1C3 A285 7EFC 7C66

To claim this, I am signing this object: