Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
(defadvice package-download-transaction
(around disable-keepalives (&optional args) activate)
"Disable HTTP keep-alives to work around network issues with Melpa host."
(let ((url-http-attempt-keepalives nil))
ad-do-it))
(defvar package-filter-function nil
"Optional predicate function used to internally filter packages used by package.el.
The function is called with the arguments PACKAGE VERSION ARCHIVE, where
PACKAGE is a symbol, VERSION is a vector as produced by `version-to-list', and
ARCHIVE is the string name of the package archive.")
(defadvice package--add-to-archive-contents
(around filter-packages (package archive) activate)
"Add filtering of available packages using `package-filter-function', if non-nil."
Challenge ID: 4d28aef94bcd032f1c0000dc
http://vimgolf.com/challenges/4d28aef94bcd032f1c0000dc.yaml
Keystrokes (28):
M-f M-4 M-d <down> M-f M-f M-3 M-d <down> M-f M-f M-6 M-d C-y M-y M-y <up> M-b M-b <left> C-y M-y <up> M-5 M-b <left> C-y M-y
Full command log:
M-f forward-word
//////////////////////////////////////////////////////////////////////
// Wikipedia
//////////////////////////////////////////////////////////////////////
(function(w) {
var call_wikipedia_api = function(data, callback) {
$.ajax({
url: "http://en.wikipedia.org/w/api.php",
data: $.extend({ format: "json" }, data),
dataType: "jsonp",
@purcell
purcell / completion.js
Created November 28, 2011 16:54
Cached autocompletion of wikipedia page titles with jquery ui autocomplete plugin
function cached_completer(completer) {
var cache = {};
return function(request, response) {
if (request.term in cache) {
response(cache[request.term]);
} else {
completer(request, function(resp) {
cache[request.term] = resp;
response(resp);
});
@purcell
purcell / oxtail-stew.markdown
Created November 16, 2011 12:13
Oxtail Stew Recipe

Oxtail stew recipe

By Steve Purcell

Serves 2-3. Prep time: 20 mins. Cooking time: around 4 1/2 hrs.

This stew is rich and satisfying, not to mention deceptively healthy, easy to make, and dirt cheap.

(defn follow-chain [base-url number]
(let [result (slurp (str base-url number))]
(if-let [next-number
(if (re-find #"^Yes" result)
(/ (Integer/parseInt number) 2)
(let [idx (.indexOf result "and the next")]
(when (>= idx 0)
(last (string/split (subs result idx) #" ")))))]
(do
(println result)
@purcell
purcell / color-utils.el
Created October 17, 2011 12:59
A few hacky color-related functions
(defun format-color (rgb)
"Convert a triplet of floating point (0.0-1.0) RGB values into
a hex triplet"
(apply 'format "#%02x%02x%02x"
(mapcar (lambda (x) (* 255 x)) rgb)))
(defconst colour-triplet-regex
"\\([0-9A-Fa-f]\\{2\\}\\)\\([0-9A-Fa-f]\\{2\\}\\)\\([0-9A-Fa-f]\\{2\\}\\)")
@purcell
purcell / example.html
Created October 3, 2011 09:02
Bootstrap dropdown breakage with yepnope/modernizr
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="https://raw.github.com/SlexAxton/yepnope.js/master/yepnope.js" type="text/javascript"></script>
<script type="text/javascript">
yepnope({load: "https://raw.github.com/twitter/bootstrap/master/js/bootstrap-dropdown.js"})
</script>
</head>
<body>Borken</body>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="example.js" type="text/javascript"></script>
</head>
<body>Borken</body>
</html>