Skip to content

Instantly share code, notes, and snippets.

@eslof
eslof / build_function.php
Last active July 16, 2023 16:13
build gpt 0613 typescript function definition from openai spec php array
function generateTypeScript($dummy): string {
$output = "// " . $dummy['description'] . "\n";
$output .= "type " . $dummy['name'] . " = (_: {\n";
$output .= generateProperties($dummy['parameters']['properties'], $dummy['parameters']['required'], false);
$output .= "}) => any;\n";
return $output;
}
function generateProperties($properties, $required, $indent): string {
$output = '';
@eslof
eslof / chatgpt_to_png.py
Last active December 10, 2022 13:34
script to take a right click -> save as (Web page, Single File) .mht file and save it as a png
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from io import BytesIO
from base64 import b64decode
from PIL import Image
from tkinter import Tk
from tkinter.filedialog import askopenfilename, asksaveasfilename
@eslof
eslof / game.php
Last active March 19, 2022 18:39
swoole process + websocket server
<?php declare(strict_types=1);
use Swoole\WebSocket\Server;
use Swoole\WebSocket\Frame;
const CONCURRENT_MAX = 5;
const INPUT_TYPE_COL = 'input';
$server = new Server("0.0.0.0", 9502);
$table = new Swoole\Table(CONCURRENT_MAX);
$table->column(INPUT_TYPE_COL, Swoole\Table::TYPE_INT, 4);
@eslof
eslof / bokborsen.py
Created December 12, 2021 16:19
Script I made for my mother to easily renew her oldest listings on bokborsen.se. Usage: python script.py email password
import sys
import time
from requests import Session
import requests
import urllib.parse
from bs4 import BeautifulSoup
@eslof
eslof / srt_fix.py
Created December 12, 2021 15:47
Renames SRT files to match MP4 names in folder in sorted order (e.g. by episode) to be auto-detected by media players.
from functools import partial
from pathlib import Path
print_app = partial(print, "SRT Fix:")
files = [f for f in Path().iterdir() if f.is_file()]
mp4 = sorted([f for f in files if f.suffix.lower().endswith(".mp4")])
srt = sorted([f for f in files if f.suffix.lower().endswith(".srt")])
assert len(mp4) == len(srt), f"Count miss! MP4s: {len(mp4)}, SRTs: {len(srt)}."
print_app(
f"Looking at {len(mp4)} MP4 files with matching subs starting with"
@eslof
eslof / SingletonMonoBehaviour.cs
Created June 6, 2021 18:10 — forked from ErikOG/SingletonMonoBehaviour.cs
Most singletons out there will 'destroy' other instances, I think there shouldn't be more than one instance of it to begin with, if there are we just want to find out about it so we can fix the core of the problem and not just the symptom.
using UnityEngine;
#if UNITY_EDITOR || DEBUG
using System;
using UnityEngine.SceneManagement;
#endif
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour {
private static T _instance = null;
public static T Instance {
@eslof
eslof / sqlite_seeded_random.py
Created June 3, 2020 19:01
Python ORDER BY Random with Seed in Sqlite3
import sqlite3
import random
def seeded_random_collation(string1, string2):
return random.randint(-1, 1)
try:
con = sqlite3.connect("db.sqlite")