Skip to content

Instantly share code, notes, and snippets.

View oskarnrk's full-sized avatar
💭
"Mi avvalgo della facoltà di non comprendere" (cit.)

Oscar Zambotti oskarnrk

💭
"Mi avvalgo della facoltà di non comprendere" (cit.)
View GitHub Profile
@oskarnrk
oskarnrk / productkey.vbs
Created June 27, 2021 09:20
Script that extracts Windows product key from Windows Registry
' Found on
' https://answers.microsoft.com/en-us/windows/forum/all/how-to-recover-your-windows-product-key/8687ef5d-4d32-41fc-9310-158f8e5f02e3
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
@oskarnrk
oskarnrk / isvalidfiscalcode.js
Last active April 29, 2021 06:43 — forked from massic80/isvalidfiscalcode.js
Check Italian Fiscal Code
const validFiscalCodeRegexp = /^([A-Za-z]{6}[\dlmnpqrstuvLMNPQRSTUV]{2}[abcdehlmprstABCDEHLMPRST]{1}[\dlmnpqrstuvLMNPQRSTUV]{2}[A-Za-z]{1}[\dlmnpqrstuvLMNPQRSTUV]{3}[A-Za-z]{1})$|(\d{11})$/;
const isValidFiscalCode = cf => validFiscalCodeRegexp.test(cf);
@oskarnrk
oskarnrk / AndroidAdbGrantPermissionToApp.bat
Created November 25, 2018 14:50
Grant permission to Android app using adb cli tools
// adb -d shell pm grant <app.package> <android.permission>
adb -d shell pm grant com.gsamlabs.bbm android.permission.BATTERY_STATS
@oskarnrk
oskarnrk / GetWhereColumnIsUsedAsForeignKey.sql
Last active November 12, 2018 13:40
Get all tables and columns where a column is used as foreign key
-- Thanks to Dustin Ryan
-- https://sqldusty.com/2015/07/08/tsql-script-to-find-foreign-key-references-to-a-given-column/
SELECT OBJECT_NAME(f.object_id) as ForeignKeyConstraintName,
OBJECT_NAME(f.parent_object_id) TableName,
COL_NAME(fk.parent_object_id,fk.parent_column_id) ColumnName,
OBJECT_NAME(fk.referenced_object_id) as ReferencedTableName,
COL_NAME(fk.referenced_object_id,fk.referenced_column_id) as ReferencedColumnName
FROM sys.foreign_keys AS f
@oskarnrk
oskarnrk / StringIsUndefinedOrNullOrEmpty.js
Last active October 15, 2018 10:28
Demonstration abount checking if a string is undefined, null or empty
/*
* https://codereview.stackexchange.com/questions/5572/string-isnullorempty-in-javascript
* Thanks to ndp (https://codereview.stackexchange.com/users/8041/ndp)
*/
// Starting with:
return (!value || value == undefined || value == "" || value.length == 0);
// Looking at the last condition, if value == "", it's length MUST be 0. Therefore drop it:
return (!value || value == undefined || value == "");
// But wait! In JS, an empty string is false. Therefore, drop value == "":
return (!value || value == undefined);
@oskarnrk
oskarnrk / SearchTablesAndViewsByColumnName.sql
Created October 11, 2018 09:38
Search which tables or views have a column by name
SELECT COLUMN_NAME AS 'ColumnName'
,TABLE_NAME AS 'TableName'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%MyName%'
ORDER BY TableName
,ColumnName;
@oskarnrk
oskarnrk / SearchTablesByColumnName.sql
Last active October 11, 2018 09:38
Search which tables have a column by name
SELECT c.name AS 'ColumnName'
,t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%MyName%'
ORDER BY TableName
,ColumnName;
@oskarnrk
oskarnrk / isvalidemail.js
Last active April 29, 2021 06:57
Check if is a valid URL
const validEmailRegexp = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
const isValidEmail = email => validEmailRegexp.test(email);
@oskarnrk
oskarnrk / rounddecimalplaces.js
Last active April 29, 2021 06:56
Round a number by decimal places (default: 1)
const roundDecimalPlaces = (num, decimalPlaces) => {
// default: 1 decimal places
decimalPlaces = !decimalPlaces ? 1 : decimalPlaces;
return Math.round(num * 10 * decimalPlaces) / (10 * decimalPlaces);
}
@oskarnrk
oskarnrk / photos_filename_to_exifdatetime.sh
Created March 11, 2016 10:27
Change EXIF data using date and time written in photo's filename
#!/bin/sh
exiftool '-datetimeoriginal<filename' IMG_%Y%m%d_%H%M.jpg *