Skip to content

Instantly share code, notes, and snippets.

@stephenmm
stephenmm / base_utils.tcl
Created January 20, 2020 23:40
Some basic utilities to .tcl a bit more bearable
proc xdbg { } { puts $::errorInfo }; # This must be the first proc and be as simple as possible so we are always able to debug
# Define required globals
set ::xhelpMsgs [dict create]
set ::xVerbosity INFO
# Define the verbosity levels (based on python logging levels: https://verboselogs.readthedocs.io/en/latest/readme.html )
set ::verbosityLevel [dict create]
dict append ::verbosityLevel NOTSET 0 ;# When a logger is created, the level is set to NOTSET (note that the root logger is created with level WARNING). This level isn?t intended to be used explicitly, however when a logger has its level set to NOTSET its effective level will be inherited from the parent logger.
dict append ::verbosityLevel DEVDBG 5 ;# Way too verbose for regular debugging, but nice to have when someone is getting desperate in a late night debugging session and decides that they want as much instrumentation as possible! :-)
@stephenmm
stephenmm / derefrence_arrays.bash
Last active October 21, 2019 20:20
An example of how to deref arrays and use them
# SOURCE ME
# DOES NOT WORK WITH ELEMENTS CONTAINING SPACES!!!!
# Limited use. Use a real scriptting language!?!?
# Ex:
# declare -a cmplxArr='([0]="preffoo" [1]="bar" [2]="foo" [3]="prefbaz" [4]="baz" [5]="prefbar" [6]="pref with spaces" [7]="pref
# with
# new line" [8]="
# pref with new line before")'
@stephenmm
stephenmm / wot_wn8_line_graph.py
Created July 8, 2019 14:27
WoT plot of the WN8 ratings per tier
#!/usr/bin/env python3
# Plots tank damage per tier/level
# Each dot is mean of tank types in that tier
# Each tank type is a seperate line graph
# Inspired from here https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html
# Good example of manipulating dataframes and creating stand alone application with Tk.
import matplotlib
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
@stephenmm
stephenmm / autoit_python_with_cygwin.bash
Last active March 11, 2019 21:43
autoit_python_with_cygwin.bash
# Being able to automate windows tasks with autoit is cool but it would be even cooler if we could:
# 1) run it with python (py is much easier and familiar than the autoit script language)
# 2) with cygwin (so we can do all our linux/bash/vim cleverness in a familiar work environment)
#
# Here is some info on how I got it set up on my new windows laptop.
# Some interesting reading on autoit functionality direclty from windows DLLs: https://stackoverflow.com/questions/23768184/programmatically-rotate-monitor
# Functions for win32api http://timgolden.me.uk/pywin32-docs/contents.html
@stephenmm
stephenmm / autoit_vnc_viewer.py
Last active January 24, 2019 18:57
Example of how to use AutoIt to automate screen positioning... Actually, python calling AutoIt and the start of using windows DLLs directly!
#! python
# To run this double click it in Windows File Explorer
# Notes:
# Some interesting reading on autoit functionality direclty from windows DLLs: https://stackoverflow.com/questions/23768184/programmatically-rotate-monitor
# Functions for win32api http://timgolden.me.uk/pywin32-docs/contents.html
# Directly calling the DLLs w/ ctypes: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemmetrics
import time
import win32com.client
@stephenmm
stephenmm / gvim_clip.bash
Created December 8, 2018 01:40
More extensive way to open files from your clippboard. Supports a file per line open in there own tab.
function gvim_arg() {
local clip servername && local $*; # declare possible named variables
local file_chars clip_file_check extra_stuff line_num find_str cmds cmd cmd1 cmd2
export cmds=()
export file_chars='[-a-zA-Z0-9\$\.\/_]'
#(>&2 echo "Clip: $clip" )
# Get rid of non-file name charecters
clip_file_check=$( echo "$clip" | perl -ne '/($ENV{"file_chars"}+)/ && print("$1");' )
extra_stuff=$( echo "$clip" | perl -ne '/$ENV{"file_chars"}+(.*)/ && print("$1");' )
if [[ $extra_stuff =~ ^(:[0-9]+) ]]; then
@stephenmm
stephenmm / bits2signed.py
Last active November 29, 2018 16:28
Convert a value into its signed counterpart given a particular bit width. Also shows creating simple test in python with asserts and exceptions.
def bits2signed( val, width ):
'''Convert a value into its signed counterpart given a particular bit width'''
shift=width-1
max_val=(2**width)-1
if val > max_val:
raise ValueError('The value provided (%s) is greater than the bit width can represent(2^%s=%s)'%(val,width,max_val))
sign_bit_mask=1<<shift
magn_bit_mask=(1<<shift)-1
return -(val&sign_bit_mask) | (val&magn_bit_mask)
@stephenmm
stephenmm / SOURCE_ME.bash
Last active October 16, 2018 22:53
A quick bash script to allow quick indexing of new codebase. Just add this script to the root of the codebase (and then source it of course).
source_file=`pwd`/${BASH_SOURCE[0]}
source_root=$( readlink -f $( dirname $source_file ) )
# Setup so we can easily search the codebase with csearch/cindex
# Make sure csearch and cindex are installed first
if type cindex >/dev/null 2>&1; then
export CSEARCHINDEX=$source_root/.csearchindex.local
if [[ ! -f $CSEARCHINDEX ]]; then
cindex $source_root
@stephenmm
stephenmm / qqq_vs_spy_plot.py
Last active October 4, 2018 14:36
Very simple example of working with python dataframes and matplotlib to observe some useful info.
import matplotlib.pyplot as plt
import pandas, os, re
import fix_yahoo_finance as yf # Might need to "> pip install fix_yahoo_finance"
stocks=["SPY","QQQ"] # Array of stocks to plot
bgn_date='2014-06-12' # Set the date range
end_date='2018-09-28'
fig,ax = plt.subplots()
@stephenmm
stephenmm / repl_history.py
Last active January 12, 2020 03:17
Simple history function like bash history but for python interactive/repl.
# Simple history function like bash history but for python interactive/repl.
def history( num=0 ):
import readline
len = readline.get_current_history_length()
if( num>0 ):
num=len-num
for i in range(num,len):
print( i,readline.get_history_item(i + 1) )
# Later attemps at the same thing: Cygwin setup of Python REPL