Skip to content

Instantly share code, notes, and snippets.

@sebastiankade
sebastiankade / iso-date.ts
Created October 17, 2024 07:47
ISO-Date Proposal
export type TZDate = `${number}-${number}-${number}Z`;
export type TZDateTime =
| `${number}-${number}-${number}T${number}:${number}:${number}Z`
| `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;
export type CalDate = `${number}-${number}-${number}`;
export type CalDateTime =
| `${number}-${number}-${number}T${number}:${number}:${number}`
| `${number}-${number}-${number}T${number}:${number}:${number}.${number}`;
@sebastiankade
sebastiankade / date-fp.md
Last active August 22, 2024 21:14
Deleting The JS Date Object: FP Dates

Principles

  • JS Date object is magic (magic is bad)
  • We prefer to separate data from logic
  • Side effects are bad (FP)
  • Timezones are not as confusing as we have made them

Mental Model

First, a new mental model for thinking about dates (yes dates include datetimes).

1. Calendar Dates

@sebastiankade
sebastiankade / modern-id-spec.md
Last active October 12, 2024 15:42
Stop using UUIDs: The Modern ID Spec

Modern ID Spec

An adaptable, human-friendly, web-safe, unique ID spec for modern applications.

Guiding Principles

  • Short
  • Human friendly
  • URL-safe
  • Developer experience
find src/ -name "lib.ts" -exec sh -c 'mv "$0" "${0%lib.ts}utils.ts"' {} \;
website {
index_document = "index.html"
error_document = "error.html"
routing_rules = <<EOF
[{
"Condition": {
"HttpErrorCodeReturnedEquals": "404",
"KeyPrefixEquals": ""
@sebastiankade
sebastiankade / promise.ts
Created May 19, 2019 00:46
Typescript wrapper for node util promisify
import * as util from "util";
type Maybe<T> = T | undefined | null;
export function promisify<Args, R>(
fn: (arg: Args, callback: (e: Maybe<Error>, result: R) => void) => void,
self?: any
): (arg: Args) => Promise<R> {
return util.promisify(fn).bind(self);
}
// Serverless.yml
functions:
myCloudWatch:
handler: myCloudWatch.handler
events:
- cloudwatchEvent:
event:
source:
- "aws.mediaconvert"
detail-type:
@sebastiankade
sebastiankade / media.js
Last active April 15, 2019 08:39
Get duration of video or audio in react browser
export const getVideoDuration = async (file) =>
new Promise((resolve, reject) => {
const mediaType = file.type.split("/")[0];
if (mediaType === "video" || mediaType === "audio") {
var video = document.createElement(mediaType);
video.preload = "metadata";
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
resolve(video.duration);
};
// export the default export of a legacy (`export =`) module
export import MessageBase = require('./message-base');
// export the default export of a modern (`export default`) module
export { default as MessageBase } from './message-base';
// export an interface from a legacy module
import Types = require('./message-types');
export type IMessage = Types.IMessage;
'body':
'cmd-shift-down': 'window:focus-next-pane'
'cmd-shift-up': 'window:focus-previous-pane'
'cmd-ctrl-right': 'window:focus-next-pane'
'cmd-ctrl-left': 'window:focus-previous-pane'
'.platform-darwin':
'shift-cmd-alt-right': 'move-panes:move-next'
'shift-cmd-alt-left': 'move-panes:move-previous'
'shift-cmd-S': 'project-find:show'
'cmd-shift-o': 'fuzzy-finder:toggle-file-finder'