Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@paultopia
paultopia / gowder.py
Created September 28, 2016 15:40
I'm super lazy and want to be able to type, e.g., "gowder pdf test" and have it convert a markdown file to pdf without having to type flags etc. ditto "gowder dropbox test.txt"
#!/usr/bin/env python3
import sys
import os
mode = sys.argv[1]
command = sys.argv[2]
def markdown_to_pdf(root_filename):
md_filename = root_filename+".md"
pdf_filename = root_filename+".pdf"
print("converting {0} to {1}".format(md_filename, pdf_filename))
return "pandoc -o {0} {1}".format(pdf_filename, md_filename)
@paultopia
paultopia / extracttrumpinsults.py
Created October 24, 2016 16:39
python 2 script to extract trump insults from NYT article
# you can extract the text from NYT article in javascript console with document.documentElement.outerText
# nyt article is here: http://www.nytimes.com/interactive/2016/01/28/upshot/donald-trump-twitter-insults.html
# first open the file. I saved it as trumpinsults2.txt on my hard drive
# I also changed non-ascii quotes to quotes and got rid of other non-ascii stuff using sublime text, and some code I
# wrote for the purpose from here: https://github.com/paultopia/ascii_punctuation
with open("trumpinsults2.txt") as t:
insults = t.readlines()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paultopia
paultopia / euler2.clj
Last active December 8, 2016 05:10
euler problem 2 (sum even fib sequence < 4m) in clj/cljs
;; note: the extra case is to fit weird euler def. of fib seq that goes 1, 2, 3, 5, 8, 13, ... rather than 1, 1, 2, 3, 5, 8, 13
;; not nearly as cool as the fibs here: https://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci
(def fib
(memoize
(fn [n]
(case n
0 0
1 1
2 2
@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 / planckpipe.cljs
Created January 5, 2017 00:40
getting planck to pipe (saving for later use in some markdown hacks)
;; thanks Mike Fikes for helping me figure out how to do this!
#!/usr/bin/env planck
(ns panpdf.core
(:require [planck.shell :refer [sh]]))
(def s "\"#foo\nbar\"")
(sh "bash" "-c" (str "echo " s " | pandoc -o fbb.html"))
@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 = []
@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 / 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 / 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):