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 / phone_format.rb
Created Jan 27, 2015
Phone number format script for TextExpander snippet
View phone_format.rb
#! /usr/bin/env ruby
# Source: tadman on StackOverflow - http://stackoverflow.com/a/5913838
def formatted_number(number)
digits = number.gsub(/\D/, '').split(//)
if (digits.length == 11 and digits[0] == '1')
# Strip leading 1
digits.shift
View gmail_to_fastmail.md

Proceed at your own risk. Back up. Don't blame anyone but yourself if you lose all your email or send your personal information to a nefarious third party.

Source: http://hynek.me/articles/fleeing-from-gmail/

  1. On a VPS to increase speed (I used a Digital Ocean VPS):

     wget http://imaputils.googlecode.com/svn-history/r5/trunk/imapcopy.pl
    
  2. Create a text file called map with the following contents:

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 / gist:380d067da1f521b01cb0
Last active Dec 17, 2017
Find FastMail tab(s) in Safari
View gist:380d067da1f521b01cb0
-- 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 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
View jupyter_notebook_config.py
# 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 / 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 / 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
You can’t perform that action at this time.