Skip to content

Instantly share code, notes, and snippets.

@msabramo
msabramo / install-tmux.sh
Last active December 11, 2023 21:46
Install tmux in a barebones Ubuntu environment without root (like a Docker container for Ethos)
#!/bin/sh
TMUX_ROOT=~/tmux
# Install tmux in a barebones Ubuntu environment without root (like a Docker
# container for Ethos)
apt-get download tmux libutempter0 libevent-core-2.1-7 ncurses-base
for deb in *.deb; do
dpkg -x ${deb} ${TMUX_ROOT}
@msabramo
msabramo / mock_patch_multiple_targets.py
Created September 11, 2015 19:42
Mock patch multiple targets in Python
@contextlib.contextmanager
def multiple_targets(mock_patches):
"""
`mock_patches` is a list (or iterable) of mock.patch objects
Example usage:
with mock.patch.multiple_targets([
mock.patch('os.path.exists', side_effect=mock_path_exists),
mock.patch('subprocess.Popen'),
@msabramo
msabramo / fakesocket.py
Last active August 25, 2023 19:16
A `FakeSocket` Python class that implements the `recv` method
from dataclasses import dataclass
from typing import Optional
@dataclass
class FakeSocket:
chunks: list[bytes] = None
buf: bytes = None
max_chunk_size: Optional[int] = None
log_func: Optional[callable] = None
@msabramo
msabramo / build_mac.sh
Last active May 18, 2023 17:59 — forked from SchizoDuckie/build_mac.sh
Build an OSX .pkg installer from Linux using mkbom and xar
#!/bin/bash
# change the values below to match your system.
# target the BUILD_DIR to output from an nw.io build process. nwjs-shell-builder recommended!
# https://github.com/Gisto/nwjs-shell-builder
# BASE_DIR is the target directory for this script, where files will be gathered and packaged to
BUILD_DIR="/var/www/deploy/TMP/osx-ia32/latest-git"
BASE_DIR="/var/www/deploy/osx" 
@msabramo
msabramo / git_prompt_info.zsh
Created April 11, 2012 00:07
The slowness of my zsh prompt when in a git-svn managed directory was killing me. I improved it by removing the git status stuff that slows it down...
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
@msabramo
msabramo / githash.py
Created January 3, 2011 07:09
Python code to generate git SHA-1 hashes
#!/usr/bin/env python
from sys import argv
from hashlib import sha1
from cStringIO import StringIO
class githash(object):
def __init__(self):
self.buf = StringIO()
@msabramo
msabramo / pymssql_gevent_test.py
Created October 3, 2013 05:59
Illustrates performance of pymssql for slow queries using 2 kinds of gevent wait callbacks
import datetime
import gevent
import gevent.socket
import os
import pymssql
#import random
server = os.getenv("PYMSSQL_TEST_SERVER")
user = os.getenv("PYMSSQL_TEST_USERNAME")
password = os.getenv("PYMSSQL_TEST_PASSWORD")
@msabramo
msabramo / multiple_mocks.py
Created September 11, 2015 16:12
A Python context manager for doing multiple mock.patches
@contextlib.contextmanager
def multiple_mocks(mock_specs):
"""
`mock_specs` is a dict of mock target name => mock patch kwargs
Example usage:
with multiple_mocks(
{'os.path.exists': {'side_effect': mock_path_exists},
'subprocess.Popen': {},
@msabramo
msabramo / buildout.cfg
Created April 29, 2011 06:39
A zc.buildout that compiles and installs varnish and supervisor
[buildout]
parts = pcre varnish-build varnish supervisor
origin_port = 8080
varnish_port = 8000
supervisor_port = 9002
[pcre]
recipe = hexagonit.recipe.cmmi
url = http://downloads.sourceforge.net/project/pcre/pcre/8.12/pcre-8.12.tar.gz
@msabramo
msabramo / Alfred.app Append to nvALT Daily notes.applescript
Created September 18, 2012 20:25
Alfred.app Append to nvALT Daily notes
on alfred_script(q)
set theYear to year of (current date) as string
set theMonth to (month of (current date) as number)
if theMonth < 10 then
set theMonth to "0" & theMonth
else
set theMonth to "" & theMonth
end if