Skip to content

Instantly share code, notes, and snippets.

View gintsmurans's full-sized avatar
👏
javascript

Gints Murāns gintsmurans

👏
javascript
View GitHub Profile
@gintsmurans
gintsmurans / openai_test.py
Created December 9, 2023 17:15
Test for openai memory leaks
"""
1. install openai and memory_profiler
2. Add following to class Completions(SyncAPIResource):
def forceClose(self):
self.with_raw_response = None
3. Add following to class class OpenAI(SyncAPIClient):
@gintsmurans
gintsmurans / move_images_by_exif_date.py
Last active March 22, 2023 23:18
Image exif helpers
#!/usr/bin/env python3
import os
import re
import shutil
from datetime import datetime
from pathlib import Path
from PIL import Image
import argparse
import logging
@gintsmurans
gintsmurans / cleanup.py
Last active July 19, 2022 12:56
Cleanup docker registry
#!/usr/bin/env python3
# This script will cleanup docker registry images, that are older than 7 days (see REMOVE_OLDER_THAN_DAYS).
# Note: This will only work on v2 registry.
# Before running make sure you have:
#  1. Installed requirements by running `python3 -m pip install -r requirements.txt`
#  2. Put registry password in `.registry-password` file
#  3. Updated correct values in `Constants` section
# Then run `python3 cleanup.py` or `chmod +x cleanup.py && ./cleanup.py`
# After cleaning registry, run garbage collector on registry, for example: `docker compose exec registry sh -c "/bin/registry garbage-collect --delete-untagged /etc/docker/registry/config.yml"`
#!/bin/bash
#
# Make sure you have screen installed (on debian). On Arch linux no screen is required.
# Debian:
# apt-get install screen
#
# Monit example:
# check process ssh-tunnel matching "^ssh -N sshtunnel"
# user root
# start program = "/root/ssh_tunnel.sh"
@gintsmurans
gintsmurans / debian_unifi_nvr_letsencrypt.bash
Last active September 8, 2023 00:37
Unifi NVR + letsencrypt certificate
#!/bin/bash
## Unifi NVR + letsencrypt certificate
# Remember to use fullchain.pem
# Thanks: https://www.john.geek.nz/2018/05/using-letsencrypt-with-ubiquiti-unifi-video-server/
#
# Also remember adding `ufv.custom.certs.enable=true` to the `/usr/lib/unifi-video/data/system.properties` file
#
HOSTNAME=XXX.gm.lv
@gintsmurans
gintsmurans / jquery.serializeObject.js
Last active February 20, 2021 19:34
Serialize form fields recursively into json type object
// jQuery addons
// Serialize form fields recursively into json type object,
// so for example <input type="text" name="record[type][x]" value="1"> becomes {type: {x: 1}}
var
rbracket = /\[\]$/,
rarrayKeys = /\[(.*?)\]/g,
rarrayKeysPrefix = /^(.*?)\[.*/g,
rCRLF = /\r?\n/g,
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
CREATE OR REPLACE FUNCTION jsonb_array_search(json_arr jsonb, col TEXT, search_for TEXT) RETURNS boolean
LANGUAGE plpgsql IMMUTABLE AS $$
DECLARE
rec jsonb;
len int;
ret boolean = false;
BEGIN
-- If json_arr is not an array, return false
BEGIN
len := jsonb_array_length(json_arr);
#!/usr/bin/env python3
# Little library for email and sms (using SMSEagle - http://www.smseagle.eu/) notifications.
# Can be used as a command line or library.
# For this to work please set SMTP and SMSEAGLE parameters
import argparse
import smtplib
import json
from email.mime.text import MIMEText
@gintsmurans
gintsmurans / Functions.php
Last active February 6, 2016 11:02
Various useful php functions
<?php
/**
* Returns fixed floating number with precision of $precision. Replaces "," to "." and " " to "".
*
* @param $input mixed
* @param $precision int
* @return float
*/
function fixFloat($input, $precision = -1)
@gintsmurans
gintsmurans / session_helpers.php
Created November 5, 2015 11:42
Session expire and destroy other sessions
<?php
const SESSION_EXPIRATION_TIME = 100; // Seconds
function session_expire()
{
if (empty($_SESSION['last_visit'])) {
$_SESSION['last_visit'] = time();
}
if ($_SESSION['last_visit'] + SESSION_EXPIRATION_TIME < time()) {