Skip to content

Instantly share code, notes, and snippets.

@SlamJam
SlamJam / test_zmq.py
Created March 10, 2016 14:59
ZMQ REQ-REP poll example
import sys
import time
import zmq
context = zmq.Context()
def run_service(addr):
socket = context.socket(zmq.REP)
socket.bind(addr)
@SlamJam
SlamJam / ioc.py
Last active June 30, 2017 13:55 — forked from mlashcorp/python IOC
python IOC
######################################################################
##
## Feature Broker
##
######################################################################
class FeatureBroker:
def __init__(self, allowReplace=False):
self.providers = {}
self.allowReplace = allowReplace
@SlamJam
SlamJam / LICENSE
Created July 17, 2017 23:58 — forked from justjkk/LICENSE
Parsing JSON with lex and yacc
The MIT License (MIT)
Copyright (c) 2015 J Kishore Kumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@SlamJam
SlamJam / latency.txt
Created July 30, 2017 11:11 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@SlamJam
SlamJam / gist:e1f70ad79f5956a8ab0afbd9104155b7
Created October 5, 2017 00:53 — forked from datagrok/gist:2199506
Virtualenv's `bin/activate` is Doing It Wrong

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

@SlamJam
SlamJam / hash_ring.py
Created November 2, 2017 00:17 — forked from reorx/hash_ring.py
Consistent hash implementation in Python.
# -*- coding: utf-8 -*-
"""
hash_ring
~~~~~~~~~~~~~~
Implements consistent hashing that can be used when
the number of server nodes can increase or decrease (like in memcached).
Consistent hashing is a scheme that provides a hash table functionality
in a way that the adding or removing of one slot
does not significantly change the mapping of keys to slots.
@SlamJam
SlamJam / defaults.py
Created June 15, 2018 00:32 — forked from dutc/defaults.py
PEP 563 -- Postponed Evaluation of Annotations (https://www.python.org/dev/peps/pep-0563/)
from __future__ import annotations
from inspect import signature
from functools import wraps
from collections import namedtuple
opt = namedtuple('Optional', '')()
def better_defaults(f):
sig = signature(f)
@wraps(f)
def func(*args, **kwargs):
@SlamJam
SlamJam / checklist.md
Created July 20, 2018 18:57 — forked from askd/checklist.md
Чеклист спикера

Общее

  1. Представься: краткая информация о себе – имя, место работы, чем занимаешься, можно фото для тех, кто будет смотреть слайды отдельно
  2. План доклада: несколько пунктов (лучше не более 5) о чём будет доклад. Это могут быть главы доклада (кстати, составление плана может помочь грамотнее структурировать доклад ещё при создании)
  3. Зачем: кратко рассказать, чем то, о чем рассказываешь в докладе, может быть полезно остальным – и разработчикам, и руководителям, и клиентам (можно акцентироваться на аудитории конкретной конфы – например если там есть дизайнеры, бэкенды, то упомянуть, что они могут узнать из доклада)
  4. Итоги: в конце доклада ещё раз пройтись по плану и подвести итог по каждому пункту – что узнали, чему научились
  5. Контакты: как слушатель и тот кто смотрит слайды может связаться и задать вопрос

Оформление

@SlamJam
SlamJam / ctype_async_raise.py
Created July 29, 2018 00:33 — forked from liuw/ctype_async_raise.py
Nasty hack to raise exception for other threads
#!/usr/bin/env python
# liuw
# Nasty hack to raise exception for other threads
import ctypes # Calm down, this has become standard library since 2.5
import threading
import time
NULL = 0
import itertools
a = 'a'
b = 'b'
c = 'c'
participant = [a,b,c]
payments = {