Skip to content

Instantly share code, notes, and snippets.

@jsundram
jsundram / graph_merge.jl
Last active January 28, 2021 01:24
implementation of `merge_hierarchical` in Julia
import Colors
using DataStructures
using ImageSegmentation
using LightGraphs
using MetaGraphs
# idea from https://vcansimplify.wordpress.com/2014/08/17/hierarchical-merging-of-region-adjacency-graphs/
function _weight_mean_color(data::MetaGraph, n1::Int, n2::Int)::Real
# Determine weight of an edge between n1 and n2
@jsundram
jsundram / lapser.py
Created January 11, 2021 16:08
turn a timelapse into a sliced timelapse
from skimage import io
import argparse
import glob
import numpy as np
import os
def make_frames(files, outdir, n=8, prefix="composite"):
split = int(len(files) / n)
pathstart = os.path.join(outdir, prefix)
@jsundram
jsundram / history.jl
Created December 10, 2020 20:46
`IJulia.history()` prints everything on one line in jupyter-console, not sure why; this is a quick workaround
function history()
map(sort(collect(keys(IJulia.In)))) do k
println(k, ": ", IJulia.In[k])
end;
return Nothing;
end
@jsundram
jsundram / explore_types.jl
Created December 7, 2020 23:09
looking at julia's type hierarchy
function super(a)
local t
try
t = supertype(a)
catch
t = typeof(a)
end
if t == a
@jsundram
jsundram / fix_web.sh
Last active July 6, 2021 20:50
Internet connection goes down periodically on macos and needs to be restarted by turning wifi on and off again. Sigh.
#!/bin/bash
# Adapted from https://stackoverflow.com/questions/6118948/bash-loop-ping-successful.
# Network connection mysteriously dies; ping every N seconds, and if ping fails
# turn wifi off and on again, which seems to fix it.
echo "run this script with sudo!"
echo "Starting ..."
DOWN=0
while true; do
@jsundram
jsundram / setup.sh
Last active July 3, 2023 13:34 — forked from bradp/setup.sh
New Mac Setup Script
# forked from https://gist.github.com/bradp/bea75b16d3325f5c47d4
# usage:
# 1) attach ssd to old machine and start running backup.sh
# 2) grab the latest version of this file from
# https://gist.github.com/jsundram/eeca472a8929bfab27209783b16bd6d9
# 3) copy this script onto the new machine and start running it
# sh setup.sh
# you will need to add homebrew to your .zprofile path
# PATH=$PATH:/opt/homebrew/bin
# echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zprofile
from datetime import datetime, timedelta
import random
import matplotlib.pyplot as plt
import matplotlib.dates as dates
def make_data():
random.seed(0) # Make it repeatable
s = datetime(2020, 1, 1) # Pick a leap year!
@jsundram
jsundram / worldladder.py
Created May 21, 2020 23:44
I got nerd sniped by @vanreece
from collections import defaultdict
import networkx as nx
import string
import matplotlib.pyplot as plt
def get_words(filename='/usr/share/dict/words'):
d = defaultdict(set)
with open(filename) as f:
for line in f:
"""
Takes a Met Opera json file and parses it and then writes a .inf file suitable for creating video chapters.
ffmpeg -i opera.mp4 -i opera.json.inf -map_metadata 1 -codec copy new_opera.mp4
"""
import json
import sys
from datetime import datetime
@jsundram
jsundram / wav2flac.sh
Created March 28, 2020 19:26
Convert a folder full of .wav files to .flac
find *.wav -exec ffmpeg -i '{}' '{}.flac' \;