Skip to content

Instantly share code, notes, and snippets.

package proovy;
import groovy.xml.dom.DOMCategory
import org.lobobrowser.html.parser.*
import org.lobobrowser.html.test.*
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathFactory
import javax.xml.xpath.XPathConstants
import css2xpath.*
# Found on the ZshWiki
# http://zshwiki.org/home/config/prompt
#
# As lifted from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
function collapse_pwd {
echo $(pwd | sed -e "s,^$HOME,~,")
}
function prompt_char {
# Gem idea, extracted from ResourceFull. Thoughts on the API?
class User < ActiveRecord::Base
named_scope :born_after, lambda {|date|
{ :conditions => ["birthdate >= ?", Date.parse(date)] }
}
query_set :filter do
filter_with_scope :active
queryable_with :email
@bguthrie
bguthrie / argument_examples.rb
Created February 27, 2011 04:00
Several method signatures used in a DSL like ActiveRecord, somewhat simplified.
# def initialize(attributes = {})
Pirate.new :name => "Greenbeard", :ship => "The Queen Anne's Renegotiation"
# def has_many(of_what, options = {})
has_many :crew_members, :class_name => "Pirate", :foreign_key => "captain_id"
# def validates_presence_of(*arrrrrgs)
validates_presence_of :parrot, :peg_leg, :blank => false
@bguthrie
bguthrie / example.js
Created November 21, 2011 10:44
A wrapper that applies a transform to jQuery.Deferred objects.
// Low level helper function for calling some API.
function callAPI(path, params) {
return $.get("/api/url" + path, params);
}
// High-level semantic function for retrieving widgets. Leverages the underlying
// API function but itself returns a promise.
function getAllWidgets(filter) {
var apiCall = callAPI("/widgets", $.extend(filter, { foo: "bar" }));
@bguthrie
bguthrie / gol-clj-spec.clj
Created December 5, 2011 11:46
An implementation of Conway's Game of Life in Clojure.
(ns gol-clj.spec.core
(:use [gol-clj.core])
(:use [speclj.core]))
(describe "Game state after a single step"
(it "is empty given an empty set of points"
(should= #{} (gol-step #{})))
(it "is empty given only a single point"
(should= #{} (gol-step #{[0 0]})))
@bguthrie
bguthrie / notcode.md
Created December 16, 2011 03:22
A brief list of activities that do not produce code.

Thanks to @mipearson for his help in compiling this extremely serious and meaningful list.

  • Drawing Visio diagrams
  • Project management
  • Standards governance
  • Analyzing technical requirements
  • Attending meetings
  • Tweeting
  • Drinking
  • Writing gists
@bguthrie
bguthrie / coderwall_badge_markup.html
Created January 9, 2012 22:47
An example of Coderwall badge integration.
<!-- Add these tags to the HEAD section of your page. -->
<link href="http://coderwall.com/stylesheets/jquery.coderwall.css" media="all" rel="stylesheet" type="text/css">
<script src="http://coderwall.com/javascripts/jquery.coderwall.js"></script>
<!-- You also need to place a container where you'd like the Coderwall badges to render. -->
<section class="coderwall" data-coderwall-username="(your username)" data-coderwall-orientation="(vertical or horizontal)"></section>
@bguthrie
bguthrie / fill_in_wysihtml5.rb
Last active May 17, 2017 18:10
A Capybara helper to fill in WYSIHTML5 editors. Works with multiple editors on a page.
module FillInWysihtml5
def fill_in_wysihtml5(label, opts={})
page.execute_script <<-JAVASCRIPT
var id = $("label:contains(#{label})").attr("for");
$("#" + id).data("wysihtml5").editor.setValue("#{opts[:with]}");
JAVASCRIPT
end
end
(ns persistable.async
(:import [persistable.core Persistable])
(:require [persistable.core :as core]))
(defn async-persistable [wrapped]
(reify Persistable
(update [this id values] (future (core/update wrapped id values)))
(insert [this values] (future (core/insert wrapped values)))
(delete [this query] (future (core/delete wrapped query)))
(find-one [this query] (future (core/find-one wrapped query)))