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 / Laravel-MakeConfig.php
Last active August 18, 2023 06:41
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 / 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,
#!/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 / 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
@jotaelesalinas
jotaelesalinas / runcommand.py
Created May 12, 2016 23:20
Runs an external command in Python and returns exit code, stdout and stderr contents.
# runcommand.py
# Handy function that executes an external command in the shell
# and returns 3 values: exit code of the command, its standard output
# and its error output.
# If you run the script directly, an example is provided:
# first it will run a successful command and then one with errors
# (you may want to modify them if not running a Unix system).
import subprocess
@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 / git-squash.bat
Last active April 7, 2021 17:05
Easy git-squash (merges last N commits in one)
@echo off
if "%1"=="" goto blank
echo Squashing %1 commits...
git reset --soft HEAD~%1
git log --format=%%B%%n --reverse "HEAD@{1}" -n %1 > _msg.txt
git commit -t _msg.txt
del _msg.txt
echo Done!
@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
*/