Skip to content

Instantly share code, notes, and snippets.

View jotaelesalinas's full-sized avatar

José Luis Salinas jotaelesalinas

  • The Hague, Netherlands
View GitHub Profile
@jotaelesalinas
jotaelesalinas / iban.js
Created March 13, 2023 14:57
IBAN validation Javascript class
class IBAN {
static code_lengths = {
AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29, CH: 21,
CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24, FI: 18, FO: 18,
FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21, HU: 28, IE: 22, IL: 23,
IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28, LI: 21, LT: 20, LU: 20, LV: 21,
MC: 27, MD: 24, ME: 22, MK: 19, MR: 27, MT: 31, MU: 30, NL: 18, NO: 15, PK: 24,
PL: 28, PS: 29, PT: 25, QA: 29, RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24,
SM: 27, TN: 24, TR: 26, AL: 28, BY: 28, CR: 22, EG: 29, GE: 22, IQ: 23, LC: 32,
SC: 31, ST: 25, SV: 28, TL: 23, UA: 29, VA: 22, VG: 24, XK: 20,
@jotaelesalinas
jotaelesalinas / accessing_static_member.js
Created November 20, 2021 00:02
Display different ways of accessing static members from normal methods and other static methods in Javascript classes
"use strict";
// methods ending in 1 are inherited from Base
// methods ending in 2 are overriden in Child
class Base {
static num = 123;
static str = "asdf";
fnInstanceThis1() {
const REGEX_NON_ASCII_CHARS = /[\u00A0-\u9999]/g;
const REGEX_SPECIAL_CHARS = /[<>"'`&?=\\/()\[\]\{\}\#]/g;
let replaceCharWithHtmlEntity = char => `&#${char.charCodeAt(0)};`;
let htmlEncode = str => str.replace(REGEX_NON_ASCII_CHARS, replaceCharWithHtmlEntity)
.replace(REGEX_SPECIAL_CHARS, replaceCharWithHtmlEntity);
let urlEncode = str => encodeURIComponent(str);
@jotaelesalinas
jotaelesalinas / ec2-start-and-ssh.sh
Last active December 9, 2022 23:17
Starts an EC2 instance and runs a command or opens a shell
#!/bin/bash
set -u
##############################################################################
# DEPRECATION NOTE
#
# This script is outdated. Use it at your own risk.
# There is a new github repo with a new version, with no known bugs
# and with improved features:
# https://github.com/jotaelesalinas/ec2remote
#!/bin/bash
set -u
##############################################################################
# DEPRECATION NOTE
#
# This script is outdated. Use it at your own risk.
# First, it has a bug related to the option -o (basically, it does nothing).
# Second, there is a new github repo with a new version, with no known bugs
# and with improved features:
@jotaelesalinas
jotaelesalinas / Laravel-MakeConfig.php
Last active July 17, 2024 12:07
Laravel make:config artisan command
<?php
/*
* Run this artisan command before:
* php artisan make:command MakeConfig
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
@jotaelesalinas
jotaelesalinas / geoloc.html
Created November 14, 2019 10:38
IP Geoloc
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geoloc</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
@jotaelesalinas
jotaelesalinas / dragndrop.js
Created November 14, 2018 08:31
Javascript script for easy drag and drop on an HTML element
/*
* Configures an element to receive files via drag'n'drop.
* - el: drop element, either id string or HTMLElement object.
* - cb_ok: callback, accepts: contents or data returned by preprocessor, file and index; called once per successfully preprocessed file.
* - cb_fail: callback, accepts error, file and index; called once per failed file.
* - preprocessor: function that accepts the contents of the file and can return any data; accepts: contents, file, index; called once per dropped file.
* - cb_start: callback, called before preprocessing all files, accepts the files, can throw, e.g. if wrong filetypes
* - cb_finished: callback, called after handling all files, no matter is failed or not
* - css: CSS styles to be applied to the drop element
*/
@jotaelesalinas
jotaelesalinas / selectr.js
Created April 6, 2018 12:24
JS snippet to pick elements and extract text and links
(function () {
var self = this;
self.version = '1.2';
self.els = {};
self.utils = {};
self.utils.addEvent = function (el, evname, f, capture) {
@jotaelesalinas
jotaelesalinas / highlight.css
Last active March 22, 2018 16:08
highlight.css
.highlight {
background-image: linear-gradient(-100deg,hsla(90,92%,75%,.3),hsla(90,92%,75%,.7) 98%,hsla(90,92%,75%,.1));
border-radius: .25em 0;
padding: 0 .25em;
margin: 0 -.25em;
}
.underline {
background-image: linear-gradient(120deg, darkorange 0%, orange 100%);
background-repeat: no-repeat;
background-size: 100% 0.2em;