Skip to content

Instantly share code, notes, and snippets.

Avatar

David Demaree ddemaree

View GitHub Profile
@ddemaree
ddemaree / no-more-masters.md
Last active Feb 4, 2022
Draft blog post for renaming Git master branches
View no-more-masters.md

No More Masters

In my book Git for Humans, published in 2016, I made copious references to master as the primary branch name used in Git repositories.

The term master can refer to a "master copy," meaning the original or canonical version of something from which other copies are made. But its primary meaning in the English language is "a person who has general authority over others." And, especially in American and British English, it's hard to separate the word "master," and that meaning of it, from another related word: "slave."

If we're being honest, folks in tech have known that "master" and "slave" are problematic terms for a while, even if they haven't felt motivated to change them. There are those who say that if these words refer to objects or systems, rather than people, then they can't be offensive, just as people argue that tech is a meritocracy and algorithms can't be biased. These argument

@ddemaree
ddemaree / application.js.coffee
Created Jun 12, 2011
Simple Google Maps API v3 integration in CoffeeScript, with non-JS Static Maps fallback
View application.js.coffee
#= require jquery
#= require jquery_ujs
#= require lib/modernizr
#= require lib/jquery.lettering
#= require_tree .
$ ->
$('*[data-googlemap]').googleMap()
true
@ddemaree
ddemaree / _retina.scss
Created Apr 26, 2013
Example Sass mixin for a "bulletproof" Hi-DPI media query
View _retina.scss
@mixin retina($ratio: 1.5) {
$dpi: $ratio * 96;
$opera-ratio: $ratio * 100;
@media only screen and (-webkit-min-device-pixel-ratio: #{$ratio}),
only screen and ( -o-min-device-pixel-ratio: '#{$opera-ratio}/100'),
only screen and ( min-resolution: #{$dpi}dpi),
only screen and ( min-resolution: #{$ratio}dppx) {
@content;
}
@ddemaree
ddemaree / 01_ticket.rb
Created May 30, 2011
I cannot believe this is valid Ruby syntax. P.S. - I love Ruby
View 01_ticket.rb
class Ticket < ActiveRecord::Base
SEARCH_COLUMNS = {
:tickets => [:token, :subject, :body, :customer_name, :customer_email],
:notes => [:body, :author_name, :author_email]
}
def self.conditions_for_keyword_search(table, keywords)
# Because we may use this string elsewhere, we don't want to mutate the only copy
query_words = keywords.dup
@ddemaree
ddemaree / 01_random_specs.rake
Created Jun 8, 2011
Rake task for running a random sampling of RSpec tests
View 01_random_specs.rake
namespace :spec do
SPEC_SUITES = %w(models requests integration helpers controllers lib)
def sample_spec_files(num=5)
[].tap do |specs|
SPEC_SUITES.each do |dirname|
files = Dir[Rails.root.join("spec", dirname, "**", "*_spec.rb")]
specs.concat files.shuffle.first(num)
end.shuffle
end
@ddemaree
ddemaree / 01_README.md
Created Nov 30, 2011
How Sunspot implements its wonderful search/index DSL
View 01_README.md

This code is extracted/adapted from Mat Brown's Sunspot gem. One of Sunspot's nicest features is an expressive DSL for defining search indexes and performing queries. It works by instance_eval-ing a block you pass into it in the context of its own search builder object. In this code, the pig thing1 statement is roughly equivalent to zoo = Zoo.new; zoo.pig(thing1).

Sunspot's DSL has to resort to trickery: the instance_eval_with_context method uses eval to get the block to give up the object it considers to be self, then sets up an elaborate system of delegates and method_missing calls so any methods not handled by the DSL are forwarded to the surrounding object. But as a result, this syntax is minimal and beautiful, and it works the way you expect whether or not you prefer blocks to yield an object.

Without this trick the block would be restricted to either the original, "calling" context (as a closure) or the DSL's "receiving" context (using instance_eval), but not both.

Using `ins

@ddemaree
ddemaree / talk_notes.md
Last active Dec 26, 2015
Notes and links for my Web Directions South 2013 talk
View talk_notes.md

Slides

You can view or download my slides from Speaker Deck: The Weight of the Web (Web Directions South).

Referenced in my talk

@ddemaree
ddemaree / application_controller.rb
Created Sep 6, 2012
Sample code for WCR2012 lightning talk
View application_controller.rb
class ApplicationController < ActionController::Base
def current_user
User.find_by_id(session[:user_id])
end
def current_user=(user)
session[:user_id] = user.id
end
@ddemaree
ddemaree / DDImportOperation.h
Created Jul 7, 2012
Multi-threaded Core Data import example
View DDImportOperation.h
@interface DDImportOperation
@property (strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
-(void)initWithPersistentStoreCoordinator:(NSPersistentStoreCoordinator*)persistentStoreCoordinator;
-(void)saveChanges;
@end
@ddemaree
ddemaree / 01_versioned.sql
Created Jun 27, 2012
Example of my versioning problem from earlier, or: things that were easier before ORMs
View 01_versioned.sql
CREATE TABLE items (
uuid VARCHAR(255) NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL DEFAULT '');
CREATE TABLE item_versions (
uuid VARCHAR(255) NOT NULL PRIMARY KEY,
version INT(64) NOT NULL UNIQUE AUTO_INCREMENT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
INSERT INTO items(uuid, name) VALUES("APP_GENERATED_ID", "An item");