Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@paultopia
paultopia / twitter-dejerk.py
Last active March 30, 2017 21:44
twitter-dejerk.py
# written for pythonista ios app, takes advantage of its library and access to ios twitter login. generates a list of followers who don't follow you back and lets you look at each individually to decide whethee to dispose of them or not. Only works for followers < 5000 amd following < 5000, else rate limits and cursors get imvolved and are icky. could use a real UI.
import twitter, json, webbrowser, random
account = twitter.get_all_accounts()[0]
followers = frozenset(json.loads(twitter.request(account, "https://api.twitter.com/1.1/followers/ids.json", "GET")[1].decode("utf-8"))["ids"])
ifollow = frozenset(json.loads(twitter.request(account, "https://api.twitter.com/1.1/friends/ids.json", "GET")[1].decode("utf-8"))["ids"])
not_following_back = list(ifollow.difference(followers))
def make_url(id):
return 'https://twitter.com/intent/user?user_id=' + str(id)
turls = [make_url(id) for id in not_following_back]
@paultopia
paultopia / ordered-partitions.cljs
Created March 16, 2017 16:46
Replacement for clojure.math.combinatorics/partitions that preserves ordering --- see discussion at https://groups.google.com/forum/m/#!topic/clojure/DoEMT45VpAo
(require '[clojure.math.combinatorics :as c])
(defn breaks->partition
([v brks]
(breaks->partition 0 [] v brks))
([start pars v brks]
(if (empty? brks)
(conj pars (subvec v start (count v)))
(let [this-part (subvec v start (first brks))]
(recur (first brks) (conj pars this-part) v (rest brks))))))
@paultopia
paultopia / script-from-dropbox.py
Last active March 28, 2017 18:34
Easy pythonista script to use from dropbox iOS app share sheet to take dropbox link to python script and save it to pythonista filesystem. Also works with "raw" python scripts from github and gists.
import requests, appex
from urllib.parse import urlparse
url = appex.get_url().replace("dl=0", "dl=1")
r = requests.get(url)
filename = urlparse(url).path.rpartition("/")[-1].replace(".py", "-downloaded.py")
with open(filename, "wb") as outfile:
outfile.write(r.content)
print("script downloaded as " + filename)
@paultopia
paultopia / md-docx.py
Last active March 9, 2017 20:17
Simple Pythonista script to convert markdown to docx using docverter and then save inside pythonista filesystem.
import requests
import appex
url = "http://c.docverter.com/convert"
filename = appex.get_file_path()
with open(filename, 'rb') as f:
r = requests.post(url, data={'to':'docx','from':'markdown'},files={'input_files[]':f})
if r.ok:
outfile = filename.rpartition('/')[-1].rpartition('.')[0] + '.docx'
with open(outfile, 'wb') as o:
o.write(r.content)
@paultopia
paultopia / clean_lines.py
Last active January 25, 2017 04:21
Quick and dirty clean up stray line breaks for, e.g., copy-pasted or OCRed text where paragraphs are separated by double line breaks or line-break-tabs and lines w/in paragraphs are separated by single line breaks, but you want paragraphs to be one long line separated by double-breaks.
import re
def tab_paras_to_double_lines(s):
return re.sub("\n\t", "\n\n", s)
def de_leading_trailing(s):
s1 = re.sub(" \n", "\n", s)
return re.sub("\n ", "\n", s1)
def fix_unspaced(mobj):
m = mobj.group(0)
@paultopia
paultopia / dfs.cljs
Last active January 16, 2017 08:45
Depth-first search in clojurescript
#!/usr/bin/env planck
;; note: I haven't included any lein or boot tooling since there are no
;; dependencies. the easiest way to run is to use planck on osx, as a script.
;; can also be easily adapted to normal clojure or have some tooling added if you want to
;; run it and don't have a mac
(ns dfs.core
"depth-first search of tree. Makes a few assumptions for simplification purposes:
1. tree is directed graph
@paultopia
paultopia / twitterpost.py
Created January 16, 2017 01:08
simple post to twitter (requires tweepy) that strips away complicated tweepy api. requires setting up application and consumer tokens and keys per tutorial here: https://www.digitalocean.com/community/tutorials/how-to-create-a-twitter-app and then putting them in a json file.
import tweepy, json
def twitter_poster(json_creds):
"""Pass me a json file with twitter creds.
Fields:
'consumer_key',
'consumer_secret
'access_token',
'access_secret',
which are all in the order given in the twitter dev page
@paultopia
paultopia / hashurl.py
Created January 15, 2017 21:49
hashurl.py
from requests import get
from shutil import copyfileobj
from hashlib import sha256
import gzip
testhtml = "http://paul-gowder.com/curve/index.html"
testbinary = "http://paul-gowder.com/penguin-square.jpg"
# fetch and save to file
def fetch_and_save(url, name):
@paultopia
paultopia / ipad-remote.sh
Created January 13, 2017 21:43
work in progress remote-coding-platform insta-install script
# Ubuntu 16.10 32bit on smallest digitalocean droplet
# Operating as root
# point of this is to have something I can ssh into from iPad to compile and run stuff
# I've run all this stuff interactively, but I think it should work as a shell script... tried to put force confirmation in everything.
# apologies if something blows up, or hangs waiting for confirmation; work in progress
# make sure all is good in the world
apt-get update
@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