Skip to content

Instantly share code, notes, and snippets.

View A1rPun's full-sized avatar
🌊
Fractalicious

A1rPun A1rPun

🌊
Fractalicious
  • The Netherlands
View GitHub Profile
@A1rPun
A1rPun / KeepAzureVpnAlive.ps1
Created November 11, 2021 12:15
Azure VPN PowerShell
$connectedSleep = 59
$disconnectedSleep = 5
$currentSleep = $connectedSleep
$vpnName = "Azure VPN"
while($true) {
$value = Get-NetIPInterface | findstr -i $vpnName
if ($value -eq $null) {
$currentSleep = $disconnectedSleep
@A1rPun
A1rPun / decorators.js
Last active May 13, 2021 08:04
Generic helper stuff for experiments
function memoizer(fn) {
const cache = new Map([]);
return (...args) => {
let result;
const key = args.toString();
if (cache.has(key))
result = cache.get(key);
else {
result = fn(...args);
cache.set(key, result);
const GTIN_SSCC_LENGTH = 16;
const WEIGHT_EVEN = 3;
const WEIGHT_ODD = 1;
function ceil(n, base) {
// TODO: 0.1, 0.01, 0.001, etc.
return Math.ceil(n / base) * base;
}
function validateEan(str = '') {
@A1rPun
A1rPun / 1-form.js
Created August 13, 2019 09:40
Angular to Vue
function checkValidity(el) {
if (el.checkValidity()) {
el.$valid = true;
el.$invalid = false;
} else {
el.$valid = false;
el.$invalid = true;
}
}
@A1rPun
A1rPun / 0-README.md
Last active May 17, 2019 12:27
A function to convert a number to a roman numeral

Roman numerals

1..toRoman() // "I"
18..toRoman() // "XVIII"
1910..toRoman() // "MCMX"
9999..toRoman() // "MMMMMMMMMCMXCIX"

Inspiration

@A1rPun
A1rPun / f.js
Last active April 15, 2019 14:55 — forked from renanpvaz/f.js
JavaScript function pattern matching inspired by F#'s & renanpvaz gist
fun = (variations, matchIndex = 0) => (...appliedArgs) => (variations[appliedArgs[matchIndex]] || variations._)(...appliedArgs)
luck = fun({
7: () => "LUCKY NUMBER SEVEN",
_: () => "Sorry, you're out of luck, pal!",
})
luck(7)
// "LUCKY NUMBER SEVEN"
@A1rPun
A1rPun / blink.css
Created July 26, 2018 14:24
Cross-browser Blink
@A1rPun
A1rPun / ThueMorse.js
Last active August 17, 2017 11:06
Thue–Morse sequence
function thueMorse(i) {
var a = '0', b = '1';
for (; i--;)
a += [b, b += a][0];
return a;
}
thueMorse(0); // 0
thueMorse(1); // 01
thueMorse(4); // 0110100110010110
@A1rPun
A1rPun / deburglar.js
Last active August 17, 2017 09:50
Get duplicate requests in JavaScript
// deburglar.getDupes();
var deburglar = (function () {
var dict = {};
var maybeTheOriginalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url) {
if (!dict[url])
dict[url] = 0;
dict[url]++;
return maybeTheOriginalOpen.apply(this, arguments);
};
@A1rPun
A1rPun / int32toIP.js
Last active August 29, 2017 15:55
int32 to IP in JavaScript
function int32toIP(nMask) {
for (var nFlag = 0, nShifted = nMask, sMask = ''; nFlag < 32;
nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);
return sMask.match(/.{1,8}/g).map(function (x) { return parseInt(x, 2); }).join('.');
}
int32toIP(255); // "0.0.0.255"
int32toIP(256); // "0.0.1.0"
int32toIP(1333333337); // "79.121.13.89"
int32toIP(7527203073); // "192.168.1.1"