Skip to content

Instantly share code, notes, and snippets.

@Jc2k
Jc2k / virtualenv-js
Last active January 3, 2016 11:09
Thinking about python virtualenvs and node/npm
#! /usr/bin/env python
import os
import tempfile
import shutil
import tarfile
import sys
import subprocess
import optparse
@Jc2k
Jc2k / inet_pton.py
Created March 11, 2014 16:49
inet_pton monkey patch for windows
import socket
if not hasattr(socket, "inet_pton"): # pragma: no cover
import ctypes
WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
class sockaddr(ctypes.Structure):
_fields_ = [
("sa_family", ctypes.c_short),
("__pad1", ctypes.c_ushort),
@Jc2k
Jc2k / find_unpinned.py
Created May 21, 2014 16:09
Quick and dirty script to list unpinned dependencies in a requirements.txt
from pip.req import InstallRequirement, RequirementSet, parse_requirements
from pip.index import PackageFinder
import tempfile
import shutil
build_dir = tempfile.mkdtemp()
src_dir = tempfile.mkdtemp()
download_dir = tempfile.mkdtemp()
@Jc2k
Jc2k / keybase.md
Created July 8, 2014 13:32
I am me

Keybase proof

I hereby claim:

  • I am jc2k on github.
  • I am jc2k (https://keybase.io/jc2k) on keybase.
  • I have a public key whose fingerprint is A262 1F7E 9964 9468 FBE8 1555 EB27 AB01 4FB6 76F4

To claim this, I am signing this object:

@Jc2k
Jc2k / gist:f5dce6d0e460e6295ef7
Created July 19, 2014 10:16
Crappy API invocation to turn a ticket into a pull request (in python)
import requests
import json
issue = 104
branch = "BRANCH_TO_MERGE"
username = "USERNAME"
repo = "REPO"
url = "https://api.github.com/repos/%(username)s/%(repo)s/pulls" % locals()
@Jc2k
Jc2k / debug.py
Created July 19, 2014 10:39
Call logging decorator (probably doesn't work, found it when having a spring clean)
import logger
log = logger.getLogger(__name__)
def log_calls(fn):
def inner(*args, **kwargs):
f = inspect.currentframe()
frame, filename, line, func_name, lines, index = inspect.getouterframes(f)[1]
args = inspect.getargvalues(f)
@Jc2k
Jc2k / journald_stream.py
Created February 20, 2015 23:07
Streaming log lines from journald in python 3
import asyncio
from systemd import journal
class Journal(object):
def __init__(self, unit):
self.journal = journal.Reader()
# self.journal.log_level(journal.LOG_INFO)
self.journal.add_match(_SYSTEMD_UNIT=unit)
@Jc2k
Jc2k / spawner.py
Created August 20, 2015 07:28
Looks like i started trying to make my own docker - Feb 2012
"""
This demo expects the following directory structure:
/bundle/ - empty directory
/library/
/app1/
RANDOM FILES
/app2/
RANDOM FILES
/empty/
@Jc2k
Jc2k / process_query.py
Created August 26, 2015 11:15
A django orm-like PS
# https://raw.githubusercontent.com/pixelb/ps_mem/master/ps_mem.py
# https://people.gnome.org/~federico/misc/memstats.py
# http://brightbox.com/blog/2012/11/28/measuring-shared-ram-usage/
import itertools
import os
import operator
SUPPORTED_SMAPS_BUCKETS = [
'AnonHugePages', 'Anonymous', 'KernelPageSize', 'Locked',
@Jc2k
Jc2k / ggrok.py
Created October 3, 2015 12:22
The start of an ngrok client for python. The goal was to share a django app natively, without even having local sockets to open.
from gevent.monkey import patch_all
patch_all()
import json
import socket
import struct
import ssl
import logging
import uuid