Skip to content

Instantly share code, notes, and snippets.

@lukacat10
lukacat10 / program_data_path_utils.py
Created April 29, 2024 00:18
Common program data saving directory.
from pathlib import Path
import platform
PROGRAM_DIRECTORY_NAME = "AppName"
def get_program_data_path() -> Path:
path = None
if platform.system() == "Windows":
path = Path.home() / "AppData" / "Roaming" / PROGRAM_DIRECTORY_NAME
@lukacat10
lukacat10 / base64_add_padding.py
Created April 29, 2024 00:15
Adds padding to base64 string if missing. Helps when using sensitive base64 parsers.
def add_padding(encoded_string):
missing_padding = len(encoded_string) % 4
if missing_padding != 0:
encoded_string += "=" * (4 - missing_padding)
return encoded_string
@lukacat10
lukacat10 / wrapper.py
Created April 29, 2024 00:13
A class for wrapping other classes. Wasn't tested :)
from typing import TypeVar, Generic
T = TypeVar("T") # Declare a type variable
class Wrapper(Generic[T]):
def __init__(self, wrapped_obj: T):
self._wrapped_obj = wrapped_obj
def __getattr__(self, attr):
@lukacat10
lukacat10 / openai_schema_generator.py
Created April 29, 2024 00:08
Generate a schema out of a python function automatically for open ai function calling api. Uses the docstring and the typing of the function in order to generate the schema. Doesn't work on every possible edge case at the moment.
from enum import Enum, EnumType
import inspect
import json
from types import NoneType
from typing import Any, Dict, get_args, get_origin
from docstring_parser import DocstringParam, parse
PARAM_TYPE_RESOLUTION_TABLE = {
str: "string",
int: "integer",

Time to end this Proprietary Internet Drivers phenomena

Yes, @Lenovo, I'm talking to you! I'm sleeping in my tent outside your office with my Torches lit and my Pitchforks ready (its a bad joke).

The problem: distros like debian don't include proprietary network drives as part of the operating system installation, causing it to remain offline after installation

  1. Find a computer with an operating system similar to the one you are trying to install (debian in my case) that has good internet connection.
  2. Run the commands suggested below in the Package download section.
  3. Put the resulting .deb files in a usb drive.
  4. Install the .deb files using the command mentioned in the Installation section.
@lukacat10
lukacat10 / Debian-Sleep-README.md
Last active May 19, 2023 16:53
The great guide on sleeping debians

Time to end this sleeping phenomena

Prevent suspend on lock screen timeout:

sudo nano /etc/gdm3/greeter.dconf-defaults

set sleep-inactive-ac-timeout to 0

Note: You might need to restart your computer (or find a way to reload gdm3)

@lukacat10
lukacat10 / README.md
Last active January 1, 2023 11:00
Group azure spot instances by region

Instructions:

  1. Visit: https://azure.microsoft.com/en-us/pricing/spot-advisor/#pricing
  2. Open the console via F12
  3. Paste the script
  4. Move between the different regions in the dropdown menu (click the dropdown and use the arrow keys to move between the regions quickly).
  5. Run getPlans(), or getPlansFromCheapestToMostExpensive(), or getRegionsFromCheapestToMostExpensive(), or getPlansFilteredByPlanTypeFromCheapestToMostExpensive(), or getRegionsFilteredByPlanTypeFromCheapestToMostExpensive().
  6. There is a better way to do that, I'm sure and ashamed of myself.
@lukacat10
lukacat10 / isr_ids.js
Created October 14, 2022 22:11
A set of scripts for generating good or bad israeli phone numbers and ids (JS)
function sum(arr) {
return arr.reduce((partialSum, a) => partialSum + a, 0);
}
Array.prototype.repeat = function(n){
var a = [];
for (var i=0;i<n;[i++].push.apply(a,this));
return a;
@lukacat10
lukacat10 / scratch_6.py
Last active October 8, 2022 21:05
Auto create variadic method overloads for extended unity events
import re
count = 4
thing_to_replace = "<T0>"
input = """public static bool HasPersistentListenerMethod<T0>(this UnityEvent<T0> uEvent, UnityAction<T0> action)
{
var methodName = action.Method.Name;
for (int i = 0; i < uEvent.GetPersistentEventCount(); i++)
{