Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / ESP_IR_TR
Last active September 15, 2022 21: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 / 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 / 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 / wedsites.css
Last active September 22, 2019 11:48
Custom css for https://wedsites.com/
h2,
h3 {
text-transform: uppercase;
}
.site {
letter-spacing: 0.1em;
line-height: 1.6rem;
text-transform: none;
max-width: 100% !important;
@jhthorsen
jhthorsen / wikipedia.css
Last active September 10, 2019 14:52
Stylus styling for wikipedia.org
#content {
border: 0;
padding: 40px 50px 30px 350px;
margin: 0;
}
#mw-page-base {
display: none;
}
@jhthorsen
jhthorsen / git-report.pl
Last active September 27, 2018 08:16
Check when you worked in the git repos
#!/usr/bin/env perl
use strict;
use warnings;
my $dir = ($ARGV[0] and -d $ARGV[0]) ? shift @ARGV : '.';
my @ymd = (shift @ARGV);
my @today = (localtime)[5, 4]; # (year, mon)
$today[0] += 1900 if $today[0] <= 1900;
$today[1]++;
@jhthorsen
jhthorsen / keep_alive.pl
Created September 26, 2018 09:28
Show how you need prevent the object from going out of scope
#!perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
my $ua = Mojo::UserAgent->new;
# Try keeping this object alive with http://localhost:3000?keep_alive=1
$c->stash(ua => $ua) if $c->param('keep_alive');