Skip to content

Instantly share code, notes, and snippets.

View alphapapa's full-sized avatar

Adam Porter alphapapa

  • USA
View GitHub Profile
@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'))
@chrp
chrp / fanny.rb
Created August 12, 2013 15:21
Auto adjust fan speed of graphics card with ATI catalyst driver on Ubuntu.
#!/usr/bin/env ruby
# encoding: utf-8
# first part, get temperature
temp_str = `aticonfig --adapter=0 --od-gettemperature`
temp = temp_str.scan(/Sensor 0: Temperature - (\d+\.\d+) C/)[0][0].to_i
# determine fan speed
thresholds = [ 40, 60, 70, 80, 85 ]
speeds = [ 10, 25, 30, 35, 50 ]
@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))
@amzyang
amzyang / createshortcut.js
Created November 29, 2011 07:03
create pentadactyl commandline options
// createshortcut.js -- ++pentadactyl
// @Author: eric.zou (frederick.zou@gmail.com)
// @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
// @Created: Tue 29 Nov 2011 01:24:05 PM CST
// @Last Change: Tue 29 Nov 2011 02:23:36 PM CST
// @Revision: 41
// @Description:
// @Usage:
// @TODO:
// @CHANGES:
@wzhd
wzhd / .gitignore
Last active December 20, 2016 09:17 — forked from xiaoganghan/mynote.xml
Parsing Evernote export file (.enex) using Python
*.enex
@alphapapa
alphapapa / outline-mode-folding-python-elisp-shell.el
Created March 22, 2015 08:23
Emacs: outline-mode folding for Python, elisp, and shell
(defun my/python-mode-outline-hook ()
(setq outline-level 'my/python-outline-level)
(setq outline-regexp
(rx (or
;; Commented outline heading
(group
(* space) ; 0 or more spaces
(one-or-more (syntax comment-start))
(one-or-more space)
@alphapapa
alphapapa / better-org-return.el
Last active April 13, 2017 16:12
Better org-return
(defun ap/org-return (&optional ignore)
"Add new list item, heading or table row with RET.
A double return on an empty element deletes it. Use a prefix arg
to get regular RET. "
;; See https://gist.github.com/alphapapa/61c1015f7d1f0d446bc7fd652b7ec4fe and
;; http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
(interactive "P")
(if ignore
(org-return)
(cond ((eq 'link (car (org-element-context)))
@alphapapa
alphapapa / org-avy-refile-as-child.el
Last active April 24, 2017 01:23
org-avy-refile-as-child: Refile Org heading as child of heading selected with Avy
(defun ap/org-avy-refile-as-child ()
"Refile current heading as first child of heading selected with `avy.'"
;; Inspired by `org-teleport': http://kitchingroup.cheme.cmu.edu/blog/2016/03/18/Org-teleport-headlines/
(interactive)
(let* ((org-reverse-note-order t)
(pos (save-excursion
(avy-with avy-goto-line (avy--generic-jump (rx bol "*") nil avy-style))
(point)))
(filename (buffer-file-name (or (buffer-base-buffer (current-buffer))
(current-buffer))))
;;; Neat convenience function for working with Elisp's EIEIO objects
(defmacro oref* (object &rest slots)
"Like `oref', but each slot in SLOTS is applied in sequence.
For example,
\(oref* obj :inner :property)
is equivalent to
@alphapapa
alphapapa / dash-dollar.el
Created September 7, 2017 08:23
Emacs Lisp: -$ macro
(defmacro -$ (&rest body)
(cl-labels ((collect-vars
(&rest forms)
(cl-loop for form in forms
append (cl-loop for atom in form
if (and (symbolp atom)
(string-match (rx bos "$")
(symbol-name atom)))
collect atom
else if (consp form)