Skip to content

Instantly share code, notes, and snippets.

@ddemaree
ddemaree / text-balancer.ts
Created April 3, 2023 13:24
Simple text balancing class written in TypeScript, complete with React hook
/*
Balances text blocks, making them as narrow as possible while maintaining their current height (i.e. number of lines), preventing typographic 'widows' and
'orphans' (single words on a line by themselves).
As of early 2023, native browser support for text balancing is planned but not yet implemented. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap
This feature can be previewed in Chrome 114+ by enabling the `Experimental Web Platform features` flag in `chrome://flags`.
For browsers that don't yet support `text-wrap`, this script uses a binary search to find the narrowest width that maintains the current height, based on
@ddemaree
ddemaree / schema.js
Last active November 9, 2022 00:59
Example of WordPress–Sanity import
// First, we must import the schema creator
import createSchema from "part:@sanity/base/schema-creator";
// Then import schema types from any plugins that might expose them
import schemaTypes from "all:part:@sanity/base/schema-type";
// We import object and document schemas
import blockContent from "./blockContent";
import category from "./category";
import post from "./post";
@ddemaree
ddemaree / no-more-masters.md
Last active February 4, 2022 16:14
Draft blog post for renaming Git master branches

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 / 0_story.md
Created April 24, 2015 16:48
Apple Git prompt set up

We want our prompts to look like this:

[ddemaree@ddemaree-osx giftboxapp (master)]$ 

In this example, the text inside the square brackets shows the current username and hostname (ddemaree@ddemaree-osx), followed by the name of the current directory (giftboxapp), and finally the current Git branch ((master)) shown in parentheses.

If we have untracked changes to this Git project, those are denoted with an asterisk:

Keybase proof

I hereby claim:

  • I am ddemaree on github.
  • I am ddemaree (https://keybase.io/ddemaree) on keybase.
  • I have a public key whose fingerprint is BEA0 F423 C8D7 AEDD 8A45 D72D 4102 B0D5 7A7B 617A

To claim this, I am signing this object:

@ddemaree
ddemaree / talk_notes.md
Last active December 26, 2015 18:09
Notes and links for my Web Directions South 2013 talk

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 / _retina.scss
Created April 26, 2013 20:49
Example Sass mixin for a "bulletproof" Hi-DPI media query
@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 / application_controller.rb
Created September 6, 2012 15:56
Sample code for WCR2012 lightning talk
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 July 7, 2012 14:46
Multi-threaded Core Data import example
@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 June 27, 2012 21:02
Example of my versioning problem from earlier, or: things that were easier before ORMs
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");