Skip to content

Instantly share code, notes, and snippets.

View sbliven's full-sized avatar
💻
Typing...

Spencer Bliven sbliven

💻
Typing...
View GitHub Profile
/* Solutions to https://stackoverflow.com/questions/800368/declaring-an-object-before-initializing-it-in-c/62247236#62247236
*
* Uses c++17 for some solutions
*
* Output:
*
* $ g++ --std=c++17 -o animals animals.cpp && ./animals
* Naive Method
* ------------
* Default Constructing Animal at 0x7ffee3fc20d0
@sbliven
sbliven / timeout_fn.sh
Last active September 21, 2020 15:50
'timeout' command, implemented within the shell so that it works with shell functions
#!/bin/zsh
# A version of the 'timeout' command that works with shell functions
#
# Usage:
# source timeout_fn.sh
# timeout_fn DURATION COMMAND [ARG]...
timeout_fn () {
local timeout=$1
shift
@sbliven
sbliven / vcd2mp4
Created August 3, 2020 05:56
Convert a VCD .dat file to .mp4 video
#!/bin/bash
# usage: vcd2mp4 output.mp4 input.dat [input2.dat...]
if [[ $# -lt 2 ]]; then
echo "usage: $0 output.mp4 input.dat [input2.dat...]" >&2
exit 1
fi
output="$1"
shift
@sbliven
sbliven / restartnet
Created January 27, 2021 21:12
Restart the network (Ubuntu 20.04)
#!/bin/bash
# Restart the network
# usage: sudo restartnet [iface]
# Requires root
# Guess interface for outgoing traffic
TARGET=8.8.8.8 # known IP. Could also be 192.168.0.1 or similar for local networks
function guess_iface {
ip route get $TARGET | grep -Po '(?<=dev\s)\w+' | cut -f1 -d ' '
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sbliven
sbliven / closuretest.cpp
Created March 12, 2021 07:56
C++ lambda function with closure
// g++ -o closuretest -std=c++11 closuretest.cpp
#include <iostream>
#include<functional>
int main() {
int i = 0;
std::function<void()> fns[3];
for(;i < 3; i++) {
fns[i] = [&i]() {
std::cout << i << std::endl;
@sbliven
sbliven / mysettings.py
Created April 22, 2021 20:46
Example of reading a "settings" python module
"""A settings module based on global variables"""
name = "Custom Settings"
x = 4
y = 0
@sbliven
sbliven / mysettings.ini
Last active April 22, 2021 21:39
Improved version of sbliven/d413c2f2f4af3bf56e13d1f8656751b1 using configparser
[nlsa] |~
name = Custom Settings |~
x = 4 |~
import shapefile
def replace_escape(s):
return s.replace(b'\xc3\x82\xc2',b'\xc2').replace(b'\xc3\x83\xc2',b'\xc3')
sf = shapefile.Reader("swisscantonsmod/ch-cantons.dbf")
print(f"records: {len(sf.records())}")
print(f"shapes: {len(sf.shapes())}")
out = shapefile.Writer("swisscantonsmod/ch-cantons_fixed.dbf")
for f in sf.fields:
@sbliven
sbliven / TimeDistToZurich.csv
Last active August 11, 2021 12:35
driving distance around zurich (in minutes)
lon lat duration
8.5215272410261 47.3957616953417 0
8.371835 47.24679 31.235
8.371027 47.250516 29.9966666666667
8.372975 47.255491 29.2833333333333
8.37146 47.260156 28.6333333333333
8.372376 47.264277 29.7183333333333
8.369903 47.269002 33.515
8.371152 47.274843 31.0783333333333
8.371162 47.280342 27.5366666666667