Skip to content

Instantly share code, notes, and snippets.

View keithort's full-sized avatar

Keith Ort keithort

View GitHub Profile
@chaance
chaance / example.ts
Created August 12, 2021 03:39
Merge discriminated union props for better easier destructuring
type SomeProps =
| { action: "START" }
| { action: "STOP"; time: number }
| { action: "PAUSE"; time: number; ref: { current: any } };
function useExample(props: SomeProps) {
let {
action, // "START" | "STOP" | "PAUSE"
time, // number | undefined,
ref // { current: any } | undefined
@jamiebuilds
jamiebuilds / tradeoffs-in-value-derived-types-in-typescript.md
Last active December 16, 2022 17:21
Value-derived types in TypeScript are super powerful, but you should be thoughtful in how/when you use them

Tradeoffs in value-derived types in TypeScript

Many of the more "advanced" typescript features can be used for creating "value-derived" types.

At its simplest form:

let vehicle = { name: "Van", wheels: 4 }
@nth-commit
nth-commit / VariadicPipe.ts
Last active September 29, 2022 21:47
Function composition in TypeScript 4.1 (on top of ixjs's pipe)
import { OperatorFunction } from 'ix/interfaces';
import { pipe } from 'ix/iterable';
import { map } from 'ix/iterable/operators';
/**
* Creates a new type which is the first element of a non-empty tuple type.
*
* @example type T = Head<[string, number, Object]>; // string
*/
export type Head<Ts extends [any, ...any[]]> = Ts extends [infer T, ...any[]] ? T : never;
@scottjehl
scottjehl / whichones.js
Created August 21, 2020 15:40
which elements are wider than the viewport?
var list = [];
document.querySelectorAll("body *")
.forEach(function(elem){
if(elem.getBoundingClientRect().width > document.body.getBoundingClientRect().width){
list.push(elem.outerHTML.split('>')[0] + '>');
}
});
confirm( "these elements are wider than the viewport:\n\n " + list.join("\n") )
@paulirish
paulirish / what-forces-layout.md
Last active April 8, 2025 12:26
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@ericelliott
ericelliott / essential-javascript-links.md
Last active March 22, 2025 17:28
Essential JavaScript Links
@staltz
staltz / introrx.md
Last active April 8, 2025 04:41
The introduction to Reactive Programming you've been missing
@Integralist
Integralist / 0. JavaScript Function Programming TOC.md
Last active July 3, 2018 04:57
JavaScript Function Programming (scratch pad) -> Most of the code here is modified from the excellent O'Reilly book "Functional JavaScript".

This code is modified from the excellent O'Reilly book "Functional JavaScript". You should buy it, I highly recommend it! Don't kid yourself into thinking this gist even remotely covers the great content from a 200+ page technical book on the subject; it doesn't. Buy the book and get the in-depth knowledge for yourself. It's worth it.

<?php
function gfc_customers_update_7001() {
//Move the scoreboard to the scoreboard region
db_update('block')
->fields(array(
'weight' => 2,
'region' => 'scoreboard_only',
))
->condition('module', 'views')
<?php
include_once DRUPAL_ROOT . "/sites/golfchanneldev.prod.acquia-sites.com/settings.php";
$conf['stage_file_proxy_origin'] = 'http://www.golfchannel.com';
$conf['refresh_score_pages'] = FALSE;
$conf['gfc_customers_api_golfnow_url'] = 'http://develop.gnsvc.com/V1.1/TeeTimesAPIRest.svc/';
$conf['https'] = FALSE;
$cookie_domain = '.golfchannel.local';
// $conf['securepages_basepath'] = 'http://golfchannel.local';
// $conf['securepages_basepath_ssl'] = 'https://secure.golfchannel.local';