Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@paultopia
paultopia / working_3dplot
Created February 2, 2019 23:29
fixing size issues on 3d plot
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
@paultopia
paultopia / 3dregplot.ipynb
Created February 2, 2019 22:44
3d matplotlib regression plot example, but with broken figure size (at least in jupyter 4.4.0)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paultopia
paultopia / caselaw.py
Last active January 31, 2019 22:48
quick and dirty commandline tool to download a case by citation from caselaw access project (https://case.law). Requires API key registration.
import requests, json, string, sys, os
endpoint = "https://api.case.law/v1/cases/"
apikey = os.environ["CASELAW"] # put your case.law api key here
headers = {"Authorization": "Token " + apikey}
def depunctuate(st):
return st.translate(str.maketrans(dict.fromkeys(string.punctuation)))
// more gui experiments
// see: https://stackoverflow.com/questions/54357317/nssavepanel-name-not-user-editable
import AppKit
import Foundation
import Quartz
NSApplication.shared.setActivationPolicy(.accessory)
func helperReadPDF(_ filename: String) -> String {
@paultopia
paultopia / pdfopentest-multi.swift
Created January 24, 2019 23:44
multiple version (ignore me, personal testing)
import AppKit
import Foundation
import Quartz
func helperReadPDF(_ filename: String) -> String {
let pdata = try! NSData(contentsOfFile: filename) as Data
let pdf = PDFDocument(data: pdata)
return pdf!.string!
}
@paultopia
paultopia / pdfopentest.swift
Created January 24, 2019 23:24
ignore me, just saving some code where I won't forget it, mid learning how to mess with UI from swift cli
import AppKit
import Foundation
import Quartz
func readPDF(_ file: URL) -> String {
let pdata = try! NSData(contentsOf: file) as Data
let pdf = PDFDocument(data: pdata)
return pdf!.string!
}
@paultopia
paultopia / download_file_to_icloud.py
Created December 21, 2018 04:17
download_file_to_icloud.py
# simple pythonista/shortcuts file download to stream big files to disk from the phone
# 1. create a "downloads" directory in your icloud folder in the pythonista app.
# 2. install this shortcut: https://www.icloud.com/shortcuts/d397a0fedef74d29a5b735c371c11f89
# 3. save this script in your local files in pythonista
# then you can long press on a url and have pythonista download it and dump it in icloud.
import shutil, os, requests, sys, uuid
from urllib.parse import urlparse
url = sys.argv[-1]
@paultopia
paultopia / commoncrawl_experiment.py
Created July 5, 2018 07:12
commoncrawl_experiment.py
# adapted (mostly stolen) from:
# https://www.cedar.net.au/using-python-and-common-crawl-to-find-products-from-amazon-com/
# with conversion to python 3 + tweaks
import requests, json, io, gzip
from bs4 import BeautifulSoup
index_list = ["2018-26"]
### -----------------------
@paultopia
paultopia / monkey_patch_slicing_into_string.swift
Last active June 17, 2020 17:48
swift lets you monkeypatch your way into doing python things. :-)
/*
Swift is a lovely-looking language, but I really don't like how it doesn't
let you slice strings by grapheme and makes you create and pass in
un-ergonomic index types instead...
I recognize that unicode has a bunch of different sizes of strings, which
is why Swift doesn't wanna do that. But for small strings, which are the
kind where one might reasonably want to do a lot of Python-style slicing,
the perf cost of just iterating to get slices all the time seems, to me,
to be at least sometimes outweighed by the ergonomics on the code-writing
@paultopia
paultopia / download_humble_book_bundle.py
Created May 22, 2018 05:38
download humble book bundle
# first run the following line of javascript (minus the comment hashtag) in your browser console
# JSON.stringify(Array.prototype.slice.call(document.getElementsByTagName('a')).map(x => x.href).filter(x => x.indexOf("pdf") + x.indexOf("mobi") + x.indexOf("epub") !== -3))
# then right-click output of that, copy to clipboard, and paste into text editor as urls.json.
# I'm assuming you're using firefox here, if not, it might do something different---particularly, the double json load below handles the wonky output that firefox produces with a json wrapped in a string
# (come to think of it you can probably just read it and `loads` that, but whev.
# anyway, then run this. donezie.