Skip to content

Instantly share code, notes, and snippets.

@leth
leth / .bash_profile
Created June 15, 2020 09:52
Create new git repos with a 'main' branch rather than 'master'
# Add this to your .bash_profile
function git_init_fnc () {
\git "$@"
if [[ $1 == "init" ]];then
if [[ -n "$2" ]]; then
git_dir="$2";
else
git_dir=`pwd`;
fi
@leth
leth / Dockerfile
Created April 24, 2017 15:09
sony-pm-alt sync setup
FROM python:2-alpine
RUN apk add --no-cache gphoto2
RUN pip install --no-cache requests
RUN mkdir /root/.gphoto
ADD gphoto-settings /root/.gphoto/settings
ADD sony-pm-alt/sony-pm-alt.py /sony-pm-alt.py
VOLUME /var/lib/Sony
CMD exec python /sony-pm-alt.py
@leth
leth / streaming-tar.py
Last active August 12, 2016 14:24 — forked from chipx86/streaming-tar.py
Sample code to build a tar chunk-by-chunk and stream it out all at once.
#!/usr/bin/env python
#
# Building a tar file chunk-by-chunk.
#
# This is a quick bit of sample code for streaming data to a tar file,
# building it piece-by-piece. The tarfile is built on-the-fly and streamed
# back out. This is useful for web applications that need to dynamically
# build a tar file without swamping the server.
from io import BytesIO
from os import walk
import os
import pickle
import operator
from snimpy import mib, manager
from snimpy.smi import smi, ffi
_cache_file = '/tmp/smi_mib_cache'
class LazyLoad(object):
import weakref
import threading
from twisted.python.threadpool import ThreadPool
from crochet import EventualResult
_blocked_pool_threads = weakref.WeakKeyDictionary()
_orig_pool_limits = weakref.WeakKeyDictionary()
_originals = {}
@leth
leth / bench.py
Created August 9, 2014 22:42
_clean_data benchmarking
import os
import re
import StringIO
import cStringIO
import contextlib
# caching the compilation of the regex used
# to check for lookup calls within data
LOOKUP_REGEX=re.compile(r'lookup\s*\(')
@leth
leth / changes
Created August 8, 2014 15:40
ansible jinja2 escaping speedup
diff --git c/lib/ansible/utils/__init__.py i/lib/ansible/utils/__init__.py
index 5da39ac..696f1a7 100644
--- c/lib/ansible/utils/__init__.py
+++ i/lib/ansible/utils/__init__.py
@@ -33,7 +33,7 @@ from ansible.module_utils.splitter import split_args, unquote
import ansible.constants as C
import ast
import time
-import StringIO
+import cStringIO
@leth
leth / main.go
Created April 8, 2014 19:32
Example Mac OSX SDL app (avoids NSInternalInconsistencyException)
package main
/*
#import <dlfcn.h>
int
PreInit() {
void* cocoa_lib;
cocoa_lib = dlopen( "/System/Library/Frameworks/Cocoa.framework/Cocoa", RTLD_LAZY );
@leth
leth / gist:9291261
Last active August 29, 2015 13:56 — forked from sloria/gist:5895687
f = open('file.txt', 'w')
f.write('hi')
f.close()
# Better
with open('file.txt', 'w') as f:
f.write('hi')
with pytest.raises(ValueError):
int('hi')
@leth
leth / libpython.py
Last active April 10, 2022 06:13
Working python frames in gdb for production python interpreters
#!/usr/bin/python
'''
From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
to be extended with Python code e.g. for library-specific data visualizations,
such as for the C++ STL types. Documentation on this API can be seen at:
http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html
This python module deals with the case when the process being debugged (the
"inferior process" in gdb parlance) is itself python, or more specifically,