Skip to content

Instantly share code, notes, and snippets.

@bguthrie
bguthrie / LICENSE.txt
Last active May 21, 2021 15:30
TS typings for imagekit-react
Copyright 2021 BRIAN GUTHRIE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTH
describe SomeClass do
describe '#some_method' do
def actual(parameter)
described_class.some_method(parameter)
end
it 'expresses behavior 1' do
expect(
actual('base_value')
).to eq('expected 1')
(ns clue.core
(:require [clj-http.client :as http]
[clojure.spec :as s]))
(def client-key (System/getProperty "HUE_CLIENT_KEY"))
(def hue-api (System/getProperty "HUE_SERVER_ADDRESS"))
(def base-url (str "http://" hue-api "/api/" client-key))
(s/def :light/name (s/nilable string?))
@bguthrie
bguthrie / typed.clj
Last active September 17, 2015 16:15
An attempt to strongly-type an XML search function.
(ns xml.typed
(:require [clojure.xml :as xml]
[clojure.core.typed :as t])
(:import (clojure.lang Keyword)))
(t/defalias XmlNodeContent (t/U String XmlNode))
(t/defalias XmlNode
(t/HMap :mandatory {:tag Keyword
:content (t/ASeq XmlNodeContent)}
(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)))
@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
@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 / 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 / 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 / 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" }));