Skip to content

Instantly share code, notes, and snippets.

View masnick's full-sized avatar

Max Masnick masnick

View GitHub Profile
@masnick
masnick / compare_2_sirs.py
Last active April 28, 2016 19:02
Compare 2 SIRs in Python
"""
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 April 22, 2016 12:50
Move newest file in Downloads folder to the frontmost Finder window
#! /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 October 13, 2016 06:22 — forked from ChadFulton/stata_examples.ipynb
SARIMAX - Stata Examples
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
tell application "Finder"
set finderSelList to selection as alias list
end tell
if finderSelList ≠ {} then
repeat with i in finderSelList
set contents of i to POSIX path of (contents of i)
end repeat
set AppleScript's text item delimiters to linefeed
def icd9_transform(icd9):
l = len(icd9)
if l == 3:
return "%s000" % icd9
elif l == 4:
return "%s00%s" % (icd9[0:3], icd9[-1:])
elif l == 5:
return "%s0%s" % (icd9[0:3], icd9[-2:])
else:
return icd9
@masnick
masnick / URL from Chrome.applescript
Created March 22, 2016 20:25
Get the URL from the active Chrome tab/window for TextExpander
tell application "Google Chrome"
set frontIndex to active tab index of front window
set theURL to URL of tab frontIndex of front window
end tell
return theURL
# Based off of https://github.com/jupyter/notebook/blob/master/docs/source/extending/savehooks.rst
import io
import os
from notebook.utils import to_api_path
_script_exporter = None
_html_exporter = None
def script_post_save(model, os_path, contents_manager, **kwargs):
@masnick
masnick / gist:b1c5bf9c8972ae643321
Created February 22, 2016 14:00
Bookmarklet for removing GIFs from a webpage
javascript:$('img').filter(function() { if( this.src.indexOf('.GIF') >= 0 || this.src.indexOf('.gif') >= 0) return this; }).replaceWith('<img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg" />');;
cap log c
clear
set more off
cd "/path/to/folder/"
local files : dir "`c(pwd)'" files "*.dta"
clear
foreach f in `files' {
@masnick
masnick / javascript.html
Last active November 24, 2015 01:59
Dropbox/JavaScript/Markdown hack
<div id="dropbox-include">Loading from Dropbox...</div>
<script language="javascript">
function loadFromProxy() {
$("#dropbox-include").html("Loading from Dropbox proxy...");
var newUrl = "{{page.dropbox_url}}".replace("https://dl.dropboxusercontent.com/u/000000/permanent/text/", "https://your-dropbox-text-proxy.herokuapp.com/");
jQuery.get(newUrl, function(data) {
console.log("Got file from "+newUrl+".")
}).done(function(data){
var converter = new Markdown.Converter();
$("#dropbox-include").html(converter.makeHtml(data));