Skip to content

Instantly share code, notes, and snippets.


José Luis Salinas jotaelesalinas

  • The Hague, Netherlands
View GitHub Profile
jotaelesalinas / accessing_static_member.js
Created Nov 20, 2021
Display different ways of accessing static members from normal methods and other static methods in Javascript classes
View accessing_static_member.js
"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() {
View str-utils.js
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 /
Last active Aug 20, 2021
Starts an EC2 instance and runs a command or opens a shell
set -u
# Starts an EC2 instance _if needed_ and runs an SSH command or opens a shell.
# Summary of steps:
# 1. Checks current instance status
# 2. Starts instance if needed
# 3. Waits for the instance to be ready (status "running")
# 4. Connects via SSH, possibly running a command
set -u
# Clones and softlinks a git repo, _if needed_.
# Summary of steps:
# 1. Checks that the provided repo is valid (SSH or HTTP)
# 2. Compares local and remote commit to see if there is a new version
# 3. Clones the remote commit in local, adding -<timestamp>-<commit> to the folder name
# 4. Deletes .git directory of the cloned repo
jotaelesalinas / Laravel-MakeConfig.php
Last active Aug 31, 2021
Laravel make:config artisan command
View Laravel-MakeConfig.php
* Run this artisan command before:
* php artisan make:command MakeConfig
namespace App\Console\Commands;
use Illuminate\Console\Command;
View geoloc.html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<script src="" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
jotaelesalinas / dragndrop.js
Created Nov 14, 2018
Javascript script for easy drag and drop on an HTML element
View dragndrop.js
* 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 / selectr.js
Created Apr 6, 2018
JS snippet to pick elements and extract text and links
View selectr.js
(function () {
var self = this;
self.version = '1.2';
self.els = {};
self.utils = {};
self.utils.addEvent = function (el, evname, f, capture) {
View 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;
View read_from_console.php
function read_from_console ($prompt) {
if ( function_exists('readline') ) {
$line = trim(readline($prompt));
if (!empty($line)) {
} else {
echo $prompt;
$line = trim(fgets(STDIN));