Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • 18:34 (UTC -06:00)
View GitHub Profile
F
E
Am
Dm

[verse 1]
ive got
F
two cats sleepin around in this
# script
# the king
# tags power

EXT. DAY - a country side manor

-
scene:
chickens forage,

Some text

some text that should be styled as a quote, but no larger a font than normal text

Some more text

Opinion

Stop making text in your applications unselectable.

Copying and pasting is one of the most common things a user will do to any text you display in your application. Here are some things that applications do that make this difficult or impossible:

  • override mobile select function to select entire "blocks" of text for copying, for instance, news articles.
  • trigger some action on click, such as expanding a table row or launching an edit modal on click. Another example is launching a directions app on address click.
  • misusing the input html element to display summary text by adding "disabled" and therefore stopping a user from selecting the text
function getParticipantNames() {
// Because queries are cached, using the `allParticipants` query
// prevents another roundtrip to the database
const participants = database.getAllParticipants();
return participants.map(p => p.name);
}
function getParticipantNames() {
const participants = database.getAllParticipants();
return participants.map(p => p.name);
}

The Myth of Self Documenting Code

Or, how I learned to stop worrying and love the comment.

This article is a response to Joe Eames' article on self-documenting code. If you haven't read it yet or aren't familiar with the concept of self-documenting code, please check out the article [here][3].

I consider self-documenting code to be a myth and perpetuating it to be dangerous (especially to new programmers).

Before we get into why, let me summarize the two primary arguments for sefl-documented code:

  1. Comments that explain what the program are doing are redundant. As code changes, comments can also become out-of-date and stale, making the code harder to maintain overall.
let prev = null;
let reverse = null;
let it = head;
while (it !== null) {
prev = it;
it = it.next;
let temp = {
val: prev.val,
next: reverse,
};
// creating an array of ints without generics
int[] myArray = new int[] {};
// creating lists for ints and strings, respectively
IntList myIntList = new IntList();
StringList myStringList = new StringList();
// creating a list for each using generics
List<int> myGenericIntList = new ArrayList<int>();
List<string> myGenericStringList = new ArrayList<string>();
@prmichaelsen
prmichaelsen / deep-complete.ts
Created May 16, 2019 23:37
recursively mark all properties of a typescript type as defined
/** private type, not exported */
declare type NonObject = undefined | null | boolean | string | number | Function;
/**
* This type allows you to mark an object with
* optional properties as required.
*/
export declare type Complete<T> = {
[K in keyof T]-?: T[K];
}
/**