Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
(defun rinari-test (&optional edit-cmd-args)
"Test the current ruby function. If current function is not a
test, then try to jump to the related test using
`rinari-find-test'. Dump output to a compilation buffer allowing
jumping between errors and source code. With optional prefix
argument allows editing of the test command arguments."
(interactive "P")
(or (string-match "test" (or (ruby-add-log-current-method)
(file-name-nondirectory (buffer-file-name))))
(rinari-find-test))

The Eight Wondrous Places of the Human World

According to Buddhist mythology, the human world has eight wondrous places that give us protection. The first is a place where everyone is illuminated by a golden light. This golden light supports all sentient beings and helps them to grow and mature under all circumstances. Consider your own life. For the past ten, twenty, thirty, or forty years, how many troubles have you experienced? Countless troubles. But still, you're alive. How? You don't know. But this is reality. You are a survivor. You have been protected and nurtured by many things -- your parents, your teachers, your friends, and more. All this time, your life has been supported. You have been illumined by a golden light that constantly shines, and constantly helps you.

The second place is one in which you are immune to trouble. Of course, we all have troubles. But if you learn something from your troubles, then those troubles aren't exactly troubles. By realizing the true nature of trouble, trouble

@purcell
purcell / application_helper.rb
Created September 9, 2011 09:23
Make will_paginate generate HTML that bootstrap.less will render nicely
# Based on https://gist.github.com/1182136
class BootstrapLinkRenderer < ::WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag :div, tag(:ul, html), container_attributes
end
def page_number(page)
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
<!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>
@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>
@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\\}\\)")
(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 / 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.

@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);
});
//////////////////////////////////////////////////////////////////////
// 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",