Skip to content

Instantly share code, notes, and snippets.

@tvler
tvler / getLinkifiedString.tsx
Last active October 29, 2022 01:04
Turn a string into JSX with autolinks
type LinkifiedString = Array<string | JSX.Element> | string | null | undefined
/**
* Turn a string into JSX with autolinks
*/
export function getLinkifiedString(str: string | null | undefined): LinkifiedString {
try {
// Group by whitespace (wrapping regex in parens keeps matched results in the array)
const substrings = str?.split(/(\s+)/g)
@tvler
tvler / hoc.tsx
Last active November 7, 2021 01:06
A type-safe high-order-component creator that injects a prop named a given string, with a type inferred by a given hook's return value.
/**
* A type-safe high-order-component creator
* that injects a prop named a given string,
* with a type inferred by a given hook's
* return value.
*
* Ex:
* const Component = ({ name }) => {
* return <>Hello {name}</>;
* };
@tvler
tvler / ImplicityTypedActionPayloadByActionType.ts
Last active April 22, 2020 00:39
Implicitly type an action payload by an action type
type ActionTypes = 'actionA' | 'actionB' | 'actionC' | 'actionNoPayload';
type ActionPayloads = {
actionA: { payload: number };
actionB: { payload: string };
actionC: { foo: boolean; bar: boolean };
};
type Actions = {
[key in ActionTypes]: {
@adamgit
adamgit / .gitignore
Last active June 2, 2024 09:58
.gitignore file for Xcode4 / OS X Source projects
#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.6
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
@coryalder
coryalder / Appropirate.py
Created May 17, 2011 05:51
Creates a glitching effect called "datamoshing" using pygame and pymedia
#! /usr/bin/env python
# based on vplayer.py (http://pymedia.org/tut/src/vplayer.py.html) by dmitry borisov (http://pymedia.org)
# bloated and uglied for fair reasons by sven könig (http://www.popmodernism.org)
import sys, thread, time, traceback, Queue, os
import optparse
import pymedia
import pymedia.video.muxer as muxer