Skip to content

Instantly share code, notes, and snippets.

View CD3's full-sized avatar

C.D. Clark III CD3

View GitHub Profile
@CD3
CD3 / terminal-here.sh
Created July 16, 2017 22:00
Small script that will open a new terminal in the working directory of the currently focused terminal. Useful with i3.
#! /bin/bash
ID=$(xprop -root | gawk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')
PID=$(xprop -id $ID | gawk '/_NET_WM_PID\(CARDINAL\)/{print $NF}')
SH=$(basename $SHELL)
ZPID=$(pstree -lpA $PID | sed -n "/$SH/ s/.*$SH(\([0-9]\+\)).*/\1/p")
if [[ -n $ZPID ]]
then
CWD=$(readlink /proc/$ZPID/cwd)
@CD3
CD3 / Approx.py
Created January 18, 2018 16:37
An Approx class for unit testing float values similar to Catch2 (https://github.com/catchorg/Catch2/blob/master/docs/assertions.md#floating-point-comparisons)
class Approx(object):
def __init__(self,val):
self._val = val
self._epsilon = 0.01
def epsilon(self,epsilon):
self._epsilon = epsilon
return self
def __eq__(self,other):
return abs(other - self._val) <= self._epsilon*abs(other + self._val)/2