Saturday, February 27, 2010

(provide 'git-addendum)

So the git addons I wanted to write are finished and working perfectly. They're really simple, but they completely annihilate my need to go to terminal during my daily hacking.

  ;;Addendum to the built-in GIT library for Emacs
  (defun git-init (directory)
  "Initializes the given directory as a GIT repo, then runs git-status on it"
  (interactive "DSelect directory: ")
  (cd directory)
  (shell-command "git init ")
  (git-status directory))

  ;;added (define-key map "\C-p" 'git-pull) to git-status-mode-map in git.el
  (defun git-pull (remote-dir)
  "Pulls from a directory. Typical input is 'user@remote-machine:directory maste'"
  (interactive "sSelect remote dir and branch: ")
  (unless git-status (error "Not in git-status mode"))
  (shell-command (concat "git pull " remote-dir))

  (provide 'git-addendum)

I'm actually highly surprised that git.el doesn't just come with these, as they seem obvious and easy. I sent it over to 'gitster at pobox dot com', which is the listed email of its maintainer. Not sure whether it'll come to anything, but in the meanwhile, at least I get to use it.

Friday, February 26, 2010

(define (upgrade-9.10) (

So I've upgraded to ubuntu 9.10. They've put a lot of effort into making the UI more consistant, which is nice I guess. Also, it's shaved off a further four seconds from my startup routine; the system itself now starts up about 2 seconds faster, and they changed the login screen so that I can just hit <ret> instead of typing in my user name (which saved the other two seconds).

That's really not why I finally decided to ugrade though this is. Ubuntu 9.20 has apt-get support for emacs 23, and I really didn't feel like going through a manual install from their ftp site. That seems like something I'd have had to do in 1998, not 12 years after the fact.

A few things were obsoleted, but noting important. Though, you may wanna take that with a grain of salt. Like I said last time, I basically live in Emacs, Gimp/Inkscape and Chrome now. Ok, and every once in a while I'll drop into DrScheme for the macro-stepper, Klavaro for keyboard practice or into terminal because Emacs' GIT mode doesn't provide git-init or git-pull (funny story, I actually got Emacs 23 because it supports tab completion when executing shell commands, which would let me write my own little add-ons for those two git commands to obviate the terminal entirely).

Anyway, my point is: the list of applications that I use is short. None of the above have broken, but if you use other programs, check whether they're still supported (one I was surprised to see obsoleted was gcc 4.3, so it doesn't hurt to check).

My .emacs is getting fatter, by the way. Here's the latest evolution:

(setq inferior-lisp-program "/usr/bin/sbcl")
(setq load-path (append load-path (list "~/emods" "~/emods/slime" "/usr/lib/erlang/lib/tools-2.6.2/emacs" "/usr/share/doc/git-core/contrib/emacs")))

(setq erlang-root-dir "/usr/lib/erlang")
(setq exec-path (cons "/usr/lib/erlang/bin" exec-path))

(setq x-select-enable-clipboard t)

(require 'vc-git)
(when (featurep 'vc-git) (add-to-list 'vc-handled-backends 'git))
(require 'git)
(autoload 'git-blame-mode "git-blame"
  "Minor mode for incremental blame for Git." t)

(require 'htmlize)
(require 'blog-mode)
(require 'quack)
(require 'erlang-start)
(require 'slime)
(require 'redo)
(require 'php-mode)
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode) '("\\.ss$" . scheme-mode))

(add-hook 'php-mode-hook
          (lambda () (define-key php-mode-map (kbd "<tab>") (lambda () (interactive) (insert-char 9 1)))))

(setq scroll-bar-mode-explicit t)
(set-scroll-bar-mode `right)

(global-set-key (kbd "<f5>") 'eval-buffer)
(global-set-key (kbd "<f7>") 'call-last-kbd-macro)

(global-set-key (kbd "C-w") (lambda () (interactive) (kill-buffer nil)))

(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "C-y") 'redo)

(defun other-window-backward (&optional n)
  (interactive "p")
  (other-window (- (or n 1))))

(global-set-key (kbd "C-n") 'other-window)
(global-set-key (kbd "C-S-n") 'other-window-backward)
(global-set-key (kbd "C-a") 'mark-whole-buffer)

(tool-bar-mode nil)
(menu-bar-mode 0)

  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(cua-mode t nil (cua-base))
 '(htmlize-output-type (quote inline-css))
 '(iswitchb-mode t)
 '(show-paren-mode t)
 '(transient-mark-mode t))
(put 'downcase-region 'disabled nil)
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.

Changes from last time:

  1. (tool-bar-mode nil) and (menu-bar-mode 0) are now in my default .emacs instead of just on the netbook. Yegge suggests removing the GUI right away, but it actually takes a while before you get used to using the keyboard for everything (and in fact, if you want inter-application copy/paste and you don't know enough elisp to change how the default kill/yank functions work, you have to use the corresponding menu items). I'm far enough along that I don't need the training wheels anymore, and it gives me another 5-6 lines of editor space on screen, so they're gone.
  2. iswitchb mode is on by default. It adds one keystroke to the process of making a buffer not tied to a file, but it makes finding existing buffers easy enough that it's worth the trade.
  3. Lots more mode-includes including htmlize, my own blog-mode (which I'm using right now to type this), language support for Erlang, Scheme, and Common Lisp (php and JavaScript have been there for quite a while), and hooks into Git mode.
  4. Parentheses are being highlighted by default. I get the feeling it was made for Lisp coding, but it's actually even more useful in JavaScript with jQuery, where a code block might look something like
$('#something').click(function () {
   stuff = [$(this).attr('id'), $(this).attr('class'), $(this).attr('src')];
   for(i in stuff){

In these cases, parenthesis highlighting (which also highlights [] and {}) is critical for making sure you close them all properly, and in the right order. You could probably do it by hand without help, but I wouldn't envy you that task.

EDIT: After upgrading my desktop, I went to upgrade my other machines to 9.10. The HP Mini 1035nr upgrade was not seamless. Almost, but not quite. I had to run

sudo apt-get install --reinstall bcmwl-kernel-source

to enable the wireless card.

Tuesday, February 23, 2010


I've been noticing two patterns lately in my various activities. They're not really bad or good (or at least, I'm unsure which); it's just some digital behaviors I've noticed in myself.

Firstly, anything of even vague importance on my personal workstations is a git repository that I've made it a habit to udate each time I use each machine. Between the three independant computers I use on a daily basis, my data is pretty safe from a random hardware malfunction. Granted a building fire or similar would still take them all out but a single piddling hard-drive failure isn't something that strikes fear into my heart at this point. My most used git commands are (in descending order

  1. git add .
  2. git checkout
  3. git commit -m
  4. (since I started using git from Emacs; see below) git log

Next, Emacs and Gimp are quickly supplanting almost every program I used to use. In fact (for my personal work) I now basically live in Emacs, Gimp, Inkscape and Chrome. Gimp gets used for image manipulation (Inkscape just for vectors), Google Chrome for the obvious, and Emacs for everything else. I used to use Terminal to run git, erl, mzscheme and (every once in a while) SBCL. Since getting heavily into Emacs, Quack lets me drop into an improved mzscheme prompt, erlang-shell does the same thing for erl, and despite my earlier complaints, SLIME is actually very nice once you're already comfortable with Lisp and Emacs. Emacs 22+ also comes with a git package that you just need to require to get a pretty freakin' good interface going.

As an aside, if you're interested in picking up Emacs, I highly recommend these two articles by Steve Yegge, and Xah's awesome tutorials. If you're interested in picking up a Lisp dialect and don't already know the editor very well, I actually recommend staying away from Emacs until you have a firm grip on PLT Scheme, then coming back and picking up Elisp once you're more familiar with the language.

Like I said, I'm not sure whether these pattrns are positive or not, but they remain as I've stated them:

  1. Anything even remotely important on a machine I pilot is in a GIT repo.
  2. I use a grand total of 4 programs for any and all personal projects (and the usage is skewed heavily towards Emacs and Chrome).

Friday, February 19, 2010

(define (free)

(define (free)

I finally have some free time to write.

It's been hard to come by; I work at an office where the Agile Mafia has taken over, and the only visible result I've observed is that there's less free time and more shitty, un-maintainable products. It's weird, because looking around at real tech companies, you'd get the impression that Agile was dead (or at least, restricted to the less ridiculous aspects). I'm here to tell you that if you're at anything other than a tech-focused company, you get to put up with all the annoyance of "weekly sprints", "daily scrum" and "tighter scheduling" without getting any of the real or imagined benefits.

Here's the result, from someone at ground zero:

  1. You're always forced to over-commit.
  2. You're held to your commitments, and missing a deadline (no matter how unreasonable) is seen as a failure on your part.
  3. Bug fixing and testing is expected to go on for 1/4 as long as development.
  4. When there are issues on live, you are expected to handle those, then work overtime to catch up with your actual work (because the plans are always made on the assumption that this time nothing will go wrong).

Number 1 means that there's never really enough time to get everything done. Number 2 means that it's actually better, from the incentive perspective, to half-ass everything you're tasked with so that you can call it "done", and tell yourself and your peers that you'll fix it later. Number 3 means that in any given release, half or more of the major issues get pushed out onto our clients (who promptly complain about those issues and cause number 4). Finally, number 4 means that there's never enough time to fix the defects introduced in numbers 1 and 2.

Ironically, number 2 also means that if performance is measured closely enough and used as a gauge enough times, anyone that tries to point out and/or work against the negative re-enforcement loop gets canned.

In other words, I have observed that the Agile process, used as it is at my company decreases the number of competent developers/designers, decreases the quality of work done, decreases the number of working features present at any given time and (if I can imagine their viewpoint for a moment) erodes client good-will. This sounds like it's bad.

I don't even want to think about a general case though. I'm thinking right now. A feature I'm working on is languishing. It doesn't get attention because it's really only been requested by a couple of clients, and because the rest of the dev team though it would be trivial. It wasn't I've watched the programmer responsible struggle the entire way through. Hell, the flash side alone was struggle enough. The back-end accounting logic for this thing must have been monstrous. We're at the last day right now. Tonight. As I write this, it's 11:45 pm on the Friday before release, and I know it's going out on Monday, come hell or high-water.

The process we're using, and the assumptions we've internalized combine to mean that I can't fix it. That if I try and succeed, I'll get a talking to. If I try and fail, it'll just re-enforce the perception that the process should not be deviated from.

Superstition is infuriating in others, though I realize that it must affect me at some point as well.

I didn't want to talk about that though. I wanted to talk about how I'm taking the edge off enough that I haven't decked anyone yet. This is the sort of ironic thing about my life and job. I love drawing, and I love programming. And even when those are the things that principally make up my job, they're what I do as stress release, and as entertainment. So lately, I've been programming. What, you ask? Why, this:

(defmacro defregion (tag-name tag-text)
  `(defun ,(make-symbol (concat "region-to-" (symbol-name tag-name))) ()
     (wrap-region ,tag-text (region-beginning) (region-end))))

(defmacro deftag (tag-name start-tag end-tag)
  `(defun ,(make-symbol (concat "insert-" (symbol-name tag-name))) ()
     (insert-tag ,start-tag ,end-tag)))

(define-minor-mode blog-mode
  "This is a collection of useful keyboard macros for editing Langnostic"
  " Blog"
  (setq blog-mode-map (make-sparse-keymap))
  (define-key blog-mode-map "\C-cl" 'insert-link)
  (define-key blog-mode-map "\C-cb" 'insert-code-block)
  (define-key blog-mode-map "\C-c\C-l" 'region-to-link)
  (define-key blog-mode-map "\C-c\C-b" 'region-to-code-block))

(deftag link (concat "<a href=\"" (x-get-clipboard) "\">") "</a>")
(deftag code-block "<pre>" "</pre>")

(defregion link (concat "<a href=\"" (x-get-clipboard) "\"></a>"))
(defregion code-block "<pre></pre>")

(defun insert-tag (start-tag &optional end-tag)
  (insert start-tag)
    (insert (or end-tag ""))))

(defun wrap-region (a-tag start end)
  (let ((tag-pair (split-tag a-tag)))
    (goto-char end)
    (insert (cadr tag-pair))
    (goto-char start)
    (insert (car tag-pair))))

(defun split-tag (a-tag)
  (let ((tag-pair (split-string a-tag "><")))
    (cons (concat (car tag-pair) ">") (list (concat "<" (cadr tag-pair))))))

(provide 'blog-mode)

It's still taking me some time to get used to the keybindings (given that I use the CUA mode shortcuts, so C-c is also my "copy" shortcut which makes it slightly more challenging), and I still haven't put together an automatic indenting/coloring feature on the code-block functions, but this is a half-way decent first stab at a helper mode for Emacs.

So yeah.

I've also gotten to the point where my average WPM is up at 52-58, which means that I'm about 20% faster than my previous peak. Combined with the helper mode above, it means that this is the least amount of time I've spent writing a blog entry by a pretty wide margin. I plan to keep it up, so the savings will increase as I practice and write further convenience functions for myself. The guys who keep saying how it's important to build your own tools are on to something. It's made me more productive.

I think.

The sad fact is that I don't have a reliable way of measuring, so I might be just as deluded as my product manager and CEO. I'm still going to keep it going. If nothing else, this kind of skills development will keep my blood-pressure down and potentially make me a more attractive hire for a company that gives a rat's ass about shipping AND having great product, rather than just unqualified shipping.

Monday, February 15, 2010

Quick Update

Just a quick update before I go to bed. Really, I'd like to give you a much better update, but I don't want my sleep cycles to get even more fucked up than they currently are.

First, I've been programming quite a chunklet of Flash recently. And it's reasonably cool, but there's very little reason for me to use it in general. I don't animate many things, I don't make web games, and the community seems to be almost exclusively geared towards graphic designers (that is, graphic designers who are not also programmers). The entire thing typically gets pitched as an alternative to learning HTML/CSS/JS, with reduced cross-browser headaches.

In practice, ActionScript is a poor-man's jQuery, and IE still breaks things you never really thought could break. The only real advantage flash has over the standard web trio is that you can visually lay out interfaces rather than doing it as a series of nested tags and properties. That's a powerful abstraction once you understand it, but in my experience, not many do. Flash is most powerful when you use the stage metaphor as a way of setting up your objects, then script all of their actions. Actual humans who use flash tend to fall into two groups:

  1. Graphic Designers (with the capital GD) who use the stage for everything. These are the people who will set up empty movie-clips with onEnterFrame events instead of taking the two minutes to understand how setTimeout works.
  2. Programmers (with the capital P) who script everything. Typically, half of their code is things like

Second, I haven't made much progress on Emacs Extensions, but I have picked up some data structures literature, and I'm moving onto The Seasoned Schemer. Also, I've found some interesting (if academic) programming problems that I'm trying to work through in Scheme now that I've started using Quack (which reminds me, I'm hacking Scheme again now that my Python project is finished and my PHP contract is winding down). Quack is basically SLIME-lite for the Scheme language. It gives you much better highlighting than the default Emacs scheme-mode, and you can use C-c C-q r to start up a Scheme prompt (which defaults to MzScheme on my machine. I'm not sure if it just uses whichever implementation it finds, or tries to use MzScheme even if it's not installed). The debugger and macro-stepper are now really the only reasons I hop into DrScheme anymore.

Third and finally, I've been spending more and more time tinkering with Apache. Mostly, trying unsuccessfully to get it to play nice with PLT-Server. Apache seems like an application based on how people talk about it and use it, but when you get deep enough into this thing, it becomes clear that Apache is actually a (close to) Turing-complete, XML-based language with none of the debugging ability or cohesion of an actual language. I'm seriously considering picking up Unix Network Programming and getting my head around the protocols just so I don't have to deal with it.

Monday, February 8, 2010