Skip to content

Instantly share code, notes, and snippets.

@rg443a
rg443a / inet_aton.sql
Created June 7, 2024 20:30
duckdb inet_aton function
CREATE OR REPLACE FUNCTION inet_aton(ip) AS (
cast(
split_part(ip, '.', 1)::UINTEGER * 16777216 +
split_part(ip, '.', 2)::UTINYINT * 65536 +
split_part(ip, '.', 3)::UTINYINT * 256 +
split_part(ip, '.', 4)::UTINYINT as UINTEGER)
);
-- select inet_aton('255.255.255.252');
@rg443a
rg443a / wp_tags.js
Last active January 6, 2023 22:46
wp server sites and tags
wp_continents = {"northamerica":{"Albany":{"id":"latham","name":"albany","title":"Albany","location":"Latham","state":"New York","country":"United States","latitude":"42.7469","longitude":"-73.7589","continent_name":"North America"},"Albuquerque":{"id":"albuquerque","name":"albuquerque","title":"Albuquerque","location":"Albuquerque","state":"New Mexico","country":"United States","latitude":"35.1107","longitude":"-106.6100","continent_name":"North America"},"Asheville":{"id":"asheville","name":"asheville","title":"Asheville","location":"Asheville","state":"North Carolina","country":"United States","latitude":"35.6008","longitude":"-82.5542","continent_name":"North America"},"Atlanta":{"id":"atlanta","name":"atlanta","title":"Atlanta","location":"Atlanta","state":"Georgia","country":"United States","latitude":"33.7489","longitude":"-84.3881","continent_name":"North America"},"Austin":{"id":"austin","name":"austin","title":"Austin","location":"Austin","state":"Texas","country":"United States","latitude":"30.2500
@rg443a
rg443a / sparklines1.js
Created June 26, 2022 13:04
svg sparklines in javascript
function getY(max, height, diff, value) {
return parseFloat((height - (value * height / max) + diff).toFixed(2));
}
function removeChildren(svg) {
[...svg.querySelectorAll("*")].forEach(element => svg.removeChild(element));
}
function defaultFetch(entry) {
return entry.value;
@rg443a
rg443a / Streamer.php
Created May 26, 2021 10:58 — forked from gpbmike/Streamer.php
php backend for streaming file upload with XMLHttpRequest
<?php
class File_Streamer
{
private $_fileName;
private $_contentLength;
private $_destination;
public function __construct()
{
if (!isset($_SERVER['HTTP_X_FILE_NAME'])
# https://help.duckduckgo.com/duckduckgo-help-pages/results/duckduckbot/
20.191.45.212
23.21.227.69
40.88.21.235
50.16.241.113
50.16.241.114
50.16.241.117
50.16.247.234
52.5.190.19
@rg443a
rg443a / dbip-mmdb-update.sh
Created May 2, 2021 20:23
dbip mmdb update
#!/usr/bin/env bash
cd /usr/share/GeoIP;
curl -LRO https://download.db-ip.com/free/dbip-country-lite-$(date +%Y-%m).mmdb.gz;
curl -LRO https://download.db-ip.com/free/dbip-city-lite-$(date +%Y-%m).mmdb.gz;
curl -LRO https://download.db-ip.com/free/dbip-asn-lite-$(date +%Y-%m).mmdb.gz;
gunzip dbip-$(date +%Y-%m).mmdb.gz;
ln -sf dbip-country-lite-$(date +%Y-%m).mmdb dbip-country-lite.mmdb;
ln -sf dbip-city-lite-$(date +%Y-%m).mmdb dbip-city-lite.mmdb;
ln -sf dbip-asn-lite-$(date +%Y-%m).mmdb dbip-asn-lite.mmdb;
geoipupdate -v;
@rg443a
rg443a / bash_history_rem_dupl.sh
Created April 23, 2021 11:24
bash history remove duplicates
tac $HISTFILE | awk '!x[$0]++' | tac | sponge $HISTFILE
awk '!x[$0]++' ~/.bash_history
tac ~/.bash_history | awk '!x[$0]++' | tac
# https://medium.com/@dblume/have-only-unique-lines-in-your-bash-history-941e3de68c03
@rg443a
rg443a / st1-byday.js
Created March 21, 2021 18:26
st list by day
var s=document.body.innerText.split("\n");
console.log(s.length);
var nn=s.map(v=>{try {var x=JSON.parse(v)}catch(err){console.log(v);}return x||[];}).flat();
document.body.innerHTML="<pre>" +
nn.sort(sdl).map(n=>{try{var h=new URL(n.url||n.hostname).hostname}catch(err){h=n.url}; return [n.id,(''+n.rtt).padStart(3),(0.001+n.dl).toFixed(0).padStart(4,' '),(0.001+n.elapsed).toFixed(1).padStart(4,' '),(n.country||n.cc).padEnd(20," "),n.name.padEnd(20," "),n.ip,h||n.url||n.hostname].join("\t");}).join("\n")
+"</pre>";
console.log(nn.length);
function srtt(a,b){return a.rtt-b.rtt}
function sdl(a,b){return b.dl-a.dl}
@rg443a
rg443a / ip2location-cc.js
Last active January 9, 2021 11:14
ip2location visitor-blocker download [TSV]
(async function() {
var cl = Array.from(document.getElementsByName("countryCodes[]")[0].options).map(v => v.value);
var a=[];
console.log(cl);
for (var cn of cl) {
r = await fetch("https://www.ip2location.com/free/visitor-blocker", {
"headers": {
"content-type": "application/x-www-form-urlencoded",
},
"referrer": "https://www.ip2location.com/free/visitor-blocker",
@rg443a
rg443a / inet_aton_ntoa.js
Last active January 2, 2020 06:37
inet_aton, inet_ntoa, ip2int, int2ip
function inet_aton(a) {
return a.split(".").reduce(function(a, b) {
return (a << 8) + parseInt(b, 10);
}, 0) >>> 0;
}
function inet_ntoa(a) {
return (a >>> 24) + "." + (a >> 16 & 255) + "." + (a >> 8 & 255) + "." + (a & 255);
}