Skip to content

Instantly share code, notes, and snippets.

View brandones's full-sized avatar

Brandon Istenes brandones

View GitHub Profile
@brandones
brandones / graph_pca.m
Last active June 16, 2016 16:53
Matlab implementation of PCA on a graph
function X = graph_pca(A, k)
% A: the adjacency matrix of a graph
% k: the number of dimensions to reduce to
%
% Calculates the ECTD-preserving PCA of the graph given by A.
% See http://outobox.cs.umn.edu/PCA_on_a_Graph.pdf for background.
L = diag(sum(A)) - A;
Lp = pinv(L);
[U, E] = eigs(Lp, k);
X = E.^(1/2) * U';
import networkx as nx
import numpy
import scipy.io
import scipy.linalg
import scipy.sparse.linalg
from scipy.sparse.linalg.eigen.arpack.arpack import ArpackNoConvergence
def reduce_from_matlab(mat_path, output_dim):
mat = scipy.io.loadmat(mat_path)
@brandones
brandones / pylint
Created May 9, 2017 23:04
Run pylint using first virtualenv named 'env' in a parent directory
#!/usr/bin/python
#
# Placed at /usr/local/bin/python
# Expects pylint executable at /usr/bin/pylint
#
import os
import sys
def get_python_exec():
@brandones
brandones / matrix_deleted_pivot.m
Created September 26, 2017 12:33
Matlab implementation of the "deleted pivot" operation described by Greg Kuperberg in "Kasteleyn cokernels"
1; % script file
function res = deleted_pivot(M, i, j)
% Calculates the deleted pivot of matrix M at row i, column j
% as described by Greg Kuperberg in "Kasteleyn cokernels"
% X = the jth column of M with element i removed
X = [M(:,j)(1:i-1); M(:,j)(i+1:end)];
% Yt = the ith row of M with element j removed
Yt = [M(i,:)(1:j-1), M(i,:)(j+1:end)];
@brandones
brandones / dbexport.py
Created August 14, 2018 22:01
Jython: use Jackcess all the tables from a password-protected MS Access database to CSV
#! /usr/bin/env jython
#
# Based on https://gist.github.com/shapr/507bcbf3e8cfdc5d3549
#
# Install prereqs:
# sudo apt-get install jython libcommons-logging-java libcommons-lang-java
#
# Put the following jars into the same directory as this file:
# jackcess: https://sourceforge.net/projects/jackcess/files/
# jackcess-encrypt: https://sourceforge.net/projects/jackcessencrypt/files/
@brandones
brandones / odrive-sync.sh
Created November 9, 2018 18:13
Nautilus context menu sync with ODrive
#!/bin/bash
# Put this file in ~/.local/share/nautilus/scripts/
# Remember to `chmod +x` it
IFS='
'
for file in ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}
do
if [[ $file == *.cloud ]] || [[ $file == *.cloudf ]]
then
@brandones
brandones / append_roxygen_script_doc_to_readme.sh
Created March 1, 2019 18:09
Appends Roxygen @Package docstring to README.md
#!/bin/bash
#
# Extracts the Roxygen package documentation from each script file in the
# package root directory and appends it to README.md
#
# Documentation that you want included should start on the second line of the script
OUTFILE="README.md"
r_files=( *.R )
Example config:
foo: {
bar: 0,
baz: {
qux: "abc",
quy: "xyz"
}
}
@brandones
brandones / array-config.js
Last active November 7, 2019 21:16
Arrays in OpenMRS MF Configurations
// Example 1: Array of primitives
// input
foo: [2, 42, 99]
// schema
{
foo: {
default: [1, 1, 2, 3],
arrayElements: {
@brandones
brandones / remove_untranslated.py
Created May 5, 2020 22:57
Remove strings matching the english string from a messages_LL.properties file
#!/usr/bin/env python3
import argparse
import re
def main(lang):
en_strings = properties_to_dict(read_file("en"))
t_strings = properties_to_dict(read_file(lang))
translated = {k: t_strings[k] for k in t_strings if en_strings[k] != t_strings[k]}