Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
@paultopia
paultopia / navbar.cljs
Last active June 7, 2018 22:29
Floating navbar with only a single css property changed (thanks to the magic of reagent, a clojurescript interface to react)
;; I think this will work. It's extracted from a working version here:
;; https://github.com/paultopia/stdio (mostly in the nav namespace)
;; so if you try this and it doesn't work, I probably left something off, feel free to go to the original.
(ns navbar.core
(:require [reagent.core :as r :refer [render atom]]))
(defn loren [reps]
(apply str (take reps (repeat "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
@paultopia
paultopia / spacemacs.md
Last active November 7, 2016 02:52
everything I've managed to learn so far about spacemacs (gist can't handle pandoc tables, view in raw)

so it turns out pandoc markdown + github + lots of symbols = sadness and chaos. Here's a slightly less ugly version, though still pretty uggo:* http://paul-gowder.com/emacs.html

Actually getting Spacemacs to do stuff

(Notes, mostly to self, and based on my own needs. Shared in case others need too.)

Absolute basics

Emacs but with vim keybindings.

@paultopia
paultopia / regex-label-extraction.py
Created May 26, 2016 00:13
add labels for regex to dict of data
# Common data cleaning pattern: you need to find regex matches in some block of text, stored w/ labels in a
# dictionary (i.e., from json), extract those matches, and store them as an additional labels.
# here's a quick and dirty utility function to do so. can then be used in loop or listcomp over entire dataset
import re
from collections import Counter
def pattern_extractor(instance, pattern, textlabel, newlabel):
found = re.findall(pattern, instance[textlabel])
if found:
if isinstance(found[0], (list, tuple)):
matches = [filter(None, x)[0] for x in found]
@paultopia
paultopia / gradecheck.py
Last active May 19, 2016 22:38
for future personal reference: just compare filenames to grade CSV to make sure no grades are missed.
import csv, glob
examfiles = [x[0:4] for x in glob.glob("*.pdf")]
with open("count.csv", 'rU') as grades:
gradelist = [x[0] for x in csv.reader(grades, dialect=csv.excel_tab)]
# but csv is shit so:
grades = [x[0:4] for x in gradelist]
missinggrades = []
for i in examfiles:
if i not in grades:
missinggrades.append(i)
@paultopia
paultopia / filter-by-other.clj
Last active May 5, 2016 19:56
filter one vector based on applying the predicate to a different vector, in clojure.
(defn filter-by-other
[target test pred]
(let [pairs (map vector target test)]
(mapv first (filter #(pred (second %)) pairs))))
; filters target based on applying pred to test. probably will blow up with infinite sequences, and god only knows what will
; happen with lazy ones. Assumes target and test are vectors of equal length, pred is a single-arity function
;
; EXAMPLE:
; (filter-by-other [:a :b :c :d] [1 2 3 4] even?)
# convert a directory full of M$word .docx files to PDF
# REQUIREMENTS:
# 1. Only works on Mac.
# 2. Assign the variable USERNAME to your home directory
# 3. Requires the PDFwriter printer driver, get it here: https://sourceforge.net/projects/pdfwriterformac/
# 3.5 (might require PDFwriter to be your default printer; on my machine it's the only printer, so I haven't tested with any other config
# 4. Requires the launch and appswitch apps from the wonderful Nicholas Riley, get them here: http://sabi.net/nriley/software/
import glob, os, time
homedir = os.getcwd()
@paultopia
paultopia / upload.py
Last active February 7, 2016 21:24
Hacktastic quick ftp upload (for one-line web deployment etc.)
""" see http://stackoverflow.com/questions/35245929/python-ftplib-hangs-on-upload-stor-and-not-network-latency for the ftplib hell that led here
Obvs replace [SERVER] [USER] and [PASSWORD] with appropriate values, and add to the list of ascii extensions for whatever you use.
"""
import sys
import os
import datetime as dt
full = sys.argv[1]
path = 'public_html/' + full[:full.rfind('/') + 1]
@paultopia
paultopia / never_do_this.py
Last active June 3, 2016 22:10
never_do_this.py
# NEVER DO THIS EXCEPT AS A PRANK ON YOUR WORST ENEMY
class foo(str):
def __call__(self):
try:
exec self
except Exception:
pass
str = foo
@paultopia
paultopia / worst_python_ever.py
Last active December 30, 2015 03:44
worst_python_ever.py
# I think I've discovered a bit of Python code even more dangerous than https://github.com/ajalt/fuckitpy
class string(str):
def __call__(self):
try:
exec self
except Exception:
pass
evil = string('print "EVIL"')
@paultopia
paultopia / scrapewrap.py
Last active December 29, 2015 17:39
scrapewrap.py
import sys
import spideyscrape
import console
import os
args = sys.argv[1:] # see if the user gave us a command line argument
start = args[0] if args else raw_input('URL to crawl: ')
html = spideyscrape.scrape(start)
filename = spideyscrape.savePage(html)
console.open_in(filename)