Skip to content

Instantly share code, notes, and snippets.

import haversine as hs
from haversine import haversine, haversine_vector, Unit
import pandas as pd
import numpy as np
import json
print('hello')
lat=30.393000
lon=-98.070050
@stephenmm
stephenmm / stockfundamentalanalysis.ipynb
Created March 5, 2022 18:27
StockFundamentalAnalysis.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stephenmm
stephenmm / eng_format.py
Created March 4, 2022 23:52
Finally got a engineering format the way I like it
from math import log10
def eng_str(x, significance=8, precision=3):
y = abs(x)
exponent = int(log10(y))
engr_exponent = exponent - exponent%3
z = y/10**engr_exponent
if x < 0:
z=z*-1
if engr_exponent > 0:
exp_str=f"+{engr_exponent:03}"
@stephenmm
stephenmm / example_list_dict_ops.tcl
Last active May 4, 2021 16:42
Basic list and dict manipulations
# Basic 101 list commands for .tcl (cannot do $X[$index] has to be [lindex $X $index])
set X [list] ;# NOTE! Good practce to start with empty list (.tcl is calling [] function "list" and returning an empty list)
lappend X a b c ; puts $X ;# a b c
#lappend X {d e f} ; puts $X ;# a b c {d e f} ;# NOTE! This is probably not what you wanted! Creates list of list
lappend X {*}{d e f} ; puts $X ;# a b c d e f ;# NOTE! The {*} tells tcl to expand the list before appending
set X [lreplace $X 1 1 B] ; puts $X ;# a B c d e f ;# NOTE! lreplace does not modify the origianl list so must assign it back
set X [lreplace $X 2 3 C D] ; puts $X ;# a B C D e f
set X [lreplace $X 2 2] ; puts $X ;# a B D e f ;# Delete list element by replacing it with nothing
set X [lreplace $X 3 4] ; puts $X ;# a B D
set idx [lsearch $X "B"] ;# Search for index by value
@stephenmm
stephenmm / fill_csv_columns_with_zeros.bash
Created April 30, 2021 16:03
# Create 6 column CSV with with added zeros (Solutions w/ perl awk sed) https://stackoverflow.com/a/38106938/120681
# I have a file.txt containing numbers like
1, 2, 3
4, 5
6, 7, 8, 9,10,11
12,13,14,15,16
# I want to create a CSV file by padding each line such that there are 6 values separated by 5 commas, so I need to add to each line an appropriate number of ",0". It shall look like
1, 2, 3, 0, 0, 0
4, 5, 0, 0, 0, 0
6, 7, 8, 9,10,11
12,13,14,15,16, 0
@stephenmm
stephenmm / xchrome_func_source.sh
Last active December 28, 2020 20:46
Open webpage in chrome from linux terminal (and search for string "my_string"): xchrome -f my_string /path/to/html.html
function xchrome() {
read -r -d '' HELP_MSG << END_HELP_MSG
Description:
Open webpage in chrome from terminal (and search for string "my_string")
Installation:
Add this function to your .bashrc
Known limitiations:
find string can only contain [a-zA-Z_]
URL cannot have anchors /path/to/html.html#anchor
@stephenmm
stephenmm / bash_function_named_args.bash
Last active August 20, 2020 20:33
Very simple named arguments for bash functions
# Do not use in public facing servers as I am sure it can do bad things by malicious individuals
# Initialize variables and functions
unset -f boo
unset -f echoerror
unset other
echoerr() { printf "%s\n" "$*" >&2; }
# Example bash function to show the use of:
# required args "rqrd_arg"
# named args "namd_arg"
@stephenmm
stephenmm / simple_plot.py
Created March 28, 2020 07:05
How to go from bare windows machine to plotting graphs in Python (Amazingly complicated but should be very repeatable...)
#!/home/smeckley/py/venvs/venv1/bin/python
# All the steps required to get this simple plot:
# 1) Install VM VirtualBox on my windows machine
# 2) Download LinuxMixt (LMDE4) .iso
# 3) Create new VM for Linux Ubuntu and load .iso into the virtual optical drive
# 4) Startup the VM and click on "install" icon on the desktop (follow propmts)
# 5) Once finished with the basic install we need to enable "Guest Additions" to share clipboard/resize screen (all the goodies) VM->Devices->"Install Guest Additions CD Image" and run that
# 6) Install gvim (WTF!!) "sudo apt install vim-gtk3"
# 7) Get Python working with the correct libraries
# sudo su
@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")'