Skip to content

Instantly share code, notes, and snippets.

putting out fires

Ilya Konstantinov ikonst

  • San Francisco, CA
View GitHub Profile
View mock_instance_method.py
class Foo():
message = 'foo'
def bar(self):
print('bar')
from unittest.mock import patch
def baz(self):
print(self.message)
View pynamodb_test_date.py
from datetime import datetime
import pytz
import dateutil.tz
from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute, UTCDateTimeAttribute
class MyModel(Model):
class Meta:
table_name = 'my_model'
View PhpArrayModernCodec.php
<?php
use DateTime;
use DrSlump\Protobuf;
use google\protobuf\Timestamp;
class PhpArrayModernCodec extends \DrSlump\Protobuf\Codec\PhpArray {
protected function encodeMessage(Protobuf\Message $message)
{
if ($message instanceof Timestamp) {
View abort_on_eof.py
from contextlib import contextmanager
from functools import wraps
from socket import socket as socket_type, MSG_PEEK
from typing import Set
import flask
import gevent
def _abort_on_eof_watchdog(socket: socket_type, greenlets: Set[gevent.Greenlet]) -> bool:
@ikonst
ikonst / abort_request_on_socket_shutdown.py
Last active Dec 31, 2017
Example of a gevent-based Flask server that aborts requests on socket shutdown
View abort_request_on_socket_shutdown.py
from gevent import monkey
monkey.patch_all()
import gevent
from flask import Flask
from gevent.wsgi import WSGIServer
app = Flask(__name__)
@ikonst
ikonst / mongoengine_allow_inheritance_be_careful.py
Created Dec 19, 2017
One doesn't just add "allow_inheritance=True"
View mongoengine_allow_inheritance_be_careful.py
from mongoengine import Document, StringField, ListField, EmbeddedDocument, EmbeddedDocumentField
# ******** before remodel: **********
class FailedChargeAttempt_Old(EmbeddedDocument):
id = StringField()
failed_reason = StringField()
View get_org_contribs.py
from github import Github
from csv import DictWriter
# Generate on https://github.com/settings/tokens
TOKEN = '<REDACTED>'
ORG = 'lyft'
AUTHOR = '<github username here>'
g = Github(login_or_token=TOKEN)
org = g.get_organization(ORG)
View mongoengine_referencing_documents.py
from mongoengine import Document, EmbeddedDocument, Q, ReferenceField
from pymongo.read_preferences import ReadPreference
all_models = Document.__subclasses__()
def referencing_models(document):
for model in all_models:
if issubclass(model, EmbeddedDocument):
continue
fields = [field for field in get_reference_fields_of_model(model)
View mov2gif.sh
#!/bin/sh
set -e
# Converts a Quicktime movie to a GIF aniamtion.
# Useful for screen recordings.
# Preliminary step with palette required to make it look good
# without dithering artifacts.
FPS=10
PALETTE=$(mktemp).png
@ikonst
ikonst / private.xml
Created Mar 18, 2016
Microsoft L5V-00001 Sculpt Ergonomic Desktop Keyboard and Mouse — private.xml for Karabiner
View private.xml
<?xml version="1.0"?>
<root>
<!--
Based on:
https://blog.yorkxin.org/posts/2014/04/12/microsoft-sculpt-mobile-mouse-and-mac/
Button 4 is the side button (located by the blue Windows button).
This allows you to map the Windows button as Button 5.
1. brew cask install karabiner
You can’t perform that action at this time.