Skip to content

Instantly share code, notes, and snippets.

@nthe
nthe / Option.py
Last active April 15, 2022 18:45
from typing import Callable, Generic, TypeVar
T = TypeVar("T")
class Option(Generic[T]):
def __init__(self, value: T) -> None:
self._value: T = value
self._binds: list[Callable] = []
@nthe
nthe / uia-edge-perf-test.ps1
Created February 7, 2022 12:52
UI Automation Performance Test
Add-Type –AssemblyName UIAutomationClient
Add-Type –AssemblyName UIAutomationTypes
Write-Output "===== UI automation and accessibility test ====="
# start an instance of Microsoft Edge and wait for it to load
Write-Output "Starting an instance of Microsoft Edge"
Start-Process msedge "-inprivate https://en.wikipedia.org/wiki/Main_Page"
Start-Sleep –s 2
@nthe
nthe / inflections.py
Last active January 15, 2023 13:06
Find inflection points in the array.
from typing import Any, Iterator
def yield_unique_in_order(array: list) -> Iterator[tuple[Any, int]]:
"""Yields unique value and their respective indices in order.
Args:
array: Array of values.
Returns:
Iterator over unique values and their indices.
@nthe
nthe / ScreenRec.cs
Last active January 16, 2023 04:33
Screen recording app using ffmpeg with pause / resume support.
using System;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.IO.Compression;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ScreenRec
{
@nthe
nthe / ConcurrentQueue.cs
Created February 3, 2020 21:11
ConcurrentQueue with MTA threads example
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace dotnetpad
{
class Program
{
@nthe
nthe / background.js
Created January 29, 2020 19:23
URL tracking cross-browser web-extension.
(function (window) {
/* reference exposed api based on browser */
const API = window.chrome || window.browser;
/* IP address used for calls */
let IPAddress = "0.0.0.0";
/* polling period in miliseconds */
@nthe
nthe / noisy_attractor.pde
Last active September 2, 2019 19:53
Noisy Attractor | Processing
float A = -2.337,
B = -2.337,
C = 0.2553,
D = 1.378,
dx = 0.1,
dy = 0.1;
float X() {
return A * sin(dx * A) - sin(dy * D);
}
@nthe
nthe / shallow_water.pde
Created August 23, 2019 10:19
Shallow Water | Processing
import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;
/**
* varaibles
*/
float
cx,
cy,
@nthe
nthe / perf.js
Last active August 19, 2018 11:29
Simple performance monitor implemented as higher order component.
import React, { unstable_Profiler as Profiler } from "react";
/**
* Profiles storage.
*/
const profiles = {};
/**
* Calculate weighted average.
* @param {number} time - time passed
@nthe
nthe / api-cache.js
Last active January 20, 2023 15:11
Simple API cache for redux-observable
/**
* Check if cached record is valid.
* @param {object} cachedValue - cache record
* @param {number} cacheTime - time to cache
* @returns {bool}
*/
const isCached = (cachedValue, cacheTime) =>
(new Date() - cachedValue.at) / 1000 < cacheTime;
/**