Skip to content

Instantly share code, notes, and snippets.

Avatar

Max Masnick masnick

View GitHub Profile
@masnick
masnick / ipython_notebook_config.py
Created Jul 17, 2015
IPython post hook for saving `.py` and `.html` files from notebooks
View ipython_notebook_config.py
# http://stackoverflow.com/questions/29329667/ipython-notebook-script-deprecated-how-to-replace-with-post-save-hook
import os
from subprocess import check_call
c = get_config()
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
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:

@masnick
masnick / How I Do PlantUML.md
Created Nov 25, 2020 — forked from jerieljan/How I Do PlantUML.md
PlantUML with Style -- How I do PlantUML
View How I Do PlantUML.md

I use PlantUML a lot. It's what I use for drawing all sorts of diagrams and it's handy because of its easy markup (once you get used to it) while making things easy to maintain as projects grow (thanks to version control)

This gist explains how I do my PlantUML workspace in a project.

  • The idea is to keep a globals directory for all diagrams to follow (like the "stylesheet" below) to keep things consistent.
  • I use a stylesheet.iuml file that keeps the use of colors consistent through use of basic FOREGROUND, BACKGROUND and ACCENT colors.
  • The style-presets.iuml file defines these colors so you can make "presets" or "themes" out of them.
  • As stated in the stylesheet.iuml, you'll need the Roboto Condensed and Inconsolata fonts for these to work properly.
  • You can choose to either run the PlantUML jar over your file/s, or use an IDE like VSCode with the PlantUML extension. Here's a preview of example-sequence.puml for example: https://imgur.com/Klk3w2F
@masnick
masnick / gist:1291199
Created Oct 16, 2011
jQuery inject one-liner
View gist:1291199
var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js";var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b);
@masnick
masnick / fix_dates.R
Last active Jul 13, 2020
Fix up date columns in R
View fix_dates.R
df_messy_dates <- tribble(
~col1_dt, ~col2_dt, ~other_data,
"2019-01-01", "2019-01-02", "a",
"2019-01-03", "1/4/2019", "b",
"01/05/2019", "2019-01-06", "c"
)
# A tibble: 3 x 3
# col1_dt col2_dt other_data
# <chr> <chr> <chr>
@masnick
masnick / emails.md
Last active Jun 3, 2020
A strategy for writing clearer emails
View emails.md

From this HBR article:

  • Start email with single sentence summary:

    Bottom line: This is a better way to write emails informed by US Military practices.

  • Then have a Background section that succinctly provides the necessary context for the "bottom line."

  • Keep the whole thing as short as possible, ideally to avoid the reader having to scoll.

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 / output.txt
Created Dec 28, 2019
Output of tweet to Markdown shortcut
View output.txt
[Max Masnick on Twitter](https://twitter.com/masnick/status/1209899493048639488):
> It’s surprisingly hard to find a tweet with multiple URLs in it for API response testing purposes.
>
> So here are my two favorite non-Google search engines:
>
> 1. <https://t.co/jFqkR0eo8x>
> 2. <https://t.co/UZD9mmtzEH>
>
> 👍
@masnick
masnick / safari_to_chrome.applescript
Created Dec 27, 2019
Open Safari tabs in Google Chrome
View safari_to_chrome.applescript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set url_list to {}
tell application "Safari"
set w to window 1
try
repeat with t in (tabs of w)
@masnick
masnick / batch_convert_docx_to_pdf.applescript
Last active Dec 17, 2019
Batch convert Word files (.docx) to PDF
View batch_convert_docx_to_pdf.applescript
-- Based on https://discussions.apple.com/thread/250068127 (thanks, VikingOSX!)
property word_docs : {"org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"}
property default_path : (path to desktop) as alias
property Delim : {".docx", ".doc"}
property PDF : ".pdf"
set outPDF to {}
set selected_files to (choose file of type word_docs default location default_path with multiple selections allowed without invisibles and showing package contents)