Skip to content

Instantly share code, notes, and snippets.

View nuxodin's full-sized avatar

Tobias Buschor nuxodin

View GitHub Profile
@nuxodin
nuxodin / tryAgain.js
Created February 14, 2023 23:17
tryAgain function
View tryAgain.js
function tryAgain(fn, times = 2){
try {
return fn(times);
} catch (e) {
if (times > 1) return tryAgain(fn, times-1);
throw e;
}
}
@samthor
samthor / eventlistener-signal-support.js
Last active February 22, 2023 12:19
Polyfill/code for the signal argument to addEventListener
View eventlistener-signal-support.js
// This is part of the blog post here: https://whistlr.info/2022/abortcontroller-is-your-friend/
// ...and can be used to detect/polyfill the `signal` argument to addEventListener.
//
// Note that at writing, 86%+ of active browsers already support it:
// https://caniuse.com/mdn-api_eventtarget_addeventlistener_options_parameter_options_signal_parameter
// ...but that 92% of browsers support `AbortController` and signal.
//
// So there's 6% of total browsers which will fail silently when adding the `signal` argument.
// Eyeballing it, this is mostly Safari 11-15 and Chrome 66-90. These snippets can help with those targets.
//
View weak-value.js
class WeakValue extends Map {
#registry = new FinalizationRegistry(key => {
if (this.has(key) && !this.get(key).deref())
this.delete(key);
});
get(key) {
const value = super.get(key);
return value && value.deref();
}
set(key, value) {
@nuxodin
nuxodin / easy-console.js
Created December 8, 2016 15:13
Like to write to the console like this "console = xyz" instead of "console.log(xyz)" ?
View easy-console.js
!(function(){
var original = console;
Object.defineProperty(window, 'console', {
get:function(){
return original;
},
set:function(value){
original.log(value)
}
})
@stayallive
stayallive / install.sh
Last active May 4, 2018 19:59
Install PHP 5.6.7 on Plesk 11.5 & 12 (CentOS 6)
View install.sh
#!/bin/bash
# Make sure you are up to date
yum -y update && yum -y install wget
# Install EPEL repository
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# Get us a clean working directory
mkdir /php
@ziadoz
ziadoz / awesome-php.md
Last active January 24, 2024 15:45
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.
View awesome-php.md
@tobitailor
tobitailor / get_barcode_from_image.js
Created June 1, 2010 19:33
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
View get_barcode_from_image.js
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',