Skip to content

Instantly share code, notes, and snippets.

@mm--
mm-- / org-refile-hydra.el
Created March 9, 2017 21:52
Hydra for quickly refiling Org mode entries
;; Adapted from https://emacs.stackexchange.com/questions/8045/org-refile-to-a-known-fixed-location
(defun my/refile (file headline &optional arg)
"Refile to a specific location.
With a 'C-u' ARG argument, we jump to that location (see
`org-refile').
Use `org-agenda-refile' in `org-agenda' mode."
(let* ((pos (with-current-buffer (or (get-buffer file) ;Is the file open in a buffer already?
(find-file-noselect file)) ;Otherwise, try to find the file by name (Note, default-directory matters here if it isn't absolute)
@mm--
mm-- / pdf-speedread-convert.sh
Last active September 22, 2017 23:46
Speed read PDFs with jetzt
#!/bin/bash
# Convert a pdf to html, add Javascript for speed reading
#READPDFLOC="./readPDF" # Use this if you want to use a local version
READPDFLOC="https://cdn.rawgit.com/mm--/b47c2700b6c63f1598e4/raw/a96388cb3cf89b7a041a63f06a91c2953ee5731c/readPDF.js"
FILE="$1"
HTML="$(basename "$FILE" .pdf).html"
SAVEDDIR=`pwd`
@mm--
mm-- / rfid.py
Created July 13, 2015 02:29
Raspberry Pi RFID reading for Seeed Studio Mini 125Khz RFID module
# Raspberry Pi RFID reading for Seeed Studio Mini 125Khz RFID module
import serial, operator
rfid = serial.Serial("/dev/ttyAMA0")
rfid.baudrate = 9600
rfid.timeout = 2 # Need a timeout in case we read less than 5 bytes
def verify(data):
"""Check the validation bit (the last one) by XORing the first four bytes."""
ints = map(ord, list(data))
if (len(ints) != 5):
@mm--
mm-- / asc-to-obj.R
Created September 5, 2014 00:04
Take a FreeSurfer ASCII format surface and convert to Wavefront .obj, unnecessarily rendering a rainbow-colored surface using rgl ;P
#!/usr/bin/Rscript
## Josh Moller-Mara
## Take in an .asc file created with mris_convert
## (e.g. mris_convert lh.pial lh.pial.asc)
## and then convert it into a Wavefront OBJ.
## And also unnecessarily render it with rgl :-)
library(rgl)
args <- commandArgs(trailingOnly = TRUE)
@mm--
mm-- / lda-test.R
Created August 3, 2014 09:10
An attempt to use Latent Dirichlet Distribution to do topic modeling and clustering on text
#!/usr/bin/Rscript
## NOTE: This code got pretty messy, and is no longer meant to be run
## just as an Rscript.
##
## LDA test
## Josh Moller-Mara
## Take in a file with one "document" per line.
## Try to cluster them using Latent Dirichlet Allocation and select
## among models using DIC.
@mm--
mm-- / mixture-models-em.R
Last active March 12, 2018 21:24
An example of clustering using Gaussian mixture models, fitted using Expectation-Maximization.
## EM algorithm implementation
## Joshua Moller-Mara
require(MASS)
require(mvtnorm)
## Probability of each cluster for each point
E.step <- function(X, phi, N) {
h <-
with(phi, do.call(cbind,
lapply(1:N, function(i)
@mm--
mm-- / k-means-color.R
Created November 12, 2013 06:16
Create a color palette for xterm from a JPEG using k-means.
#!/usr/bin/Rscript
## Generate a color palette for an image using k-Means
## Joshua Moller-Mara
library(jpeg)
library(colorspace)
library(rgl)
args <- commandArgs(trailingOnly = TRUE)
plotPalette <- function(palette) {
barplot(rep(1,length(palette)), yaxt="n", col=palette)