Skip to content

Instantly share code, notes, and snippets.

@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;
@fproperzi
fproperzi / concatenate_video_in_dir.bat
Created December 2, 2023 20:42
ffmpeg merge and transcode
@ECHO OFF
setlocal enableextensions
::---------------------------------------------------------------
:: DEFINE SETTING
::---------------------------------------------------------------
SET h264_quality=26
SET ext=*.MOV *.MTS *.AVI *.MP4 *.MPG
SET vlc_path=C:\Program Files\VideoLAN\VLC\vlc.exe
@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(''),
@fproperzi
fproperzi / brightnessByColor
Created June 30, 2023 13:22
having background-color witch front color?
function frontColor (bgcolor) {
var m = bgcolor.substr(1).match(/(\S{2})/g);
if (m) {
var r = parseInt(m[0], 16), g = parseInt(m[1], 16), b = parseInt(m[2], 16);
return (((r*299)+(g*587)+(b*114))/1000) > 125 ? 'black' : 'white';
}
return 'black';
}
@fproperzi
fproperzi / language_it.php
Last active June 15, 2023 06:48
one translations file to include in js or php
<?php
$jlang = <<<EOT
{
"cancel":"Cancella",
"close": "Chiudi",
"copy": "Copia",
"delete": "Elimina",
"delete-confirm": "Confermi la cancellazione?",
"deleted": "Cancellato",
"disabled": "Disabilitati",
// https://medium.com/recraftrelic/es5-vs-es6-with-example-code-9901fa0136fc
//--- ES5 callBack
function isGreater (a, b, callBack) {
var greater = false
if(a > b) {
greater = true
}
callBack(greater)
}
@fproperzi
fproperzi / afGroupBy2TreeMapArray
Last active April 27, 2023 07:49
From sql group-by flat array to google chart treeMap data
// main function
function afGroupBy2TreeMapArray(data, global='ciccio') {
let id = 1,
arr = data //create tree from flat array
.reduce((a, r) => {
let keys = Object.keys(r);
keys.reduce(function (q, k, i) {
const f = r[k];
if (!q[f]) q._.push([{f:f, v:String(id++), k:k, level:i, childs:(q[f] = { _: [] })._} ]);
return q[f];
//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 / mouse_jiggler.ps1
Last active March 31, 2023 14:27
stand-by bye bye
Add-Type -assemblyName System.Windows.Forms;$a=@(1..100);while(1){[System.Windows.Forms.Cursor]::Position=New-Object System.Drawing.Point(($a|get-random),($a|get-random));start-sleep -seconds 5}
@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