Skip to content

Instantly share code, notes, and snippets.

View tyhoff's full-sized avatar

Tyler Hoffman tyhoff

View GitHub Profile
@tyhoff
tyhoff / test_kv_store_protocol_handlers.cpp
Last active May 11, 2020 17:21
Should have used a proper mock
// This is an example unit test for a function `kv_store_write_protocol_cmd`
//
// The purpose is to show that `kv_store_write` should have been implemented
// as a mock using a mocking framework, rather than a roll-your-own mock.
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
extern "C" {
#include <string.h>
@tyhoff
tyhoff / .lldbinit
Last active February 2, 2021 04:08
.lldbinit modifications for using a Virtual/Conda environment with LLDB Python scripts
# Source the python path fix
command script import ~/lldbinit.py
@tyhoff
tyhoff / progress_bar_requests_upload.py
Last active April 14, 2024 22:39
Python requests HTTP PUT with tqdm progress bar
from tqdm import tqdm
from tqdm.utils import CallbackIOWrapper
file_path = os.path.abspath(__file__)
upload_url = https://some-bucket.s3.amazonaws.com
file_size = os.stat(file_path).st_size
with open(file_path, "rb") as f:
with tqdm(total=file_size, unit="B", unit_scale=True, unit_divisor=1024) as t:
wrapped_file = CallbackIOWrapper(t.update, f, "read")
@tyhoff
tyhoff / .gdbinit
Last active February 10, 2021 21:20
.gdbinit modifications for using a Virtual/Conda environment with GDB Python scripts
# All of your normal .gdbinit commands, functions, and setup tasks
# Update GDB's Python paths with the `sys.path` values of the local Python installation,
# whether that is brew'ed Python, a virtualenv, or another system python.
# Convert GDB to interpret in Python
python
import os,subprocess,sys
# Execute a Python using the user's shell and pull out the sys.path (for site-packages)
paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"',shell=True).decode("utf-8").split()
@tyhoff
tyhoff / how_to_localize.md
Last active August 29, 2015 13:57
How to localize Waterbear

Localizing Waterbear

Background

The bottom file is the default file for /languages/javascript/sound.json. The top one, sound (localized).json, has been stripped of unimportant fields and what remains are the strings related to localizing.

NOTE: When localizing files, they should be the same name as the default file. e.g. sound.json, not sound_localized.json

The fields related to localizing are:

@tyhoff
tyhoff / extract
Created December 6, 2013 13:39
Extract .bashrc function
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;