Skip to content

Instantly share code, notes, and snippets.

@kersulis
kersulis / NotebookNirvana.ipynb
Last active November 20, 2020 11:37
Python 2 and Python 3, Julia 0.3 (release) and 0.4 (dev), plus bash, all in Jupyter notebook on Ubuntu.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kersulis
kersulis / eigenimages.py
Last active November 20, 2020 11:36
Interactive Eigenimages. Live version on Binder: http://mybinder.org/repo/kersulis/SVD-eigenimages
import ipywidgets as ipw
from pylab import *
def classify_image(tst,trn,k):
""" Input:
tst: a n x T vector corresponding to T images that are to be classified
trn: n x m x 10 matrix containing m training samples for each digit
k: integer between 1 and n
"""
n,T = tst.shape
@kersulis
kersulis / shift_scale.jl
Last active June 19, 2020 18:55
Julia code: shifting and scaling a matrix
using Images
"""
B = shift_lr(A, k)
Shift `A` by `k` columns. If `k` is positive, shift to the
right by inserting `k` columns on the left. If `k` is
negative, shift to the left by inserting `k` columns
on the right.
"""
function shift_lr(A::AbstractMatrix, k::Integer)
"""
p = joyplot(A)
Generate a "joyplot" from data in `A`. Each column of `A` will be
plotted with a `plot()` command, and all plots will be stacked
vertically.
Keyword arguments:
* `labels`: a vector of subplot labels having length size(A, 2).
* `plot_size`: overall plot size; default is (400, 500).
@kersulis
kersulis / make-problem-statistics.vd
Created November 6, 2019 15:17
Script for generating statistics by problem for Gradescope assignment export CSV files
sheet col row longname input keystrokes comment
open-file Quiz_1a_scores.csv o
open-file Quiz_1b_scores.csv o
open-file Quiz_2a_scores.csv o
open-file Quiz_2b_scores.csv o
open-file Quiz_3a_scores.csv o
open-file Quiz_3b_scores.csv o
open-file Quiz_4a_scores.csv o
open-file Quiz_4b_scores.csv o
open-file Quiz_5a_scores.csv o
@kersulis
kersulis / jpg2gif.md
Last active May 9, 2019 05:06
jpg2gif

jpg2gif

Generate an animated GIF from a folder full of .jpg images.

1. Install prerequisites

You need:

  • Python 3; I used 3.6.2 for development and testing.
  • The imageio package. If you're using pip, install with pip install imageio. I worked with version 2.2.0.

2. Place your images

@kersulis
kersulis / .block
Last active August 16, 2018 23:01
Force-directed graph: injection shift factors
heigh: 800
{
"grg_version": "v.4.0",
"network": {
"id": "nesta_case3_lmbd",
"type": "network",
"subtype": "bus_branch",
"description": "Copyright (c) 2017 The Grid Research for Good (GRG) Team. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated. documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR C
@kersulis
kersulis / IntroToJulia.ipynb
Last active July 31, 2018 02:16
Intro to Julia and PowerModels.jl
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kersulis
kersulis / SDPDecompTimingResults.md
Created July 19, 2018 15:43
Timing results for SDPDecompPowerModel
case gap time_ac time_sdp
nesta_case3_lmbd 0.380212 0.0115185 0.00657511
nesta_case5_pjm 5.21946 0.0187869 0.026509
nesta_case14_ieee 0.000147327 0.0249393 0.0432889
nesta_case24_ieee_rts 4.66891e-5 0.0591923 0.166873
nesta_case30_as 0.000902287 0.0485134 0.110496
nesta_case30_fsr 2.73208e-5 0.0556282 0.234215
nesta_case30_ieee 2.83224e-5 0.0627696 0.127613
nesta_case39_epri 0.0151207 0.0661744 0.257961