Stuff I Liked or Use

Take it easy, but take it.

Archive for the ‘Uncategorized’ Category

My .emacs file

without comments

As a seemingly eternal-beginner emacs user (there’s lots to learn), I
always appreciate seeing other .emacs files out there to get some
ideas. Here’s some of mine.

;; My .emacs
;; Time-stamp: <2008-11-28 20:14:23 brad@macbook-wireless .emacs>

;; Good .emacs references
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; http://www.emacswiki.org/emacs/InitFile

;; General Settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d")   ; My lisp files
(fset 'yes-or-no-p 'y-or-n-p)           ; Tired of typing 'yes'
(setq inhibit-startup-message t)        ; No startup screen
(global-font-lock-mode t)        	; Color syntax highlighting
(setq font-lock-maximum-decoration t)   ; Color as much as possible
(auto-compression-mode t)               ; Handle compressed files easily

;; Backup/Autosave
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; (orig. from http://jaderholm.com/configs/emacs)
; This will keep all backup/autosafe files in one location - much cleaner.
(defvar backup-dir (expand-file-name "~/.emacs.d/.emacs.backup/"))
(defvar autosave-dir (expand-file-name "~/.emacs.d/.emacs.autosave/"))
(setq backup-directory-alist (list (cons ".*" backup-dir)))
(setq auto-save-list-file-prefix autosave-dir)
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))

;; Org-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Load my own version (instead of site version)
(add-to-list 'load-path "~/.emacs.d/org-mode/lisp")
(require 'org-install)

; Associate org-mode w/.org files
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) 

; Easily follow links (i.e. no mouse)
(setq org-return-follows-link t)

; Let me get to some org commands from anywhere
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)

; Track state changes
(setq org-log-done t)
; I like to always track, but you can set this per file,
; See docs section 6.5.2:
; Very likely you do not want this verbose tracking all the time, so
; it is probably better to configure this behavior with in-buffer
; options. For example, if you are tracking purchases, put these into
; a separate file that starts with:
;     #+SEQ_TODO: TODO ORDERED INVOICE PAYED RECEIVED SENT
;     #+Startup: lognotestate

; Set default TODO states, basic
;(setq org-todo-keywords '("TODO" "NEXT" "STARTED" "WAIT" "DONE"))   

; Set default TODO states, with fast selection and state tracking
; from http://article.gmane.org/gmane.emacs.orgmode/6082
(setq org-use-fast-todo-selection t)
(setq org-todo-keywords
       '((sequence "TODO(t!/!)" "NEXT(n)" "|" "DONE(d!/!)")
 	(sequence "WAITING(w@/!)" "|" "CANCELLED(c!/!)")
 	(sequence "SOMEDAY(S!/!)" "|")
 	(sequence "STARTED(s!/!)" "|")
 	(sequence "DELEGATED(D@/!)" "|")
 	(sequence "OPEN(O!)" "|" "CLOSED(C!)")
 	(sequence "ONGOING(o)" "|")))
; above keyword definitions requires org-log-done or similar set in
; file, see further above

; Can I set it to require a comment coming out of a state? e.g. SOMEDAY(S@!/@!)

; Pretty up my keywords
(setq org-todo-keyword-faces
      '(("TODO"  . (:foreground "red" :weight bold))
 	("NEXT"  . (:foreground "red" :weight bold))
 	("DONE"  . (:foreground "forest green" :weight bold))
 	("STARTED"  . (:foreground "purple" :weight bold))
 	("WAITING"  . (:foreground "orange" :weight bold))
 	("DELEGATED"  . (:foreground "orange" :weight bold))
 	("CANCELLED"  . (:foreground "forest green" :weight bold))
 	("SOMEDAY"  . (:foreground "blue" :weight bold))
 	("OPEN"  . (:foreground "red" :weight bold))
 	("CLOSED"  . (:foreground "forest green" :weight bold))
 	("ONGOING"  . (:foreground "orange" :weight bold))))

; Default agenda file locations
(load-library "find-lisp")
(setq org-agenda-files (find-lisp-find-files "~/org" "\.org")) 

; Misc agenda settings
(setq org-deadline-warning-days 8)      ; Don't warn me too far out
(setq org-agenda-include-diary t)       ; show diary entries

; highlight current item in agenda mode
(add-hook 'org-agenda-mode-hook '(lambda () (hl-line-mode t)))  

; Don't show done tasks in agenda
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-deadline-if-done t)

