Skip to content

Instantly share code, notes, and snippets.

@tzickel
tzickel / Dockerfile
Last active April 1, 2021 10:33
Running SerenityOS inside a Docker container
FROM archlinux
# Temporary patch for support old docker versions (like the default one in ubunutu 18.04)
RUN patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst && \
curl -LO "https://repo.archlinuxcn.org/x86_64/$patched_glibc" && \
bsdtar -C / -xvf "$patched_glibc"
RUN pacman -Syyu --noconfirm && pacman-db-upgrade && pacman -S --noconfirm --needed base-devel cmake curl mpfr libmpc gmp e2fsprogs ninja qemu qemu-arch-extra git pulseaudio-alsa
RUN git clone https://github.com/bestouff/genext2fs
@tzickel
tzickel / redis_server.py
Created November 15, 2018 21:52
Start a redis server in the background on a free tcp port
import subprocess
import random
import os
class RedisServer(object):
def __init__(self, dockerimage=None):
while True:
self._proc = None
self._port = random.randint(1025, 65535)
@tzickel
tzickel / dockerignore.py
Created October 17, 2018 06:10
A simple docker build extension that works with .gitignore file directives and you can specify both Dockerfile and multiple .gitignore paths
# Version 0.0.1 (works with python2.7 and python3)
# Does not work with non-local context (i.e. git, remote archives)
# You need the pathspec package installed (pip install pathspec)
# Pass any docker build arguments you want to use after -- argument (i.e., dockerignore.py . -- -t blah)
# This works with .gitignore syntax, not .dockerignore ( https://git-scm.com/docs/gitignore#_pattern_format )
import tarfile
import subprocess
import argparse
import os
import sys
@tzickel
tzickel / apply_log.py
Created September 22, 2018 09:27
If you want to insert file name, line number and function name to logging functions (this script needs redbaron installed)
import redbaron
import re
logfunctions = ['info', 'warning', 'error', 'critical', 'exception']
#If you dont use the logger.info('text',...) format, change this code
def should_handle(node):
parent = node.parent
@tzickel
tzickel / import_io_check.sh
Created July 29, 2018 04:56
A shell script that uses a recent strace to check for python 2 I/O error checking bug
#!/usr/bin/env bash
# You can replace the python version to check
PYTHON=${PYTHON:-`which python`}
TMPFILE=tmp.py
[ -x "`which strace`" ] || { echo strace not found; exit 1; }
[ -x "${PYTHON}" ] || { echo python not found; exit 1; }
set -e
@tzickel
tzickel / multipartStreamDecoderBenchmark.py
Last active June 21, 2018 09:50
This is a benchmark that compares something you might want to do with a multipart result that is large.
# Benchmark for https://github.com/requests/toolbelt/pull/222
from requests_toolbelt import MultipartStreamDecoder, MultipartDecoder
def generate_data(bonudary, length, chunk_size):
yield b'\r\n--%s\r\n' % bonudary
yield b'Content-Disposition: form-data; name="metadata"; filename="metadata"\r\n'
yield b'Content-Type: text/plain\r\n'
yield b'\r\n'
yield str(length).encode('utf-8')
@tzickel
tzickel / patch_const.py
Created January 29, 2018 18:20
A simple example on how to patch a constant in a python 2 function
import new
class Empty(object):
pass
def patch_const(func, const_index, new_value, previous_value=Empty):
co = func.func_code
consts = list(co.co_consts)
@tzickel
tzickel / grabber.py
Last active November 24, 2021 20:16
A faster numpy ImageGrab with no dependencies
# A port of https://github.com/phoboslab/jsmpeg-vnc/blob/master/source/grabber.c to python
# License information (GPLv3) is here https://github.com/phoboslab/jsmpeg-vnc/blob/master/README.md
from ctypes import Structure, c_int, POINTER, WINFUNCTYPE, windll, WinError, sizeof
from ctypes.wintypes import BOOL, HWND, RECT, HDC, HBITMAP, HGDIOBJ, DWORD, LONG, WORD, UINT, LPVOID
import numpy as np
SRCCOPY = 0x00CC0020
DIB_RGB_COLORS = 0
BI_RGB = 0
@tzickel
tzickel / cythoncheck.py
Created December 12, 2016 21:23
A simple script to check python projects for bugs via cython's static analysis...
from __future__ import print_function
import sys
import os
import subprocess
import shutil
import tempfile
import time
import hashlib
import argparse
try:
@tzickel
tzickel / kodistandby.py
Created October 12, 2016 17:37
A simple python script to run Kodi only when someone has tried to connect to the webserver port.
from __future__ import print_function
import socket
import subprocess
import time
import sys
address = '0.0.0.0'
port = 8000
kodi_path = r'C:\Program Files (x86)\Kodi\Kodi.exe'