Skip to content

Instantly share code, notes, and snippets.

View trusktr's full-sized avatar
📜
writing code

Joe Pea trusktr

📜
writing code
View GitHub Profile
@trusktr
trusktr / image-grid.md
Last active May 1, 2024 19:59
Image grid in Markdown
screen shot 2017-08-07 at 12 18 15 pm blah screen shot 2017-08-07 at 12 18 15 pm screen shot 2017-08-07 at 12 18 15 pm
@trusktr
trusktr / DefaultKeyBinding.dict
Last active April 21, 2024 06:32
My DefaultKeyBinding.dict for Mac OS X
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
Here is a rough cheatsheet for syntax.
Key Modifiers
@trusktr
trusktr / model.tsx
Last active February 2, 2024 17:46
Solid.js directives
import {createEffect, untrack} from 'solid-js';
type GetterSetter = [() => string, (v: string) => void];
type ObjectAndKey = [Record<string, unknown>, string]; // TODO better type
/**
* Use this to make a two-way binding from an input to a signal or a reactive
* object such as a store or mutable. F.e.
*
* ```js
@trusktr
trusktr / circle.js
Created November 2, 2016 21:00
Draw a circle (pixel algorithm)
//First attempt: O(r^2)
function drawCircle(cx, cy, r) {
var dim = 100
for (let i = -r; i<=r; i+=1) {
for (let j = -r; j<=r; j+=1) {
if (
Math.round(Math.sqrt(i*i + j*j)) === r
@trusktr
trusktr / nike-on-tap-ads.md
Last active January 20, 2022 08:55
Nike SB's On Tap ad campaign with transparent plexiglass ramps and flourescent lighting.

Back in 2004 Nike SB produced an ad campaign using clear transparent skate ramps and obstacles illuminated with florescent lights in dark settings. The skaters did tricks over these obstacles while not having the best visibility of the obstacles they were skating. The difficulty of skating these obstacles added to the already awesome visual effect to create a unique and artful series of skate photos like no other. Enjoy!

272232960_1056320618556323_2896897531427220381_n

272074343_296045375908147_8032150437580007298_n

272112947_4773275592740446_3433927735527001096_n

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
type ImplementationKeys = 'static' | 'private' | 'protected'
type FunctionToConstructor<T, TReturn> = T extends (...a: infer A) => void ? new (...a: A) => TReturn : never
// Note, void also works the same in place of unknown
type ReplaceCtorReturn<T, TReturn> = T extends new (...a: infer A) => unknown ? new (...a: A) => TReturn : never
type ConstructorOrDefault<T> = T extends {constructor: infer TCtor} ? TCtor : (() => void)
@trusktr
trusktr / multiple.2.js
Last active May 25, 2020 06:48
Multiple Inheritance Implementation #2 - Copying classes and combining them into a single prototype chain. Fails miserably due to static `super` and use of `eval`, among other problems.
function multiple(...classes) {
// If more than one class extends from a native class, we may need to throw
// an error, since we can't mix native prototypes; We won't throw if the
// native prototypes of one class or in the same chain as the native
// prototypes in the others. For example, if one class extends from Array
// and another from Event, we'll throw an error because we can't put the
// Array prototype before the Event prototype or vice versa
// (`Array.prototype` and `Event.prototype` are `{enumerable:false,
// writable:false, configurable:false}`, so we can't change the __proto__ of
@trusktr
trusktr / .bashrc
Last active April 23, 2020 21:33
Bash configuration with custom prompt, aliases, and some other goodies.
# vim: set ft=sh:
#
# /etc/bash.bashrc.custom
#
## BEGIN ENVIRONMENT VARS
# Add local ruby gems to our PATH. How to add system-wide gems?
export PATH=$PATH:~/.gem/ruby/1.9.1/bin
# proper encoding for the linux terminal (ttys)
@trusktr
trusktr / obliterate.js
Created February 20, 2019 00:15
Obliterate an object
// recursively deletes all properties within an `object` or `function`
// TODO option to also handle non-enumerable but configurable descriptors
function obliterate(obj: object) {
const visited = new WeakSet
_obliterate(obj)
async function _obliterate(obj) {
if (!obj || !(typeof obj === 'object' || typeof obj === 'function')) return
@trusktr
trusktr / images.js
Last active February 8, 2020 19:56
images hosted in via comment embeds.
// host comments via uploading them in the comments.