Skip to content

Instantly share code, notes, and snippets.

View chekunkov's full-sized avatar

Alex chekunkov

  • Mountain View, California
View GitHub Profile
@chekunkov
chekunkov / recover_source_code.md
Created March 15, 2017 09:28 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@chekunkov
chekunkov / pythonstartup.py
Last active January 19, 2017 00:25
PYTHONSTARTUP file example with custom displayhook
#!/usr/bin/env python
import sys
import pprint
def displayhook_pprint(o):
"""Display hook powered by pprint.
https://www.python.org/dev/peps/pep-0217/
@chekunkov
chekunkov / s3_gz.py
Last active April 20, 2022 12:55
Stream gzip file from s3
import zlib
import boto
def decompress(key):
d = zlib.decompressobj(16 + zlib.MAX_WBITS)
for chunk in key:
yield d.decompress(chunk)
yield d.flush()
@chekunkov
chekunkov / Numpy integer overflow.ipynb
Created August 1, 2015 15:03
Numpy array integer overflow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chekunkov
chekunkov / export_csv.py
Created May 24, 2015 07:48
Anki export to CSV add-on
# -*- coding: utf-8 -*-
"""Anki add-on which adds "Notes in CSV format" option of Export desc dialog.
Copyright (c) 2015 Alex Chekunkov
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
@chekunkov
chekunkov / card.css
Last active August 29, 2015 14:21
Anki card template
.card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
.synonyms {
font-size: 14px;
@chekunkov
chekunkov / rlock.py
Last active January 25, 2021 06:27
File based reentrant lock
# -*- coding: utf-8 -*-
"""Reentrant lock based on lock file.
Copyright (c) 2015 Alexander Chekunkov
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
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y python python-dev python-pip git \
libffi-dev libxml2-dev libxslt1-dev zlib1g-dev libssl-dev
RUN mkdir -p /var/log/supervisord /project
from optparse import OptionParser
import os
import sys
import csv
import hashlib
# workaround for error:
# Field larger than field limit
csv.field_size_limit(sys.maxsize)
import re
def camelcase_to_lowercase_with_underscores(name):
"""
>>> camelcase_to_lowercase_with_underscores('CamelCase')
'camel_case'
>>> camelcase_to_lowercase_with_underscores('CamelCamelCase')
'camel_camel_case'
>>> camelcase_to_lowercase_with_underscores('Camel2Camel2Case')