; Exclude scheduled items from the global TODO list.
(setq org-agenda-todo-ignore-scheduled t)

; Following three functions are to switch between two org-agenda-files
; lists, so I can have home and work in separate places.  I don't
; want to have to tag everything as home/work.  Maybe someday.

(defun gohome ()
  (interactive)
;  (setq org-agenda-files (file-expand-wildcards "~/org/*.org"))
  (setq org-agenda-files (find-lisp-find-files "~/org/home" "\.org"))   ; recurse down
)

(defun gowork ()
  (interactive)
 (setq org-agenda-files (find-lisp-find-files "~/org/work" "\.org"))
)

(defun goall ()
  (interactive)
  (setq org-agenda-files (find-lisp-find-files "~/org" "\.org"))
)

; Keep clocks running across sessions
; As of Org version 6.11, clock-related data can be saved and resumed
; across Emacs sessions The data saved include the contents of
; `org-clock-history', and the running clock, if there is one. (From
; release notes)
(setq org-clock-persist t)
(setq org-clock-in-resume t)
(org-clock-persistence-insinuate)

; Make it easy to open my org files.
; plan.org just has links to frequently-used .org files.
(defun plan ()
   (interactive)
   (find-file "~/org/plan.org")
)
(global-set-key (kbd "C-c p") 'plan)   

; Tags I use (but I don't tag much), others are generally per-file.
(setq org-tag-alist '(
		      ("perl" .?p)
		      ("buy" .?b)
		      ("solaris" .?s)
		      ("unix" .?u)
		      ("emacs" .?e)
		      ("org-mode" .?o)

))

; http://www.gnu.org/software/emacs/manual/html_node/org/Remember-templates.html
; http://sachachua.com/wp/2007/12/28/emacs-getting-things-done-with-org-basic/
; http://members.optusnet.com.au/~charles57/GTD/remember.html
(setq org-remember-templates '(
	("Tasks" ?t "* TODO %?\n  %U\n" "~/org/Remember.org" "Tasks")
	("WorkTODO" ?w "* TODO %?\n  %U\n" "~/org/work/IBM.org" "Remembered Tasks")
	("Link" ?l "* %?\n  %i\n  %a" "~/org/Remember.org" "Links")
	("Stuff" ?s "* %?\n  %i\n  %U" "~/org/Remember.org" "Stuff")
        ("Appointments" ?a "* Appointment: %?\n%^T\n%i\n  %a" "~/org/Remember.org")
        ("Journal" ?j "* %U %?\n\n  %i" "~/org/Journal.org")
        ("Idea" ?i "* %^{Title}\n  %i\n  %a" "~/org/Remember.org" "New Ideas")
        ("EmacsTip" ?e "* %?\n  %i\n" "~/org/EmacsTips.org")
))

; Below to hook the templates into remember
(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(eval-after-load 'remember
  '(add-hook 'remember-mode-hook 'org-remember-apply-template))

(global-set-key (kbd "C-c r") 'remember)    ; get to remember from anywhere

; Set footnote-prefix in footnote.el to C-c F to not stomp org mode
; Had to set this in my own site footnote.el file, actually.  Gotta
; find out why I can't remap here.
;(defvar footnote-prefix [(control ?c) ?F]
;  "*When not using message mode, the prefix to bind in `mode-specific-map'")

; http://orgmode.org/worg/org-hacks.php#sec-9
; Remove time grid lines that are in an appointment

