Skip to content

Instantly share code, notes, and snippets.

View egalink's full-sized avatar
🏠
Trabajando desde casa

Jakim Hernández egalink

🏠
Trabajando desde casa
View GitHub Profile
@egalink
egalink / check_and_run_container_from_crontab.sh
Last active January 12, 2024 18:10
Checks if a docker container exists and is running. This script is adapted to use in a crontab.
#!/bin/bash
# check_and_run_container_from_crontab.sh
# chmod +x check_and_run_container_from_crontab.sh
# @reboot /path/to/check_and_run_container_from_crontab.sh my_container_name
container_name=$1
if docker container inspect "$container_name" &>/dev/null; then
echo "Container $container_name already exists, checking status..."
if $(docker inspect -f '{{.State.Status}}' "$container_name" | grep -q "running"); then
@egalink
egalink / docker-container-exists.sh
Last active July 17, 2025 09:02
Checks if a docker container exists and is running.
#!/bin/bash
# To check if a Docker container exists, you can use
# the docker ps command. However, it only shows the running containers.
# If you want to check if a container with a specific name exists,
# regardless of whether it is running or not, you can use
# the docker inspect command. It will return information about the container,
# and if it does not exist, it will return an error.
#!/bin/bash
# This script can copy or move files from one folder to another,
# removing special characters in file names that can cause file system
# inconsistencies
# HOW TO USE:
# 1. Open a terminal and navigate to the directory containing the script file.
# 2. Make the script executable by running the following command:
# -> chmod +x bkpfiles.sh
var collection = [
{item: "lapiz", cost: 10.2, vendor: "mari"},
{item: "lapiz", cost: 11.2, vendor: "maris"},
{item: "lapiz", cost: 8.24, vendor: "maris"},
{item: "lapiz", cost: 8.232, vendor: "maris"},
{item: "lapiz", cost: 8.23198, vendor: "maris"},
{item: "lapiz", cost: 8.23199, vendor: "maris"},
{item: "lapiz", cost: 8.25, vendor: "maris"},
{item: "lapiz", cost: 8.256, vendor: "maris"},
{item: "lapiz", cost: 9, vendor: "mariss"},
/**
* This will parse a delimited string into an array of arrays.
* The default delimiter is the comma, but this can be
* overriden in the second argument.
*
* ref: http://stackoverflow.com/a/1293163/2343
*
* @param {String} strData
* @param {String} strDelimiter
*/
/**
* Creates an array of elements split into groups the length of size.
* If array can't be split evenly, the final chunk will be the remaining elements.
*
* Usage:
* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19].chunk(4)
*
* @return (5) [Array(4), Array(4), Array(4), Array(4), Array(4)]
*/
Array.prototype.chunk = function (size = 0) {
/**
* Obtiene los valores de un string que proceden después de dos puntos:
*
* @return (2) ["file", "csv,xls,xlsx"]
*/
'file:csv,xls,xlsx'.match(/(?:[^:*]+)/gi)
@egalink
egalink / distance-between-coords.js
Last active May 6, 2019 20:20
Distance between coords
'use strict';
/**
* Below is an example function that takes two sets of
* longitude and latitude co-ordinates and returns the
* distance between the two.
*
* http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe
*/
var getDistance = function (lat1, lon1, lat2, lon2) {
var regexpCatalog = {
rule: /^(.+?)\[(.+)\]$/,
numeric: /^[0-9]+$/,
integer: /^\-?[0-9]+$/,
decimal: /^\-?[0-9]*\.?[0-9]+$/,
email: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
alpha: /^[a-z]+$/i,
alpha_numeric: /^[a-z0-9]+$/i,
alpha_dash: /^[a-z0-9_\-]+$/i,
natural: /^[0-9]+$/i,
var getCoordinatesFromValue = function (value) {
// extract coordinates from value:
var regexp = /@(-?\d+\.\d+),(-?\d+\.\d+),(\d+\.?\d?)+z/g;
if (regexp.test(value) == true) {
// check if value comes from google maps URL:
value = value.match(regexp);
if (value) {
// value has not empty:
value = value.join('').split(',');
value.pop();