Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@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
# 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 / 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!
@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"
function tweetstorm(instring) {
var currentTweet = "";
var tweets = [];
var words = instring.split(" ");
for (let item of words) {
if (currentTweet.length + item.length + 9 < 280) {
currentTweet = currentTweet + " " + item;
} else {
tweets.push(currentTweet);
@paultopia
paultopia / simple_regression.py
Created April 13, 2019 02:07
simple_regression.py
import numpy as np
def beta(x, y):
mean_x = np.mean(x)
mean_y = np.mean(y)
numerator = 0
for pair in zip(x, y):
numerator += (pair[0] - mean_x) * (pair[1] - mean_y)
denominator = np.sum([np.square(item - mean_x) for item in x])
return numerator / denominator
@paultopia
paultopia / evalme.cljs
Created March 24, 2019 03:37
Just an experiment with evaling from http
(defn hello [] (print "hello world"))
(hello)
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import json
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/documents.readonly']
@paultopia
paultopia / arrayMove.swift
Created February 10, 2019 04:57
just holding onto this for myself: reshuffling an array with generics
let arr = ["a", "b", "c"]
let arr2 = [1, 2, 3]
func moveOver<Item>(_ arr: [Item], start: Int, dest: Int) -> [Item] {
var out = arr
let rem = out.remove(at: start)
out.insert(rem, at: dest)
return out
}
moveOver(arr, start: 0, dest: 2)