Skip to content

Instantly share code, notes, and snippets.

View masnick's full-sized avatar

Max Masnick, PhD masnick

View GitHub Profile
@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));
-- Source: http://forums.omnigroup.com/showthread.php?t=31062
tell application "OmniGraffle"
set thedocument to front document
set thePath to the path of the thedocument
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set theDirectory to (text items 1 through -2 of thePath) as text
set AppleScript's text item delimiters to ASTID
# Save the original canvas for restoration
@masnick
masnick / bookmarklet.html
Created August 8, 2015 19:08
Amazon.com order history search bookmarklet
<a href="javascript:(function()%7Bvar%20x%20%3D%20window.prompt(%22Search%20Amazon.com%20order%20history%20for%3A%22)%3Bwindow.location.href%3D'https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyour-account%2Forder-history%2Fref%3Doh_aui_search%3Fopt%3Dab%26search%3D'%2BencodeURIComponent(x)%7D)()">Drag to your bookmarks bar</a>
@masnick
masnick / cross_join_results_table.md
Created August 7, 2015 16:48
Cross join results table
friend_id friend_name pet_id owner_id pet_type pet_name
1 John 1 1 goldfish Fishy
2 Sarah 1 1 goldfish Fishy
3 Rachel 1 1 goldfish Fishy
4 Sam 1 1 goldfish Fishy
1 John 2 1 goldfish Nemo
2 Sarah 2 1 goldfish Nemo
3 Rachel 2 1 goldfish Nemo
4 Sam 2 1 goldfish Nemo
@masnick
masnick / gridspec.ipynb
Created July 29, 2015 16:01
GridSpec histogram + box plot example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@masnick
masnick / cell.py
Last active August 29, 2015 14:25
IPython notebook snipped for a list of variables in a dataframe
# Assumes `df` is a Pandas DataFrame object
import IPython.core.display as di
for k, v in df.columns.to_series().groupby(df.dtypes).groups.iteritems():
di.display_html("<ul><li><b>%s</b><ul>%s</ul></li></ul>" % (k, ''.join(["<li>%s</li>" % vv for vv in sorted(v)])), raw=True)
@masnick
masnick / ipython_notebook_config.py
Created July 17, 2015 17:42
IPython post hook for saving `.py` and `.html` files from notebooks
# 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':
@masnick
masnick / gist:9bb5590b426b7ae87ad3
Last active November 22, 2015 17:54
Hide code blocks in IPython HTML output
import IPython.core.display as di
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
@masnick
masnick / Gemfile
Created June 25, 2015 14:45
LaunchBar 6 Action for posting to iDoneThis
source "https://rubygems.org"
gem 'json'
gem 'idonethis'
@masnick
masnick / xtitle: Clipboard to titlecase helper
Created June 4, 2015 13:31
TextExpander: Clipboard to Titlecase
#!/bin/bash
echo -n "%snippet:xxxxtitle%" | tr -d '\n'