Skip to content

Instantly share code, notes, and snippets.

@P4
P4 / default.reg
Last active April 13, 2024 05:23
Color schemes for Windows Command Prompt
Windows Registry Editor Version 5.00
; Default color scheme
; for Windows command prompt.
; Values stored as 00-BB-GG-RR
[HKEY_CURRENT_USER\Console]
; BLACK DGRAY
"ColorTable00"=dword:00000000
"ColorTable08"=dword:00808080
; BLUE LBLUE
@P4
P4 / Your language sucks.md
Last active May 18, 2023 09:29
Your programming language sucks

You appear to be advocating a new...

  • Functional
  • Imperative
  • Object-oriented
  • Procedural
  • Stack-based
  • "Multi-paradigm"
  • Lazy
  • Eager
@P4
P4 / CustomLeafletMarkers.ts
Created September 7, 2016 20:49
Testing extending Leaflet components via TypeScript's inheritance model
/// <reference path='../leaflet/leaflet.d.ts' />
namespace L {
type LatLngExpression = L.LatLng | number[] | ({ lat: number; lng: number });
export var JSMarker = L.Marker.extend({
options: { title: 'MyMarker' },
initialize: function(latLng: LatLngExpression, options?: L.MarkerOptions) {
@P4
P4 / konami.ts
Created July 15, 2021 16:54
Konami code in 7 lines of RxJS
import {find, fromEvent, scan} from 'rxjs';
const up = "ArrowUp", down = "ArrowDown", left = "ArrowLeft", right = "ArrowRight";
const sequence = [up, up, down, down, left, right, left, right, "b", "a"];
fromEvent<KeyboardEvent>(document, 'keyup').pipe(
scan((i, {key}) => (sequence[i] == key) ? i+1 : 0, 0),
find(i => i == sequence.length)
).subscribe(() => console.log("unlocked"))
@P4
P4 / immutable.ts
Created June 17, 2021 16:53
Make a TypeScript type readonly, recursively
type AnyFunction = (...args: any[]) => any;
type ImmutablePrimitive = undefined | null | boolean | string | number | AnyFunction;
type Immutable<T> =
T extends ImmutablePrimitive ? T :
T extends Map<infer K, infer V> ? ReadonlyMap<Immutable<K>, Immutable<V>> :
T extends Set<infer E> ? ReadonlySet<Immutable<E>> :
{ readonly [P in keyof T]: Immutable<T[P]> }
@P4
P4 / user-script.util.js
Created July 10, 2020 14:56
UserScript utilities
/** returns a promise that resolves when element becomes available */
function waitForElement(selector, timeout=1000) {
return new Promise((resolve, reject) => {
let start, element;
requestAnimationFrame(function wait(timestamp) {
if (start == null) start = timestamp;
element = document.querySelector(selector);
if (element) {
resolve(element);
} else {
@P4
P4 / coerce-boolean.ts
Created April 7, 2020 19:26
coerceBooleanProperty as property decorator
function coerceBooleanProperty(prop: unknown): boolean {
return !!prop;
}
const CoerceBoolean: PropertyDecorator = (proto, prop) => {
const values = new WeakMap();
Object.defineProperty(proto, prop, {
get() {
return values.get(this)
},
@P4
P4 / synology-reload.sh
Created May 8, 2019 21:26
acme.sh reloadcmd for Synology NAS; updates the certificate copies used by services with the renewed certificate, then reloads the service.
#!/bin/bash
# Let's Encrypt Certificate reload on Synology NAS
# Services configured through DSM to use a given certificate create their own copies of the certificate files.
# This script will update those copies after the original certificate is renewed.
#
# Install and configure acme.sh on the Synology NAS by following the tutorial:
# https://github.com/Neilpang/acme.sh/wiki/Synology-NAS-Guide
CERT_DIR=/usr/syno/etc/certificate
interface Inner<T> {
value: T;
}
interface Numeric {
content: Inner<number>;
}
interface Text {
content: Inner<string>;
@P4
P4 / create_sde_connection.py
Created October 5, 2016 22:14 — forked from odoe/create_sde_connection.py
Arcpy script to add data to mxd and publish to ArcGIS server without ArcMap
'''
Created on Feb 24, 2011
The purpose of this script is to create the SDE connection file needed to connect to your SDE
@author: rrubalcava
'''
import os, arcpy
class CreateSDEConnection: