Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@paultopia
paultopia / zotero_add.py
Created April 4, 2020 21:18
hacking together zotero magic add
import requests
import json
import os
from copy import deepcopy
APIKEY = os.environ["ZOTEROKEY"]
ACCOUNT = os.environ["ZOTEROACCOUNT"]
TESTITEM = '10.2307/4486062' # just the same example item used on https://github.com/zotero/translation-server
def get_item_from_identifier(identifier):
endpoint = "http://zotglitch.glitch.me/search"
@paultopia
paultopia / read_apple_notes.ipynb
Created January 21, 2018 21:20
attempt to read apple notes from python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paultopia
paultopia / safe-merge.clj
Last active September 4, 2023 22:16
merge for clojure that doesn't overwrite existing values with nil values
(require '[clojure.core.match :refer [match]])
(defn discard-nils [a b]
(match [a b]
[_ nil] a
:else b))
(def safe-merge (partial merge-with discard-nils))
;; examples
@paultopia
paultopia / bluesky_thread.py
Last active August 21, 2023 02:00
post bluesky tweet thread
# Quick and dirty script to post a bluesky thread via API
# because I hate having to manually break up long text at character count limits
# largely adapted/swiped from the more full-featured library at https://github.com/ianklatzco/atprototools/tree/master
import requests
import datetime
import textwrap
import appex # this is a pythonista (ipad/ios python app) library for share sheet functionality, omit on real computer
import sys
import keychain # pythonista library, for a real computer use envirnoment variables instead
@paultopia
paultopia / bluesky_post.py
Created August 20, 2023 17:02
quick and dirty bluesky posting script
# Quick and dirty script to post via API, mostly for the purposes of
# making threads without having to manually break up at character count breaks (in version 2)
# largely adapted/swiped from the more full-featured library at https://github.com/ianklatzco/atprototools/tree/master
import requests
import datetime
# Authentication information
# n.b.: ketchain is a pythonista (ipad/ios python app) library, for a real computer use envirnoment variables instead
import keychain
@paultopia
paultopia / backup-to-git.py
Last active July 16, 2023 07:32
quick python script to run to backup on an unversioned directory (like dropbox, icloud, where git would break) of files with given extension to git repo. Just modify the first three lines, and stick the target directory in a private github repo or something
#!/usr/bin/env python
target_dir = "FULL_PATH_TO_YOUR_TARGET_DIRECTORY_WITH_GIT_REPO" # example: /Users/you/github/backup/
source_dir = "FULL_PATH_TO_YOUR_TARGET_DIRECTORY_WITH_NO_GIT" # example: /Users/you/Dropbox/ImportantDocuments/
extensions = ["txt", "md"] # example list of extensions to copy, change to suit you.
import glob, shutil, subprocess, os
source_wildcards = [source_dir + "*." + x for x in extensions]
source_filenames = []
# PROBLEM: Zotero loves to grab the URL and last accessed date of articles and books and such when you use the
# zotero browser extensions to get them into the citation manager. Then those things incorrectly show up in your
# automatically generated citations, e.g., when using the bluebook citation format.
# And it's really obnoxious to delete them all by hand either in the output or zotero.
# SOLUTION: use CSL json as your output for processing with pandoc or whatever (which you should be doing anyway)
# and then interpose this little script between the raw CSL json file and cleaned up CSL json file with the URLs etc.
# stripped.
# USAGE: "python clean_cite_json.py YOUR_EXISTING_CITATION_FILE NEW_FILENAME_FOR_CLEAN_FILE"
@paultopia
paultopia / .spacemacs
Last active May 10, 2021 09:44
A quick and dirty .spacemacs for my digitalocean minimal droplet, to be used from iPad.
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@paultopia
paultopia / upload.cljs
Created December 21, 2016 21:50
clojurescript read uploaded text file in browser (derived from https://mrmcc3.github.io/post/csv-with-clojurescript/ )
(ns upload-file.core
(:require [reagent.core :refer [render atom]]
[cljs.core.async :refer [put! chan <! >!]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
;; derived from https://mrmcc3.github.io/post/csv-with-clojurescript/
;; and based on reagent-frontend template.
;; dependencies from project.clj in addition to clojure, clojurescript, and reagent:
;; [org.clojure/core.async "0.2.395"]
@paultopia
paultopia / solve_string.py
Created October 5, 2020 02:22
Do string-based math with pythonista. mostly because I don't want to buy a fancy string calculator app when I already have python available.
# for the pythonista ios app (which comes with sympy bundled)
# allows one to create a text file, for example in drafts, containing the string
# x - (9 * 5) = x / 2
# and then share it into this pythonista script (or copy it to clipboard and run the script)
# and get the answer (90) back.
# see comments at end for more examples of stuff that it can solve.
#
# I wrote this because it annoys me that there are paid apps that do ticker tape calculator kinds of
# things. Why should I pay extra to add up a list of numbers whilst still getting to see the numbers when
# I have a whole programming language available to me!