;(defun org-time-to-minutes (time)
;  "Convert an HHMM time to minutes"
;  (+ (* (/ time 100) 60) (% time 100)))
;(defun org-time-from-minutes (minutes)
;  "Convert a number of minutes to an HHMM time"
;  (+ (* (/ minutes 60) 100) (% minutes 60)))
;(defadvice org-agenda-add-time-grid-maybe (around mde-org-agenda-grid-tweakify
;                                                  (list ndays todayp))
;  (if (member 'remove-match (car org-agenda-time-grid))
;      (flet ((extract-window
;              (line)
;              (let ((start (get-text-property 1 'time-of-day line))
;                    (dur (get-text-property 1 'duration line)))
;                (cond
;                 ((and start dur)
;                  (cons start
;                        (org-time-from-minutes
;                         (+ dur (org-time-to-minutes start)))))
;                 (start start)
;                 (t nil)))))
;        (let* ((windows (delq nil (mapcar 'extract-window list)))
;               (org-agenda-time-grid
;                (list (car org-agenda-time-grid)
;                      (cadr org-agenda-time-grid)
;                      (remove-if
;                       (lambda (time)
;                         (find-if (lambda (w)
;                                    (if (numberp w)
;                                        (equal w time)
;                                      (and (>= time (car w))
;                                           (< time (cdr w)))))
;                                  windows))
;                       (caddr org-agenda-time-grid)))))
;          ad-do-it))
;    ad-do-it))
;(ad-activate 'org-agenda-add-time-grid-maybe)

;; Remember mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Make sure we have it
(add-to-list 'load-path "~/.emacs.d/remember")
(require 'remember)

;; Git
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Commit org files to git repository after save

(defun git-commit ()
  (when (or
	 (eq major-mode 'org-mode)
;	 (eq major-mode 'cperl-mode)
;	 (eq major-mode 'sh-mode)
	 (eq major-mode 'emacs-lisp-mode))
    (shell-command "git commit -a -m 'Auto commit.'")))
; Set a name for each revision, maybe just the date?

(add-hook 'after-save-hook 'git-commit)

;; Diary
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sort my diary entries nicely while I'm at it (calendar mode, which I
; rarely use.  But it sounded cool.  :)
; http://www.emacswiki.org/cgi-bin/wiki/DiaryMode
(add-hook 'list-diary-entries-hook 'sort-diary-entries t)

;; weblogger.el, easy posting to wordpress
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d/weblogger")
(require 'weblogger)

;; Misc little functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; easy-open .emacs
(defun myemacs ()
  (interactive)
  (find-file "~/.emacs.d/init.el"))
(defun doemacs ()
  (interactive)
  (load-file "~/.emacs.d/init.el"))

; I use an org remember template now, so this is lonely...
(defun journal ()
  (interactive)
  (find-file "~/Documents/books/journal.txt")
  (end-of-buffer)
  (insert "\n\n")
  (insert "*")
  (insert-time)
  (insert "\n\n"))

;; writeroom
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Just for Aquamacs at home, low-distraction style
(defun writeroom ()
  "Switches to a WriteRoom-like fullscreen style"
  (interactive)
  (when (featurep 'aquamacs)
					; switch to Garamond 36pt
    (set-frame-font "-apple-garamond-medium-r-normal--18-180-72-72-m-360-iso10646-1")
					; switch to white on black
    (color-theme-initialize)
    (color-theme-clarity)
					; switch to fullscreen mode
    (aquamacs-toggle-full-frame)))

;; fill-buffer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;http://www.dotfiles.com/files/6/409_.emacs_1
(defun fill-buffer ()
  "Fill each of the paragraphs in the buffer."
  (interactive)
  (let ((beg (point-min))
	(end (point-max)))
    (fill-region beg end)))

;; timestamper
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Really, what I want is to make this mode-sensitive.  So, if in
; emacs-lisp, do ;comment, in perl do #, in html blah blah

(defun insert-date-time ()
 (interactive)
  (insert (format-time-string "#@%Y-%m-%d %H:%M:%S "))
  (insert (user-login-name))  (insert "@")
  (insert (system-name))
)
(global-set-key "\C-ct" 'insert-date-time)  ; C-c 'time'

(defun insert-time-only ()
 (interactive)
  (insert (format-time-string "%H:%M:%S "))
)
(global-set-key "\C-cn" 'insert-time-only)   ; C-c 'now'

;; Time-stamp hook, autotimestamp files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S %u@%s %f")
(add-hook 'write-file-hooks 'time-stamp)
(setq time-stamp-line-limit 16)

; And insert stamp hook where I want it
(defun stamp ()
  "Insert Time-stamp hook at point."
  (interactive "*")
  (insert "Time-stamp: <>")
  (time-stamp)
  )

;; Bcrypt open file
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun open-encrypted-file (fname)
  (interactive "FFind file: n")
  (let ((buf (create-file-buffer fname)))
    (shell-command
     (concat "echo " (read-passwd "Decrypt password: ") " | bcrypt -o " fname)
     buf)
    (set-buffer buf)
    (kill-line)(kill-line)
    (toggle-read-only)
    (not-modified))
  )

;; epg stuff (gpg for Emacs)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d/epg")
(require 'epa-setup)
; M-x epa- to browse options

; transparent, automatic encryption
(epa-file-enable)

;; w3m
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; http://emacs-w3m.namazu.org/
(add-to-list 'load-path "~/.emacs.d/emacs-w3m")
(require 'w3m-load)
(setq w3m-use-cookies t)   

;; emacsserver
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(server-start)

Written by Brad

November 18th, 2008 at 10:26 pm

Posted in Uncategorized

Posting to WordPress from Emacs

without comments

See it all here ->
http://www.tolchz.net/2008/01/06/posting-to-wordpress-with-emacs-webloggerel/

To post:weblogger-start-entry
C-x C-s to save and submit
C-c C-c to save as draft

To edit:weblogger-fetch-entries
Next: C-c C-p
Prev C-c C-n

Written by Brad

October 14th, 2008 at 9:17 pm

Economist Jokes

without comments

Culled largely from http://freakonomics.blogs.nytimes.com/2008/09/15/our-daily-bleg-econ-jokes-needed


The First Law of Economics:

For every economist, there is an equal and opposite economist.

The corollary:
They’re both wrong.


This was originally about a mathematician, a physicist, and an engineer but I will adapt it.

An economist, a sociologist and a psychologist were walking down the street and passed a butcher shop which had a sign in the window which said: Psychologists brains $25/lb, Sociologists brains $50/lb, Economists brains $100/lb.

The economist was elated and said to his friends, “See, I always told you economists’ brains were higher quality than yours.” He then insisted that they ask the butcher how he had reached the same conclusion.

The three then entered the shop. When the economist asked the butcher why the economist brains were so much more valuable than the others, the butcher replied, “Listen, do you realize how many economists you have to kill to get a pound of brains?”


Three economists decide that they want to go deer hunting. They do a whole slew of research, and finally come up with the perfect place and time to catch a deer while everybody they know is snickering at their efforts. So, on the appointed day, at the appointed time, they set out to the forest with their gear and walk to the appointed clearing, and sure enough, there’s a ten-point buck standing there.

The first economist takes aim at the buck and fires: BLAM! He misses just to the right of the buck. The buck lifts its head, but isn’t scared off by the noise.

Now, the second economist takes aim at the buck and fires: BLAM! He misses just to the left! Still, the buck seems untroubled by the noise.

The third economist takes aim at the buck, carefully lining up his sights, and fires: BLAM! His shot goes just over the top of the buck.

All of the economists look at eachother and yell out “Success!”


A lady sent her little boy off to Sunday School. She gave him two dimes–one for the offering and one for himself.

But along the way, he tripped and one of the dimes got away from him and rolled down a storm drain. He could not retrieve it.

After church, when he returned home, his mother asked him about his day.

“On the way to church, I lost God’s dime.”

“What? How did you know it was God’s dime?”

“‘Cause the other one was mine!”


How can you tell an extroverted economist from an introverted one? The extrovert looks at YOUR shoes when he’s talking to you.


What do you call a bus full of economists with one empty seat going over a cliff?  A lost opportunity.


This one is a Physics joke, but is easily adaptable.

There is this farmer who is having problems with his chickens. All of the sudden, they are all getting very sick and he doesn’t know what is wrong with them. After trying all conventional means, he calls a biologist, a chemist, and a physicist to see if they can figure out what is wrong. So the biologist looks at the chickens, examines them a bit, and says he has no clue what could be wrong with them. Then the chemist takes some tests and makes some measurements, but he can’t come to any conclusions either. So the physicist tries. He stands there and looks at the chickens for a long time without touching them or anything. Then all of the sudden he starts scribbling away in a notebook. Finally, after several gruesome calculations, he exclaims, ‘I’ve got it! But it only works for spherical chickens in a vacuum.’


from the preface to Paul Krugman’s book, “Peddling Prosperity: Economic Sense and Nonsense in the Age of Diminished Expectations” (1994, page xi): An Indian-born economist once explained his personal theory of reincarnation to his graduate economics class. “If you are a good economist, a virtuous economist,” he said, “you are reborn as a physicist. But if you are an evil, wicked economist, you are reborn as a sociologist.”


Two men are flying in a captive balloon. The wind is ugly and they come away from their course and they have no idea where they are. So they go down to 20 m above ground and ask a passing wanderer. “Could you tell us where we are?”

“You are in a balloon.”

So the one pilot to the other:

“The answer is perfectly right and absolutely useless. The man must be an economist”

“Then you must be businessmen”, answers the man.

“That’s right! How did you know?”

“You have such a good view from where you are and yet you don’t know where you are!”


Written by Brad

September 17th, 2008 at 7:19 am

Posted in Uncategorized