Skip to content

Instantly share code, notes, and snippets.

Max Masnick masnick

Block or report user

Report or block masnick

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@masnick
masnick / README.md
Created Nov 18, 2019
CiteAs bookmarklet
View README.md

This is the code for a bookmarklet to open the current page in CiteAs.

View choose_speakers.scpt
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 / loadsql.ado
Last active Dec 8, 2017
Stata: load and execute SQL from a file on disk
View loadsql.ado
/*
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 / trim.scpt
Created Nov 8, 2017
Trim whitespace with AppleScript
View trim.scpt
on trimThis(pstrSourceText, pstrCharToTrim, pstrTrimDirection)
-- http://macscripter.net/viewtopic.php?id=18519
-- pstrSourceText : The text to be trimmed
-- pstrCharToTrim : A list of characters to trim, or true to use default
-- pstrTrimDirection : Direction of Trim left, right or any value for full
set strTrimedText to pstrSourceText
-- If undefinied use default whitespaces
if pstrCharToTrim is missing value or class of pstrCharToTrim is not list then
View ipython_pickle.applescript
tell application "Keyboard Maestro Engine"
--- GET VARIABLE ---
-- IF KM Variable does NOT exist, the AS Variable will be set to empty string --
set the_path to getvariable "Path"
end tell
tell application "iTerm"
activate
create window with default 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;
});
You can’t perform that action at this time.