Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
jhthorsen / bookmarklets.js
Created March 10, 2020 00:16
javascript:...
(function(d){let e=n=>d.createElement(n);let i=(p,c,r)=>p.insertBefore(c,r||null);let b=d.body;let v=i(b,e('div'),b.firstChild);v.id='gte';v.style.display='none';let o=e('script');o.src='//translate.google.com/translate_a/element.js?cb=gti';o.type='text/javascript';i(b,o);let p=e('script');p.text='function gti(){new google.translate.TranslateElement({pageLanguage:""},"gte")}';i(b,p)})(document);
@jhthorsen
jhthorsen / grm.js
Last active June 10, 2020 23:38
Google Photos delete script - Use at own risk!
async function gPhotosPurge(nSelectedLast = -1) {
gPhotosPurgeSelectPhotos();
const nSelected = await gPhotosPurgeWaitFor(gPhotosPurgeGetNumberOfSelected, 'nSelected>0', 2000);
return nSelected > 200 || nSelected == nSelectedLast ? gPhotosPurgeExecute(nSelected) : nSelected ? gPhotosPurge(nSelected) : console.info('[gPhotosPurge] nSelected=0');
}
async function gPhotosPurgeExecute(nSelected) {
console.info('[gPhotosPurge] Deleting ' + nSelected + ' photos...');
deleteBtn = await gPhotosPurgeWaitFor(() => document.querySelector('button[title="Delete"]'), 'deleteBtn');
deleteBtn.focus();
@jhthorsen
jhthorsen / ESP_IR_TR
Last active November 17, 2024 22:38
Tasmota Rule1 IrReceived to Homebridge Button Platform
https://www.amazon.co.jp/gp/product/B08LD13HVC/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1
Friendly name: ESP_3C69E4_IR
Template: {"NAME":"ESP8285 Infrared Transceiver","GPIO":[0,0,0,0,1056,0,0,0,0,0,1088,0,0,0],"FLAG":0,"BASE":20}
backlog ipaddress1 192.168.50.52; ipaddress2 192.168.50.1; ipaddress3 255.255.255.0; ipaddress4 1.1.1.1
# LG volume up/down
{"IrReceived":{"Protocol":"NEC","Bits":32,"Data":"0x20DF40BF","DataLSB":"0x4FB02FD","Repeat":0}}
{"IrReceived":{"Protocol":"NEC","Bits":32,"Data":"0x20DFC03F","DataLSB":"0x4FB03FC","Repeat":0}}
@jhthorsen
jhthorsen / travese-packages.pl
Created December 22, 2021 08:40
Used to get package information recursive
sub traverse_packages {
my ($name, $depth) = @_;
my $pkg = do { no strict qw(refs); \%{"$name\::"}; };
for my $key (sort keys %$pkg) {
printf "%s%s::%s\n", ' ' x ($depth * 2), $name, $key;
traverse_packages("$name\::$1", $depth + 1) if $key =~ m!^(\w+)::$!;
}
}
@jhthorsen
jhthorsen / mojo.pl
Last active April 1, 2022 00:49
Test for changing max_message_size dynamically
use Mojo::Base -strict;
use Test2::V0;
use Test::Mojo;
# Note that this does not work for small HTTP messages, since they might get
# parsed way before the "progress" event gets fired, and the "max_message_size"
# check is done.
use Mojolicious::Lite -signatures;
hook after_build_tx => sub ($tx, $app) {
@jhthorsen
jhthorsen / cloudflareddns.service
Created January 13, 2023 01:01
DDNS system for Cloudflare: Update the DNS record if the webserver does not respond correctly
[Unit]
Description=Cloudflare DDNS
After=network.target
[Service]
#Environment=CLOUDFLARE_API_KEY=
Environment=ZONE_ID=1234
Environment=RECORD_ID=5678
Environment=RECORD_NAME=domain.example.com