This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] | |
### ----------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |