Skip to content

Instantly share code, notes, and snippets.

View jbrains's full-sized avatar

J. B. Rainsberger jbrains

View GitHub Profile
@jbrains
jbrains / package.json
Created February 22, 2015 16:16
How well do I understand how Atom activates/deactivates a package with/in spite of having an activation command configured?
{
"name": "status-stats",
"main": "./lib/status-stats",
"activationCommands": ["status-stats:toggle"],
"version": "0.1.0",
"private": false,
"description": "A derivative of @segphault's status-wordcount. Displays wordcount, grade level, and Flesh Kincaid scores, to help you write for your audience.",
"repository": "https://github.com/jbrains/status-stats",
"license": "MIT",
"engines": {
@jbrains
jbrains / InstanceVariablesInRSpecMatcher.rb
Created November 9, 2014 16:20
Is there any harm in using instance variables inside an RSpec Matcher like this? Will I keep garbage values from use to use?
RSpec::Matchers.define :eventually_redirect_to do | target_url |
def collect_redirect_urls_from(url)
redirect_urls = []
response = RestClient.get(url) do | response, request, result, &block |
redirect_urls.push(response.headers[:location]) if response.code == 301
response.return!(request, result, &block)
end
redirect_urls
end
@jbrains
jbrains / post-receive
Created September 14, 2014 12:34
A safe approach to publish-on-push with git and Wordpress
#!/bin/sh
# Improved safety by not checking out directly into document root
pushd /home/jbrains
SCRATCH="$(date +%N)"
TARGET="/home/jbrains/domains/jbrains.ca/web/wordpress-jbrains.ca"
# Backup
tar cf "wordpress-jbrains.ca.$SCRATCH.tar" $TARGET
# Clone, then copy
mkdir $SCRATCH
pushd $SCRATCH
@jbrains
jbrains / _posting.scss
Created May 31, 2014 16:42
How do I remove the duplication in these SCSS rules?
a.comment-link {
/* Superimposed image */
$icon-comment-height: 10px; /* Must match the size of the graphic */
$icon-comment-width: 10px; /* Must match the size of the graphic */
background: $salmon url(../images/comment.gif) no-repeat $icon-comment-height $icon-comment-width;
color: $salmon;
&:hover {
background: $dark-salmon url(../images/comment.gif) no-repeat $icon-comment-height $icon-comment-width;
@jbrains
jbrains / learn_sequel_model_spec.rb
Last active August 29, 2015 14:01
I think I'm figuring out how use Sequel::Model....
require "sequel"
# Use the module to avoid naming collisions with other specs.
module LearnSequelModelSpec
describe "Person Model" do
let(:db) { Sequel.sqlite }
before(:each) do
-- Thanks to @kimwallmark for teaching me `maybe` and showing me how a single lookup.
-- I had the brilliant idea of using `snd`, even though I dislike the name. :)
fizzbuzz :: Integer -> String
fizzbuzz n = maybe (show n) snd $ classify n
where
classify n = find (\(m, _) -> n `mod` m == 0) [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")]
@jbrains
jbrains / gist:9451941
Last active August 29, 2015 13:57 — forked from CoryFoy/gist:9441665
# SMELL I don't like the name gemfile_lock_file, but I don't know
# what else to call it. I want to distinguish it from Gemfile.
def extract_gems_from_gemfile_lock_file(contents)
gems = []
# Extract all the non-empty lines between and excluding 'specs:' and 'PLATFORMS'
contents.each_line do |line|
line = line.strip
# It takes a few seconds to understand this algorithm,
# but I can't yet justify replacing it with a functional
# approach. Again, it depends what the reader understands
@jbrains
jbrains / conways_game_of_life.coffee
Created December 17, 2013 18:31
Messing around with the Game of Life in Coffeescript. I don't know what I'm doing.
Dystopia =
expands: (world) -> []
lives: (cell) -> false
Utopia =
expands: (world) -> world
lives: (cell) -> true
evolve_world = (world, rules=Dystopia) ->
rules.expands(world).filter (cell) -> rules.lives(cell)
@jbrains
jbrains / gist_no_css_tag_spec.rb
Last active December 26, 2015 09:29
Now that's a test list!
require "rspec"
describe "gist_no_css tag" do
context "the pieces" do
context "rendering code" do
# Assume we've already successfully downloaded code
example "gist ID, username and filename"
example "gist ID and filename"
example "gist ID and username"
example "gist ID"
@jbrains
jbrains / Gist1.java
Created October 13, 2013 17:03
A gist with multiple files, as you might expect, also for testing.
public interface GistWithMultipleFiles {}