Skip to content

Instantly share code, notes, and snippets.

@optinsoft
optinsoft / formatdate.js
Last active December 13, 2025 11:18
Formats a JavaScript Date into a local timestamp string: YYYY-MM-DDTHH:MM:SS.mmm.
/**
* Formats a Date object into a string of the form:
* YYYY-MM-DDTHH:MM:SS.mmm
*
* All numeric components are zero-padded to ensure fixed width.
* The result reflects the local time of the supplied Date object
* and does not include any timezone suffix.
*
* @param {Date} dt - The Date object to format.
* @returns {string} The formatted timestamp string.
@optinsoft
optinsoft / gist:3160f8f81e9d610a0fe000b3c13be38f
Created June 26, 2025 15:30
replace placeholders enclosed in curly braces, like {thread}, {thread%10}, {thread/10}, with values
class NumReplacer(dict):
def __init__(self, **kwargs):
dict.__init__(self, **kwargs)
def __missing__(self, key):
karr = key.split('%')
if (len(karr) == 2) and karr[1].isdigit():
value = dict.get(self, karr[0], None)
if not value is None:
mod = int(karr[1])
return str(value % mod)
@optinsoft
optinsoft / gist:02b9dcce3afe6419e72cae9ed9fc975d
Last active June 11, 2025 15:55
Convert javascript class to object
async function classToObject(clss) {
var clss_list = []
var promises = []
function c2o(clss) {
const isObject = v => typeof v === "object" && v !== null
const isFunction = v => typeof v === "function"
const isRecursion = v => clss_list.find(item => item.clss === v)
const keys = x => Object.getOwnPropertyNames(x).concat(Object.getOwnPropertyNames(x?.__proto__||{})).filter(k => k !== 'enabledPlugin')
var object = {}
clss_list.push({clss, object})
@optinsoft
optinsoft / gist:f7665b0593eea392fca355ef3561c0db
Created March 13, 2025 12:34
Extract visited domains from chrome history
/* Chrome History Sqlite Db: C:\Users\YOUR_USER_NAME\AppData\Local\Google\Chrome\User Data\Default\History */
select distinct substr(substr(' '||top_level_url,instr(' '||top_level_url, '//')+2),1,instr(substr(' '||top_level_url,instr(' '||top_level_url, '//')+2)||'/','/')-1) as domain
from visited_links
@optinsoft
optinsoft / gist:b80edef76ab87fde778922960cfacbb7
Created January 29, 2025 16:27
Install Windows Terminal on Windows 2022
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x86.14.00.Desktop.appx
Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.5/Microsoft.UI.Xaml.2.8.x64.appx -OutFile Microsoft.UI.Xaml.2.8.x64.appx
Invoke-WebRequest -Uri https://github.com/microsoft/terminal/releases/download/v1.19.11213.0/Microsoft.WindowsTerminal_1.19.11213.0_8wekyb3d8bbwe.msixbundle -OutFile Microsoft.WindowsTerminal_1.19.11213.0_8wekyb3d8bbwe.msixbundle
Add-AppxPackage Microsoft.VCLibs.x86.14.00.Desktop.appx
Add-AppxPackage .\Microsoft.UI.Xaml.2.8.x64.appx
Add-AppxPackage .\Microsoft.WindowsTerminal_1.19.11213.0_8wekyb3d8bbwe.msixbundle
@optinsoft
optinsoft / get_requirements.ps1
Created September 6, 2024 07:37
Get requirements for python
pip freeze > '.\requirements.tmp'
Get-Content '.\requirements.tmp' | Out-File '.\requirements.txt' -Encoding "utf8"
@optinsoft
optinsoft / imresize.py
Created August 6, 2024 10:29
Resize OpenCV image (crop or add border when required)
import cv2
RESIZE_IMAGE_CROP: int = 0
RESIZE_IMAGE_PAD: int = 1
ResizeImageFlags = int
"""One of [RESIZE_IMAGE_CROP(default), RESIZE_IMAGE_PAD]"""
def resize_image_canvas(img: cv2.typing.MatLike, new_image_width: int, new_image_height: int, flags: ResizeImageFlags) -> cv2.typing.MatLike:
old_image_height, old_image_width = img.shape[:2]
<VirtualHost 127.0.0.1:80>
ServerName video.local
DocumentRoot "c:/WWW/video.local/html"
<Directory "c:/WWW/video.local/html/">
Options FollowSymLinks
DirectoryIndex index.html
Require all granted
AllowOverride All
</Directory>
@optinsoft
optinsoft / eurosport1.php
Created August 3, 2024 08:19
Get eurosport stream URL
<?php
$eurosport_url = 'http://cdntvmedia.com/eurosport-1.php';
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36';
function load_url($url, $referer, &$location, &$contenttype) {
$location = null;
$contenttype = null;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);