Skip to content

Instantly share code, notes, and snippets.

@nguyent
nguyent / extendedmock.py
Last active October 6, 2022 16:11
Extended Mock class which adds a handy `call_dict_contains` method to mocks
import inspect
from functools import cached_property
from typing import AbstractSet, Any, Dict
from mock import MagicMock
class ExtendedMock(MagicMock):
"""
ExtendedMock adds two useful helper methods for testing:
@nguyent
nguyent / Git Subtree basics.md
Created July 14, 2020 15:59 — forked from SKempin/Git Subtree basics.md
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@nguyent
nguyent / fml.sh
Last active July 14, 2018 02:55
bashing with spaces
export server=test
export file="name with spaces"
export cmd="scp -r"
# I want:
# scp -r test:"name with spaces"
$cmd $server:\"$file\" .
# what I see with set -x:
# scp -r 'whatbox:"name' with 'spaces"' .
@nguyent
nguyent / gist:a8dbb6012f0b5c1bb139bbb10cbf939e
Last active June 9, 2018 13:38
recursive directory listing piped into fzf for scp
remotecp()
{
server=myserver
remote_directory=filedirectory
# get full file names, slashes, and put everything in quotes (for strings with spaces yo)
filename=$(ssh $server "tree ${remote_directory} -afFiQ --prune | head -n -2" | fzf)
cmd=(scp)
# recursive copy for bash
if [ "${filename: -1}" = / ]; then
# get all the logs for a service via systemctl since today
`journalctl -u <SERVICE> --since today`
https://configure.ergodox-ez.com/keyboard_layouts/qynlrd/edit
$ ./teensy_loader_cli -w --mcu=atmega32u4 *.hex
# reset
@nguyent
nguyent / notes.bash
Created February 6, 2017 16:48
notes
# cartesian product via https://www.quora.com/What-is-the-most-succinct-way-to-compute-a-Cartesian-product-in-bash
join -j 2 f1 f2

But you see, I have, let's say, sixty years to live. Most of that time will be spent working. I've chosen the work I want to do. If I find no joy in it, then I'm only condemning myself to sixty years of torture. And I can find the joy only if I do my work in the best way possible to me. But the best is a matter of standards—and I set my own standards. I inherit nothing. I stand at the end of no tradition. I may, perhaps, stand at the beginning of one.

...

Listen to what is being preached today. Look at everyone around us. You’ve wondered why they suffer, why they seek happiness and never find it. If any man stopped and asked himself whether he’s ever held a truly personal desire, he’d find the answer. He’d see that all his wishes, his efforts, his dreams, his ambitions are motivated by other men. He’s not really struggling even for material wealth, but for the second-hander’s delusion – prestige. A stamp of approval, not his own. He can find no joy in the struggle and no joy when he has succeeded. He ca

@nguyent
nguyent / ranges.py
Created September 27, 2016 22:39
given a list of dates, create a list of lists containing contiguous ranges Raw
from datetime import timedelta
from datetime import datetime
def toDate(s):
return datetime.strptime(s, '%Y-%m-%d')
def consecutive(d1, d2):
return toDate(d1) + timedelta(days=1) == toDate(d2)
def findRangesRecursive(dates, acc=[], candidate=[]):
## Attempting to use puppet to install logstash with java already installed
fpm -s empty -t rpm --depends jre -n zc-jre-1.7.0 --provides 'jre = 1.7.0' --provides 'jdk = 1.7.0'
=> zc-jre-1.0-1.x86_64.rpm
# logstash rpm via: https://download.elasticsearch.org/logstash/logstash/packages/centos/logstash-1.4.2-1_2c0f5a1.noarch.rpm
[vagrant@logstash tmp]$ rpm -qp --requires logstash-1.4.2-1_2c0f5a1.noarch.rpm
jre >= 1.6.0