Skip to content

Instantly share code, notes, and snippets.

@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)
@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
"""
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).
{
"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
using Optim
import Optim.retract!
import Optim.project_tangent!
struct SphereSubspaceComplementIntersection <: Manifold
U::Matrix
proj::Matrix
end
function SphereSubspaceComplementIntersection(U)
@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

# Sonic Pi v2.10
use_bpm 130
notes = (ring :b3, :fs3, :g3, :c4)
notes_sliced = (ring :b3, :as3, :a3, :as3)
define :long do
4.times do
with_fx :bitcrusher, mix: 0.2 do
with_synth :hoover do
@kersulis
kersulis / procrustes.py
Last active September 28, 2016 16:11
Align shape data using SVD.
import numpy as np
def procrustes(shapes):
"""
Syntax: ashapes, sm = procrustes(shapes)
Inputs: shapes is a n x p x d array, where n is the number of
shapes, p is the number of points per shape, and d is
the dimension of each point (d=2 for xy plane, etc.).
Thus, shapes[0,5,:] contains the d coordinates for the