Skip to content

Instantly share code, notes, and snippets.

View AmazingTurtle's full-sized avatar
🐢
turtle on SPEED

Felix AmazingTurtle

🐢
turtle on SPEED
View GitHub Profile
@AmazingTurtle
AmazingTurtle / command-complete.tsx
Created January 16, 2023 16:10
A customizable command autocompletion react component with arrow navigation and history
import React, {
ChangeEvent,
KeyboardEvent,
forwardRef,
HTMLAttributes,
InputHTMLAttributes,
useCallback,
useMemo,
useState,
FocusEvent,
@AmazingTurtle
AmazingTurtle / icao-transliteration.ts
Last active January 31, 2022 12:35
ICAO MRZ Transliteration (by ICAO Doc 9303 Part 3)
// spec can be found here:
// https://www.icao.int/publications/Documents/9303_p3_cons_en.pdf
// prettier-ignore
// noinspection NonAsciiCharacters
const transliterationMapping: Record<number, string|string[]> = {
0x0020: '<',
0x002C: '<',
0x002D: '<',
0x00C0: 'A',
@AmazingTurtle
AmazingTurtle / config.ts
Created July 7, 2021 11:17
openai client
export const DEFAULT_ENGINE = 'davinci';
export const ENGINE_LIST = ['ada', 'babbage', 'curie', 'davinci', 'davinci-instruct-beta', 'curie-instruct-beta'];
export const ORIGIN = 'https://api.openai.com';
export const DEFAULT_API_VERSION = 'v1';
export const DEFAULT_OPEN_AI_URL = `${ORIGIN}/${DEFAULT_API_VERSION}`;
{
"openapi": "3.0.0",
"info": {
"title": "redacted",
"description": "The redacted API description",
"version": "1.0",
"contact": {}
},
"tags": [],
"servers": [],
@AmazingTurtle
AmazingTurtle / how-to-restore.md
Last active April 1, 2024 17:47
restore access to unifi controller

Restore access to a unifi controller

When you are unable to login to the unifi controller or forgot admin password, you can restore access using SSH and manipulating mongodb directly.

Warning

Do not uninstall unifi controller - most of the data is not stored in mongodb. In case you thought a mongodb backup would be sufficient, you may have fucked up already, just like me. However I managed to write this "tutorial" for anyone to not run into the same trap.

Apparently this guide no longer works with recent unifi controller versions (starting nov/dec 2022). Since I no longer use unifi hardware in my home system, I can not update the guide myself. In case you've gotten here to recover your data, you're likely doomed. But giving it a try won't hurt anyway, therefore: good luck.

import {AuthenticationError} from '../errors/authenticationError';
export default (app) => {
app.use((error, request, response, next) => {
if (error || response.sentry) { // using Sentry in my specific case aswell
if (error instanceof AuthenticationError) {
response.statusCode = 401;
response.end(
JSON.stringify({
@AmazingTurtle
AmazingTurtle / ThrottlePlugin.cs
Created October 1, 2016 13:51 — forked from coryt/ThrottlePlugin.cs
ServiceStack plugin to throttle api requests
public class ThrottlePlugin : IPlugin
{
/// <param name="redisHost">host name</param>
/// <param name="redisPort">port</param>
/// <param name="redisPassword">password</param>
public ThrottlePlugin(string redisHost, int redisPort, string redisPassword = null)
{
_redisClient = new RedisClient(redisHost, redisPort, redisPassword);
}
using System;
using System.Linq;
using System.Threading.Tasks;
using TWRC.Network;
using TWRC.Network.Handler;
using Dapper;
namespace TWRC.Game.Network.Handler
{
public class JoinServer : HandlerBase<Client.VirtualClient>
@AmazingTurtle
AmazingTurtle / gist:dc4c20c5d2c170553796
Created April 6, 2015 16:32
c# not disposing new parameter
namespace Disposetest
{
class test : IDisposable
{
public void Dispose()
{
Console.WriteLine("disposing");
}
}