Skip to content

Instantly share code, notes, and snippets.

View alphapapa's full-sized avatar

Adam Porter alphapapa

  • USA
View GitHub Profile
@alphapapa
alphapapa / w
Created November 7, 2014 05:02
w: Print summary of Wikipedia article to STDOUT
#!/usr/bin/env python
# Requires wikipedia module. '$ pip install wikipedia' Put it in your
# path and 'chmod +x'. Then just 'w whatever' and find out what
# something is! :D
# I couldn't find a good command-line utiity to do this.
# wikipedia2text is okay but it does the whole page, which isn't
# always what I want. The old command 'dig +short txt "$1.wp.dg.cx"'
# doesn't work anymore. But this works well.
@alphapapa
alphapapa / print-firefox-session.py
Last active September 17, 2015 06:39
Pretty-print the last Firefox session's windows, tabs, and URLs. Useful for when Firefox fails to correctly reload a tab on start, and you have no idea what was loaded in that tab, but you know it was important.
#!/usr/bin/env python
import datetime, json, sys
def formatEntry(entry):
return "%s (%s) (%s)" % (entry['title'].encode('utf8')
if entry.has_key('title') else "<untitled>",
entry['url'].encode('utf8'),
datetime.datetime.fromtimestamp(
int(tab['lastAccessed']) / 1000).strftime('%Y-%m-%d %H:%M:%S'))
@alphapapa
alphapapa / _percol_bind_keys.fish
Last active September 30, 2015 03:21
Fish functions and bindings for finding directories and files with Percol and locate
#!/usr/bin/fish
set -g percolOptions --prompt-bottom --result-bottom-up
# This is simply too slow right now, so using Bash instead
function onlyDirs
while read dir
test -d $dir
and echo $dir
end
@alphapapa
alphapapa / _reader-macros.md
Created October 26, 2015 04:34 — forked from chaitanyagupta/_reader-macros.md
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

(defun change-inner (prefix character)
"Kill region inside delimiters, using either beginning or
ending delimiter. With prefix arg, kill including delimiters."
(interactive "p\nc")
(let ((initial-point (point))
(start)
(end)
(move-point-by (if (> prefix 1) 0 1)))
Read ESV in 90 sessions (Ultimate: Gosp+Ac, Rom-Rev)
[ ] October 31, 2015 Gen 1–9, Matt 1–2, Rom 1, Ps 1–3, Prov 1:1–7
[ ] November 01, 2015 Gen 10–19, Matt 3:1–5:12, Rom 2:1–3:8, Ps 4–6, Prov 1:8–19
[ ] November 02, 2015 Gen 20–26, Matt 5:13–6:15, Rom 3:9–4:12, Ps 7–8, Prov 1:20–33
[ ] November 03, 2015 Gen 27–32, Matt 6:16–7:29, Rom 4:13–5:21, Ps 9, Prov 2:1–10
[ ] November 04, 2015 Gen 33–41, Matt 8–9, Rom 6–7, Ps 10–12, Prov 2:11–22
[ ] November 05, 2015 Gen 42–50, Matt 10, Rom 8, Ps 13–16, Prov 3:1–12
[ ] November 06, 2015 Exod 1–8, Matt 11:1–12:21, Rom 9:1–29, Ps 17, Prov 3:13–18
[ ] November 07, 2015 Exod 9–16, Matt 12:22–13:30, Rom 9:30–10:21, Ps 18, Prov 3:19–26
@alphapapa
alphapapa / org-agenda-subtree-or-region.el
Last active March 21, 2016 10:46
Emacs: Display org-agenda for current subtree or region
(defun org-agenda-subtree-or-region (prefix)
"Display an agenda view for the current subtree or region.
With prefix, display only TODO-keyword items."
(interactive "p")
(let (header)
(if (use-region-p)
(progn
(setq header "Region")
(put 'org-agenda-files 'org-restrict (list (buffer-file-name (current-buffer))))
(setq org-agenda-restrict (current-buffer))
@alphapapa
alphapapa / ap-comment-dwiw.el
Last active April 2, 2016 22:05
Yet another comment-do-what-I-want function
(defun ap/comment-dwiw (prefix)
"Add/remove comments from code.
With prefix, uncomment region or remove commented lines.
More specifically:
With active region:
* With prefix: Uncomment region.
* Without prefix: Comment/uncomment region.
@alphapapa
alphapapa / diskchecker.pl
Created April 18, 2016 04:11 — forked from bradfitz/diskchecker.pl
diskchecker.pl
#!/usr/bin/perl
#
# Brad's el-ghetto do-our-storage-stacks-lie?-script
#
sub usage {
die <<'END';
Usage: diskchecker.pl -s <server[:port]> verify <file>
diskchecker.pl -s <server[:port]> create <file> <size_in_MB>
diskchecker.pl -l [port]
@alphapapa
alphapapa / filter-buffer.el
Created April 22, 2016 09:44 — forked from wasamasa/filter-buffer.el
Emacs buffer filtering
(defun my-filter-current-buffer (program &rest args)
(let* ((stdout-buffer (generate-new-buffer " stdout"))
(ret (apply 'call-process-region (point-min) (point-max) program
nil (list stdout-buffer) nil args)))
(when (zerop ret)
(let ((output (with-current-buffer stdout-buffer
(buffer-string))))
(erase-buffer)
(insert output)))
(kill-buffer stdout-buffer)))