Skip to content

Instantly share code, notes, and snippets.

Max Masnick masnick

View GitHub Profile
@masnick
masnick / bookmarklet.js
Last active Jul 26, 2017
Universal "find at my library" bookmarklet for journal articles
View bookmarklet.js
var url = 'http://something.youruniversity.edu/foo/bar';
var doi;
var suffixes = {
"pmid": "?sid=Entrez:PubMed&id=pmid:",
"doi": "?sid=Entrez:DOI&id=doi:"
};
var re = /^[0-9]{5,15}/;
var found = jQuery(jQuery(".rprtid dd")[0]).text().match(re);
@masnick
masnick / balance.scpt
Last active May 12, 2017
macOS: Set sound output balance to middle
View balance.scpt
-- Based on the AppleScript posted here: https://secure.macscripter.net/viewtopic.php?pid=190067
tell application "System Preferences"
activate
reveal anchor "output" of pane id "com.apple.preference.sound"
delay 0.5 -- If you get an error, it's possible this delay isn't long enough.
end tell
tell application "System Events"
tell slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences"
set value to 0.5
end tell
@masnick
masnick / stored_proc_2_result_sets.py
Last active Jul 14, 2017
Loading data from a stored proc with multiple results sets into a Pandas DataFrame
View stored_proc_2_result_sets.py
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql://{}:{}@{}/{}'.format(username, password, server, database_name))
connection = engine.connect().connection
cursor = connection.cursor()
cursor.execute('call storedProcName(%s, %s, ...)', params)
# Result set 1
View loadsql.ado
* NOTE: this ADO uses shell calls to run `rm`, so it could potentally delete files
* from your computer. Use at your own risk.
cap drop program loadsql
program define loadsql
*! Load the output of an SQL file into Stata, version 1.3 (dvmaster@gmail.com)
*! Based on http://stackoverflow.com/a/12272627/173351
version 14.1
syntax using/, DSN(string) [User(string) Password(string) CLEAR NOQuote LOWercase SQLshow ALLSTRing DATESTRing]
@masnick
masnick / md2jira.js
Created May 26, 2016
Convert Markdown to JIRA markup
View md2jira.js
// https://github.com/FokkeZB/J2M/blob/master/script.js
function toJ(converted) {
converted = converted.replace(/^(.*?)\n([=-])+$/gm, function (match,content,level) {
return 'h' + (level[0] === '=' ? 1 : 2) + '. ' + content;
});
converted = converted.replace(/^([#]+)(.*?)$/gm, function (match,level,content) {
return 'h' + level.length + '.' + content;
});
@masnick
masnick / pyenv.md
Last active May 23, 2016
pyenv setup instructions
View pyenv.md

OS X ships with an old version of Python 2. Here's how I set up my system:

brew install pyenv pyenv-virtualenv

Then add to .zshrc or .bashrc:

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Then restart Terminal.app, and build the newest version of Python:

@masnick
masnick / private.xml
Created May 9, 2016
Disable Command-F1 with Karabiner
View private.xml
<?xml version="1.0"?>
<root>
<item>
<name>Disable Command-F1</name>
<identifier>private.disable.command.f1</identifier>
<autogen>--KeyToKey-- ConsumerKeyCode::BRIGHTNESS_DOWN, ModifierFlag::COMMAND_L, ConsumerKeyCode::BRIGHTNESS_DOWN</autogen>
<autogen>--KeyToKey-- ConsumerKeyCode::BRIGHTNESS_DOWN, ModifierFlag::COMMAND_R, ConsumerKeyCode::BRIGHTNESS_DOWN</autogen>
</item>
</root>
@masnick
masnick / compare_2_sirs.py
Last active Apr 28, 2016
Compare 2 SIRs in Python
View compare_2_sirs.py
"""
Compare 2 SIRs by exact binomial and mid-p
==========================================
This is a conversion of SAS code written by Minn Soe and published by the CDC.
The original SAS code is available here: http://www.cdc.gov/nhsn/sas/binom.sas
Author: Max Masnick, PhD (https://masnick.org/contact)
Last modified: 2016-04-28
@masnick
masnick / move.sh
Created Apr 22, 2016
Move newest file in Downloads folder to the frontmost Finder window
View move.sh
#! /usr/bin/env bash
current_folder=`osascript -e 'tell application "Finder"' -e "if (${1-1} <= (count Finder windows)) then" -e "get POSIX path of (target of window ${1-1} as alias)" -e 'else' -e 'get POSIX path of (desktop as alias)' -e 'end if' -e 'end tell'`
newest_file=`mdls -name kMDItemFSName -name kMDItemDateAdded -raw /Users/YOUR_USERNAME_HERE/Downloads/* | xargs -0 -I {} echo {} | sed 'N;s/\n/ /' | sort --reverse | head -1 | sed -E "s/^.*\\+0000 //"`
mv "/Users/YOUR_USERNAME_HERE/Downloads/$newest_file" "$current_folder"
osascript -e "display notification \"$newest_file$current_folder\" with title \"File moved\""
@masnick
masnick / stata_examples.ipynb
Last active Oct 13, 2016 — forked from ChadFulton/stata_examples.ipynb
SARIMAX - Stata Examples
View stata_examples.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.