Skip to content

Instantly share code, notes, and snippets.

View masnick's full-sized avatar

Max Masnick masnick

View GitHub Profile
tell application "iTunes" to activate
tell application "System Events"
tell window "iTunes" of process "iTunes"
click (first UI element whose help is "Choose which speakers to use.")
end tell
end tell
@masnick
masnick / gist:380d067da1f521b01cb0
Last active December 17, 2017 19:24
Find FastMail tab(s) in Safari
-- original from http://hea-www.harvard.edu/~fine/OSX/safari-tabs.html
-- Last updated January 16, 2015 1:22 PM
set searchpat to "fastmail.com"
tell application "Safari"
activate
set winlist to every window
set winmatchlist to {}
set tabmatchlist to {}
set tabnamematchlist to {}
@masnick
masnick / loadsql.ado
Last active December 8, 2017 19:52
Stata: load and execute SQL from a file on disk
/*
Copyright 2017 Max Masnick
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 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OT
@masnick
masnick / bookmarklet.js
Last active July 26, 2017 16:43
Universal "find at my library" bookmarklet for journal articles
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 / stored_proc_2_result_sets.py
Last active July 14, 2017 15:45
Loading data from a stored proc with multiple results sets into a Pandas DataFrame
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
* 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 / gist:7601046
Created November 22, 2013 14:47
A combination of the Correspondence and Thread Arcs layouts in MailMate.
{
name = "Correspondence Arc";
rootViewer =
{
viewerType = "MmSplitView";
orientation = "horizontal";
children =
(
{
viewerType = "MmBoxView";
@masnick
masnick / 0 umb.js
Last active October 14, 2016 17:12
PubMed → full text search
var re = /^[0-9]{5,15}/;
var found = jQuery(jQuery('.rprtid dd')[0]).text().match(re);
if(found != null) {
location.href = "http://sfx.umd.edu/hs?sid=Entrez:PubMed&id=pmid:"+found[0];
}
else {
alert('PubMedID not found.');
}
@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.
@masnick
masnick / md2jira.js
Created May 26, 2016 18:02
Convert Markdown to JIRA markup
// 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;
});