12 Feb 2015

Lighten/darken a color in Emacs

February 12, 2015

I put together a little function to lighten or darken a (hex) color, having tired of using the browser's color picker or other manual means to tweak a color. I couldn't find an existing solution so I hope this helps someone else out!

# scheme
(defun lighten-color-at-point (&optional pct)
  (interactive "p")
  (unless (looking-at-p "#")
     (re-search-backward "#"))
    (push-mark nil t t)
    (let ((dist (skip-chars-forward "#A-Za-z0-9" (+ (point) 7)))
      (percent (or pct 5)))
      (insert (apply 'color-rgb-to-hex
        (apply 'color-hsl-to-rgb
          (apply 'color-lighten-hsl
            (append (apply 'color-rgb-to-hsl
              (color-name-to-rgb (buffer-substring-no-properties (mark) (point))))
              (list percent))))))
    (delete-region (region-beginning) (+ (region-beginning) dist)))))

(defun darken-color-at-point (&optional pct)
  (interactive "p")
  (lighten-color-at-point (if (numberp pct) (* pct -1) -5)))

(defun my-css-mode-hook ()
  (local-set-key (kbd "C-c l") 'lighten-color-at-point)
  (local-set-key (kbd "C-c R") 'darken-color-at-point))

(add-hook 'css-mode-hook 'my-css-mode-hook)

To use this, put your cursor before or after a color and press C-c l or C-c R. For example (cursor denoted with |):

# css
body { background: |#ccc }

By default, it will lighten/darken the color by 5%; with a prefix argument, lighten/darken by that percent. (C-u 20 C-c l to lighten by 20%)

19 Jan 2012

Taming AppEngine Projects with Buildout

January 19, 2012

AppEngine's Python dependency management amounts to "throw everything into the 'lib' directory," which can lead to environments which are difficult to maintain and even more difficult to setup in the first place. In this guide, I show how Buildout can be used to tame AppEngine projects and bring automation and maintainability back to a project's development, deployment, and dependency manangement.

[read the rest]

29 Jun 2011

Thinkpad T420 Review

June 29, 2011

The new Thinkpad T420's cutting-edge specs, competitive price point, functional design, and magnificent keyboard make up for a few shortcomings. I chose the T420 loaded with Fedora to replace my MacBook Pro and I've never been happier with my computing environment. In this post I review the laptop itself and how it stacks up against last year's MacBook Pro; a later post will discuss the switch back to Linux.

[read the rest]

17 Mar 2011

Applying to YCombinator: Tips for Standing Out

March 17, 2011

This year I've had the opportunity to read through quite a few YCombinator applications. This article takes you through what I consider to be the important parts of the application and tips for standing out in them.

[read the rest]