Skip to content

Instantly share code, notes, and snippets.

View boertel's full-sized avatar

Benjamin Oertel boertel

View GitHub Profile
@dejager
dejager / RoundedPolygon.swift
Created October 18, 2022 05:57
A SwiftUI Shape that draws a polygon with a given number of corners and a corner radius.
//
// RoundedPolygon.swift
//
// Created by Nate on 2022-10-17.
//
import SwiftUI
struct RoundedPolygon: Shape {
@nathanborror
nathanborror / gcloud-run.md
Last active May 31, 2022 15:50
How to setup a new Go project using Google Cloud Run and Cloud SQL.

Go Google Cloud

How to setup a new Go project using Google Cloud Run and Cloud SQL.

Setup a new project

Update gcloud and authenticate

$ gcloud components update
$ gcloud auth login
@progrium
progrium / datetimeformat.js
Last active November 20, 2021 04:02
Intl.DateTimeFormat is kinda nutty with custom format strings, this makes it sane
function dateTimeFormat(timestamp, locale, str, ...opts) {
const d = new Date(timestamp);
return str.replace(/{(\d+)}/g, function(match, number) {
return typeof opts[number] != 'undefined'
? new Intl.DateTimeFormat(locale, opts[number]).format(d)
: match;
});
}
console.log(dateTimeFormat("2021-11-19T19:19:36.598071-06:00", "en", "{0} at {1}!", {dateStyle:"short"}, {timeStyle:"long"}))
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@steven2358
steven2358 / ffmpeg.md
Last active July 22, 2024 08:40
FFmpeg cheat sheet
@ryanflorence
ryanflorence / FiniteMachine.js
Created December 1, 2017 21:06
finite-machine.js
import React, { Component } from "react"
import { Machine } from "xstate"
import * as PropTypes from "prop-types"
class FiniteMachine extends Component {
machine = Machine(this.props.chart)
state = {
data: this.props.reducer(undefined, { type: "@init" }),
machineState: this.machine.getInitialState()
@fgaudin
fgaudin / decorators.md
Created May 31, 2017 19:10
Decorators in python

from @fgaudin blogpost that disappeared from the Internet

Probably like a lot of you, I’ve googled or checked Django’s code to know how to write my own decorators. And every time I was a bit confused, just copy/pasting the examples and changing the code until it works.

While working on a decorator which was basically an aggregation of other decorators, I’ve finally had to get a deeper understanding, so I’ll try to make it clear for you.

Decorators are functions

First, we’ll forget the annotation notation with the @ to understand them better. So when you do:

// declaration
function foo (n) { return n + 1; }
// expression
// note, fat arrow functions have very different meaning (usually what I want, though)
var foo = function (n) { return n + 1; };
var foo = (n) => { return n + 1; };
var foo = n => n + 1;
// object methods
@tkafka
tkafka / LICENSE.txt
Last active May 17, 2024 02:08
Drop-in replacement for ReactCSSTransitionGroup that uses velocity.js instead of CSS transforms. Add your own transitions to `transitions` hash.
The MIT License (MIT)
Copyright (c) 2014 Tomas Kafka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@soopa
soopa / reference-api-designs.md
Last active April 22, 2023 10:56
A running list of API designs worth referencing, alphabetized.