Skip to content

Instantly share code, notes, and snippets.

@carsonip
carsonip / plot_video_brightness.py
Created February 7, 2021 22:28
Script to plot video frame brightness vs time
import cv2
import matplotlib.pyplot as plt
import pandas as pd
VIDEO_NAME = 'led960_3.mp4'
cap = cv2.VideoCapture(VIDEO_NAME)
assert cap.isOpened()
FPS = 960
@carsonip
carsonip / python.md
Created November 22, 2019 06:04
Useful Python Snippets
@carsonip
carsonip / ovpn_mfa_setup.sh
Last active October 11, 2019 06:59
OpenVPN Client Configuration Generate Script
#!/bin/bash
# https://gist.github.com/egonbraun/7176976fe05ece092410462facf0adb6
# OpenVPN configuration Directory
OPENVPN_CFG_DIR=/etc/openvpn
# Where this script should create the OpenVPN client config files
OUTPUT_DIR=~/ovpn-mfa/
We can't make this file beautiful and searchable because it's too large.
geoname_id,locale_code,continent_code,continent_name,country_iso_code,country_name,subdivision_1_iso_code,subdivision_1_name,subdivision_2_iso_code,subdivision_2_name,city_name,metro_code,time_zone,is_in_european_union
49518,en,AF,Africa,RW,Rwanda,,,,,,,Africa/Kigali,0
49747,en,AF,Africa,SO,Somalia,BK,Bakool,,,Oddur,,Africa/Mogadishu,0
51537,en,AF,Africa,SO,Somalia,,,,,,,Africa/Mogadishu,0
53654,en,AF,Africa,SO,Somalia,BN,Banaadir,,,Mogadishu,,Africa/Mogadishu,0
54225,en,AF,Africa,SO,Somalia,SH,"Lower Shabeelle",,,Merca,,Africa/Mogadishu,0
56335,en,AF,Africa,SO,Somalia,SD,"Middle Shabele",,,Giohar,,Africa/Mogadishu,0
57289,en,AF,Africa,SO,Somalia,WO,"Woqooyi Galbeed",,,Hargeisa,,Africa/Mogadishu,0
58994,en,AF,Africa,SO,Somalia,GE,Gedo,,,Garbahaarrey,,Africa/Mogadishu,0
59611,en,AF,Africa,SO,Somalia,MU,Mudug,,,Gaalkacyo,,Africa/Mogadishu,0
@carsonip
carsonip / mysql-variables.txt
Last active June 25, 2019 02:39
MySQL variables mysql-5-6-too-much-write-after-enabling-compression
# https://dba.stackexchange.com/questions/240459/mysql-5-6-too-much-write-after-enabling-compression
mysql> show variables;
+--------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Var
@carsonip
carsonip / time33.py
Created April 15, 2019 09:04 — forked from zed/time33.py
time.process_time() and time.perf_counter() for Python 2 on Ubuntu.
"""time.process_time() and time.perf_counter() for Python 2 on Ubuntu."""
import ctypes
import errno
from ctypes.util import find_library
from functools import partial
CLOCK_PROCESS_CPUTIME_ID = 2 # time.h
CLOCK_MONOTONIC_RAW = 4
clockid_t = ctypes.c_int
@carsonip
carsonip / python-hiredis-benchmark.txt
Created April 5, 2019 14:20
Python hiredis benchmark
Using a slightly modified version of https://github.com/popravich/python-redis-benchmark to disable async tests and support Python 2.
*** CPython 2.7
------------------------------------------------------------------------------------------------------------- benchmark 'bulk-string': 36 tests -------------------------------------------------------------------------------------------------------------
Name (time in ns) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
benchmark_parser_bulk_string[---10-hiredis-bytes] 425.7475 (1.0) 1,924.3785 (1.03)
@carsonip
carsonip / hang.log
Created March 14, 2019 08:50
Debugging output of ProxySQL hang issue #1939
2019-03-14 08:30:31 MySQL_Thread.cpp:2874:run(): [ERROR] 0x7fb2a4e0d000: epoll got event, unreg, move to resume 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:3045:run(): [ERROR] 0x7fb2a4e0d000: add to thr exchange resume 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:2732:run(): [ERROR] 0x7fb2a480d000: poll get from myexchange resume, reg 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:2855:run(): [ERROR] 0x7fb2a480d000: set sess to_process=0 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:2951:run(): [ERROR] 0x7fb2a480d000: checking mypoll DS 0x7fb29bdffc00 fd 2367 events 1 revents 1 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:3146:process_data_on_data_stream(): [ERROR] 0x7fb2a480d000: handling revent 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:3167:process_data_on_data_stream(): [ERROR] 0x7fb2a480d000: finish handling revent 0x7fb2974d1c80
2019-03-14 08:30:31 MySQL_Thread.cpp:3225:process_all_sessions(): [ERROR] 0x7fb2a480d000: processing 0x7fb2974d1c80
2019-03-14 08:30:3
@carsonip
carsonip / bash.md
Last active November 1, 2019 02:43
Bash magic

Argument

echo $1 $2  # argument by position
echo $@  # all arguments

Default

echo ${x:-default value}  # equiv to python: "x or 'default value'"
@carsonip
carsonip / python.md
Created February 25, 2019 04:28
Handy Python snippets