Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
typedef struct {
int *data;
int capacity;
int size;
} BinaryHeap;
// Function prototypes
#!/usr/bin/env python3
"""
Helper file that has executable examples.
Ex:
~/hlp/PY_HLP.py map_simple_example
"""
def ex_args_kwargs( *args, **kwargs ):
for i in kwargs.items():
print(f'{i}: {kwargs[i]}')
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