Skip to content

Instantly share code, notes, and snippets.

@fproperzi
fproperzi / luxon_setLocale_test.js
Last active May 28, 2019 09:29
luxon setLocale slow execution!!!
var l,m,i,d;
for(m=(new Date).valueOf(),i=0;i<1000;i++) d=luxon.DateTime.local().plus({days:i}).toFormat('ddcccccMM');
m = (new Date).valueOf()-m;
for(l=(new Date).valueOf(),i=0;i<1000;i++) d=luxon.DateTime.local().plus({days:i}).setLocale('it').toFormat('ddcccccMM');
l = (new Date).valueOf()-l;
console.log(m,l,'-->',Math.round(1000*(l-m)/m)/10,'%++');
// expect time like:
// no setLocale: 10
// setLocale('it'):246
@fproperzi
fproperzi / sscc.sql
Created September 8, 2021 08:25
create sscc from store procedure + sequence by year
-- wont my sscc from sequence
-- prefix(8) + year(2) + serial(7) + check digit(1)
-- 08008443 21 0001234 D
USE [intranet]
GO
-- create sscc with part serial restart by year
drop sequence if exists s_sscc
go
CREATE SEQUENCE [dbo].[s_sscc]
for (var i = 1; i < 5; i++){
setTimeout(() => { console.log(i); }, 1000);
}
// 5 5 5 5
for (let i = 1; i < 5; i++){
setTimeout(() => { console.log(i); }, 1000);
}
// 1 2 3 4
//https://pablotron.org/2022/03/09/fastest-js-html-escape/
const _esc = (v) => v
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll("'", '&apos;')
.replaceAll('"', '&quot;');
var a = {a:'vispa',b:'teresa', list:[{v:'1',t:'uno'},{v:'2',t:'due'},{v:'3',t:'t<r>e'}]}
const fn = (j) => `
@fproperzi
fproperzi / concatenate_video_in_dir.bat
Last active January 23, 2023 11:45
to concatenate video in subdirectories. happens when record a long match of your son with your camera: many files to concatenate. Install VLC to process videos!
@ECHO OFF
setlocal enableextensions
::---------------------------------------------------------------
:: DEFINE SETTING
::---------------------------------------------------------------
SET ext=*.MOV *.MTS *.AVI *.MP4 *.MPG *.M4V
SET vlc_path=C:\Program Files\VideoLAN\VLC\vlc.exe
@fproperzi
fproperzi / config.wsf.js
Last active April 26, 2024 08:48
wsf file and config to use in wsf files
// https://stackoverflow.com/questions/34882591/upgrading-iis-classic-asp-javascript-jscript-scripting-engines-to-chakra
var _htmlfile = WScript.CreateObject('htmlfile');
_htmlfile.write('<meta http-equiv="x-ua-compatible" content="IE=11" />');
// expose more modern methods from htmlfile
var JSON = _htmlfile.parentWindow.JSON;
String.prototype.trim = _htmlfile.parentWindow.String.prototype.trim;
String.prototype.padStart = _htmlfile.parentWindow.String.prototype.padStart;
Array.prototype.indexOf = _htmlfile.parentWindow.Array.prototype.indexOf;
Array.prototype.forEach = _htmlfile.parentWindow.Array.prototype.forEach;
Array.prototype.map = _htmlfile.parentWindow.Array.prototype.map;
<!DOCTYPE html>
<html lang="en">
<!--- https://mkxml.github.io/zpl-webusb/ -->
<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>Zebra USB Test</title>
</head>
@fproperzi
fproperzi / printers_web.ps1
Created March 7, 2023 07:48
Check printers from port 80-web
# script per identificare le stampanti in rete
# versione 1.0
#
# per lanciarlo da prompt powershell:
#
# PS: C:\users\your-name\documents> .\printers.ps1
#
# risultato in file .CSV
#
# C:\users\your-name\documents\debby_printers.csv
@fproperzi
fproperzi / printers_snmp.ps1
Created March 7, 2023 07:52
Check printers with snmp call to specific OID
# other powershell snmp information
# https://solvedbypowershell.blogspot.com/2014/12/powershell-using-snmp-for-html-network.html
# https://www.powershellgallery.com/packages/Proxx.SNMP/1.0.1.2/Content/Invoke-SnmpGet.ps1
# https://www.powershellgallery.com/packages/Proxx.SNMP/1.0.0.1/Content/Invoke-SnmpWalk.ps1
# https://exchange.nagios.org/directory/Plugins/Hardware/Printers/SNMP-Printer-Check/details
# https://www.powershellgallery.com/packages/Proxx.SNMP/1.1.1.4
# https://www.reddit.com/r/PowerShell/comments/77ls36/printer_page_counter_from_print_server/
# https://gallery.technet.microsoft.com/Get-PrintStatistics-a6bb8323
# https://gallery.technet.microsoft.com/scriptcenter/Script-to-generate-print-84bdcf69
@fproperzi
fproperzi / tools.js
Last active July 18, 2023 09:27
javascript tools
const getParameters = URL => JSON.parse(`{"${decodeURI(URL.split("?")[1]).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"')}"}`);
// getParameters("https://www.google.com.hk/search?q=js+md&newwindow=1");
// {q: 'js+md', newwindow: '1'}
const uniqueArr = (arr) => [...new Set(arr)]; // unique array
const hashCode = (str) => [...str].reduce((s, c) => Math.imul(31, s) + c.charCodeAt(0) | 0, 0) >>> 0; // only positive numbers
const hashBCode = (str) => btoa([...str].reduce((s, c) => Math.imul(31, s) + c.charCodeAt(0) | 0, 0));
const base62 = {
charset: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
.split(''),