Skip to content

Instantly share code, notes, and snippets.

@serg06
serg06 / main.js
Last active August 6, 2024 05:06
Greasemonkey script for displaying the real time on Twitch VOD timestamps
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2024-08-06
// @description try to take over the world!
// @author You
// @match https://www.twitch.tv/videos/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// @grant none
// ==/UserScript==
'use strict'
const { pathToFileURL } = require('node:url')
// node_modules/lambda-runtime/dist/node16/UserFunction.js
;(function () {
const __getOwnPropNames = Object.getOwnPropertyNames
const __commonJS = (cb, mod) =>
function __require() {
return (
@serg06
serg06 / main.py
Created December 28, 2022 22:12
Python script for pinging Trusted Traveler Program website for appointments and notifying you by text
import time
from twilio.rest import Client
import requests
from dateutil import parser
# Create client
account_sid = '' # TODO: Grab from Twilio
auth_token = '' # TODO: Grab from Twilio
client = Client(account_sid, auth_token)
from scipy import ndimage
import numpy as np
from PIL import Image
from random import randint
from copy import deepcopy
# set the file path to wherever your provinces.png is located
im = Image.open(r"colors.png")
print('-------------------------------------------')
# DEBUGGING: simply prints the format, size, and mode of your file
@serg06
serg06 / iprange.py
Last active April 16, 2022 19:57
[Python] Get all IPs in a range
import itertools as it
"""
Given a start/end IP, return all IPs in that range (inclusive)
"""
def ipRange(start_ip: str, end_ip: str):
start = [int(x) for x in start_ip.split('.')]
end = [int(x) for x in end_ip.split('.')]
yield start_ip
@serg06
serg06 / powerMod.ts
Last active April 12, 2022 02:01
[TypeScript] powerMod implementation
// x^p mod m
function powerMod(x: number, p: number, m: number): number {
if (m === 1) {
return 0;
}
x = x % m;
let result = 1;
while (p > 0) {
if (p % 2 === 1) {
@serg06
serg06 / regex.ts
Last active April 9, 2022 05:39
[TypeScript] Types for JavaScript's replacerFunction in String.prototype.replaceAll
export interface ReplacerArgs {
match: string; // the matched substring
groups: string[]; // captured groups
offset: number; // offset of match
string: string; // entire string
named_groups?: Record<string, string>; // named capturing groups
}
function parseReplacerArgsMutating(args: [string, ...any[]]): ReplacerArgs {
const named_groups = typeof args[args.length - 1] === 'object' ? (args.pop() as Record<string, string>) : undefined;
@serg06
serg06 / enums.ts
Last active April 9, 2022 05:39
[TypeScript] Iterating over enums
function isStringEnum<T extends Record<string, string | number>>(t: T): boolean {
return typeof Object.values(t).pop() === 'string';
}
export function enumKeys<T extends Record<string, string | number>>(t: T): (keyof T)[] {
return isStringEnum(t) ? Object.keys(t) : Object.keys(t).slice(0, Object.keys(t).length / 2);
}
export function enumValues<T extends Record<string, string>>(t: T): string[];
export function enumValues<T extends Record<string, string | number>>(t: T): number[];
@serg06
serg06 / load-script.js
Last active October 22, 2024 13:37
[JS] Load scripts dynamically
// Function to load a JS file
async function loadScript(url) {
return await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.addEventListener('load', () => resolve());
script.addEventListener('error', () => reject());
document.body.appendChild(script);
});
}
@serg06
serg06 / main.py
Last active March 11, 2021 21:26
PyQt5 / PySide2 QT StyleSheets (qss) dynamic "class" property example
from PySide2.QtCore import QObject, QTimer
from PySide2.QtWidgets import QApplication, QDialog
import sys
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowTitle("My Form")
self.setStyleSheet("""