Skip to content

Instantly share code, notes, and snippets.

View jasalt's full-sized avatar

Jarkko Saltiola jasalt

View GitHub Profile
@jasalt
jasalt / ssh_ngrok
Created January 3, 2024 13:40
SSH straight to server behind dynamic NGROK address/port using new NGROK API
#!/usr/bin/env bash
# Connect to a dynamic NGROK endpoint that changes ofter after server restart etc.
# Works with single active tunnel (per account) on free tier.
# Provides persistent or dedicated endpoint like premium experience.
# Requires environment variable $NGROK_APIKEY
NGROK_ENDPOINT=$(curl -s https://api.ngrok.com/tunnels -H "authorization: Bearer $NGROK_APIKEY" -H "ngrok-version: 2" | jq -r '.tunnels[0].public_url')
NGROK_HOST=$(echo "$NGROK_ENDPOINT" | cut -d':' -f2 | cut -d'/' -f3)
@jasalt
jasalt / auto_audiocraft_plus.py
Last active December 3, 2023 22:41
Selenium audiocraft_plus batch process
# pip install selene
from selene import browser, by, be
from time import sleep
browser.config.base_url = 'http://127.0.0.1:7860'
browser.config.driver_name = 'firefox'
browser.open('/')
@jasalt
jasalt / thinkfan.conf
Last active November 26, 2023 15:30
Fan profile (/etc/thinkfan.conf) for keeping Skylake Thinkpads silent at work
# This fan config helps to keep Thinkpad silent at work
# With it eg. 200$ second-hand 2-core Skylake laptop T460 and onwards can encode 1440p 30fps h264/h265 with
# Intel QuickSync HW encoder via proprietary VA-API driver https://wiki.debian.org/HardwareVideoAcceleration,
# silently, and stream it via OBS (RTMP/SRT/NDI..) etc..
# To use this fan config on a single-fanned Thinkpad with Debian and systemd, run:
# sudo apt install thinkfan
# sudo echo "options thinkpad_acpi fan_control=1" > /etc/modprobe.d/thinkpad_acpi.conf
@jasalt
jasalt / clock.html
Created November 2, 2023 19:49
OBS Clock HTML Snippet (cheap timecode)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>A simple clock</title>
</head>
<body translate="no" >
# Convert srt file (from eg. pywhispercpp) into csv format with sub start location also in seconds to create Youtube time link.
# Could be useful for annotating livestream recordings from transcription in a spreadsheet.
# Deps (Python 3.11):
# pip install srt
import csv
import srt
def srt_to_csv(srt_file, youtube_link):
@jasalt
jasalt / gist:91ee171ba9b41aad0dbf2c6cd1eaf10f
Last active January 29, 2023 07:32
HTML / JS to embed Github starred repos on web site [WordPress Compatible]
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<div class="gh-starred-repos"></div>
<script>
var urlToGetLatestStarredRepos = "https://api.github.com/users/jasalt/starred?per_page=10";
jQuery(document).ready(function () {
jQuery.getJSON(urlToGetLatestStarredRepos, function (allRepos) {
jQuery.each(allRepos, function (i, repo) {
var repoUrl = jQuery('<a style="color:red;"></a>').text(repo.full_name).attr('href', repo.html_url).appendTo(".gh-starred-repos");
jQuery(".gh-starred-repos").append("<label> [" + repo.description + "]</label>" + " <i><strong>" + repo.language + "</strong> ⭐ " + repo.stargazers_count + " </i> ");
@jasalt
jasalt / deshortcut_path.py
Created May 31, 2022 17:02
Replace file shortcuts in given path with files they point to (on MacOS).
#!/usr/bin/env python
import glob
import os
import sys
def print_help():
print(''' Replaces file shortcuts in given path with files they represent (on MacOS).
Directory shortcuts are skipped. Requires Python 3.10.
@jasalt
jasalt / wp-ajax-add-tag.js
Created May 17, 2022 14:40
Leftover plugin code doing ajax call securely with nonce and sanitisation. Discarded cause mixed up with existing states in post editor Tags -box.
// html page has a list of possible suggested tags rendered (see php file) which have a button from which they can be added as post tag eg:
// <p class="demo_tag">New demo tag<button class="button demo_add_keyword_as_tag_btn " data-nonce="XXX" data-demo_keyword="New demo tag" data-post_id="XXX">+</button></p>
// Click handler for buttons and ajax call
jQuery('.demo_add_keyword_as_tag_btn').click(function(e) {
e.preventDefault();
if (e.target.classList.contains("button-disabled")){
return;
};
@jasalt
jasalt / hacklabjkl_kävijäseuranta.html
Last active August 4, 2022 08:46
jkl.hacklab.fi Wordpress kävijäseuranta Block rev220804
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML 5 Boilerplate</title>
<!-- <link rel="stylesheet" href="style.css"> -->
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
</head>
@jasalt
jasalt / woo_rest_cat_urls.php
Created May 25, 2021 12:22
Add product category urls to WooCommerce REST API v3
/* Adds category term links to /products/categories endpoint giving full urls / permalinks to the category archive pages. */
add_filter('woocommerce_rest_prepare_product_cat', 'rest_add_cat_url', 10, 3);
function rest_add_cat_url($response, $object, $request) {
if (empty($response->data)){ return $response; }
$response->data['term_link'] = get_term_link($object->term_id);
return $response;
}