Skip to content

Instantly share code, notes, and snippets.

View pbroschwitz's full-sized avatar

Peter Broschwitz pbroschwitz

View GitHub Profile
@pbroschwitz
pbroschwitz / machine.js
Last active July 24, 2022 19:18
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@pbroschwitz
pbroschwitz / function-overloading-with-compose.ts
Created July 19, 2022 18:46
Master FUNCTION OVERLOADS with 'compose' - example from Matt Pocock
// See https://www.youtube.com/watch?v=D1a8OoBWi1g&list=PLIvujZeVDLMx040-j1W4WFs1BxuTGdI_b&index=10
function compose(...args: any[]) {
return {} as any;
}
const addOne = (a: number) => {
return a + 1;
}
@pbroschwitz
pbroschwitz / supplant.js
Created October 15, 2012 07:58
supplant - Crockford
/**
* supplant() does variable substitution on the string. It scans through the string looking for
* expressions enclosed in { } braces. If an expression is found, use it as a key on the object,
* and if the key has a string value or number value, it is substituted for the bracket expression
* and it repeats.
*
* Written by Douglas Crockford
* http://www.crockford.com/
*/
String.prototype.supplant = function (o) {
@pbroschwitz
pbroschwitz / index.md
Last active May 25, 2022 13:43
Object literal may only specify known properties in TypeScript - ts(2345)

Problem

const someArray = ['foo', 'bar']
const someOtherArray = ['foobar', 'barfoos']

const config = [
    ...someArray,
    ...someOtherArray,
    {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parent iframe</title>
</head>
<body>
<h1>Parent iframe</h1>
<textarea id="log" width="40" height="30"></textarea>
@pbroschwitz
pbroschwitz / hack.sh
Created March 31, 2012 09:58 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
/**
* This is similar to http://php.net/manual/en/function.array-reduce.php but returns
* the return from the callback immediately when it is 'truthy'. The callback also
* is being passed the 'key' in addition to just the 'value'. So this is basically
* some sort of more flexible array_reduce, array_filter and array_search
*/
function array_find($array, $callback) {
foreach ($array as $key => $value) {
$result = $callback($value, $key);
if ($result) {
// Paste this for example to the console
window.addEventListener(“beforeunload”, function() { debugger; }, false)
@pbroschwitz
pbroschwitz / align-text-with-different-font-size-in-flexbox.markdown
Last active June 18, 2020 15:56
Align text with different font-size in flexbox
@pbroschwitz
pbroschwitz / launch.json
Last active March 18, 2020 13:49
vscode launch.json - debug jest unit tests
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",