Skip to content

Instantly share code, notes, and snippets.

View stgogm's full-sized avatar
Always at work

Santiago "Momo" Marín stgogm

Always at work
View GitHub Profile
@stgogm
stgogm / ArrayShuffle.js
Last active March 4, 2020 14:17
This is just for shuffling an array. It gives you a more shuffled array than using sort(). I got it from http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/ - I'm keeping it here just for backup purposes.
/**
* Shuffles array in place.
*
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
@stgogm
stgogm / GetRandomInt.js
Created April 25, 2013 19:09
A small function for getting a random integer.
function gri(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@stgogm
stgogm / PasswordsVisible.js
Created April 27, 2013 20:16
This is a simple code for toggling password input fields into text fields and vice versa. You must provide a listener element, like a check box, and the inputs ID you want to toggle as 'passwordInputA, passwordInputB, ...'.
function PasswordsVisible(listener, fields) {
this.obscure = true;
this.fields = fields;
this.listener = $('#' + listener);
this.length = 0;
this.init();
}
PasswordsVisible.prototype = {
init : function() {
@stgogm
stgogm / install-dev-stack.sh
Last active April 25, 2020 17:42
Install, update and configure Git, Node.JS, MongoDB, VS Code and Redis Server in Ubuntu
#!/bin/bash
clear
# Install and update/upgrade dependencies
printf "Updating and installing dependencies...\n"
sudo apt update
sudo apt upgrade -y
sudo apt install -y build-essential curl git vim wget gnupg
@stgogm
stgogm / fixed-aspect.scss
Last active August 29, 2015 14:20
SCSS or LESS classes for fixed common aspect ratios.
/**
* Fixed aspect containers.
*
* Credit: Nicolas Gallagher and SUIT CSS.
*/
.fixed-aspect {
position: relative;
display: block;
height: 0;
@stgogm
stgogm / person-name-regexp.js
Last active March 14, 2019 16:01
Person's name RegExp
/^([a-z\u00C0-\u02AB'´`]{1,}\.?\s?)([a-z\u00C0-\u02AB'´`]?\.?\s?)+$/i
@stgogm
stgogm / convert-video-audio-only.sh
Created May 28, 2016 03:00
Convert the audio stream only of a video to AAC using avconv.
avconv -i $INPUT_FILE -strict experimental -map 0:v -map 0:a -c:a aac -b:a 768k -c:v copy $OUTPUT_FILE
@stgogm
stgogm / mongod.service
Created July 30, 2016 19:37
MongoDB Ubuntu 16.04 Systemd Service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
/**
* Scores a password's strength.
*
* It scores a password according to several factors like character variation,
* repetition and length. The passwords are scored in a numeric point scale that
* varies from less than 0 to 100 and more. A safe password score should be
* considered as 49 points or more.
*
* @param {String} pwd The password string to score.
*
@stgogm
stgogm / less-to-scss-regexps.js
Last active March 6, 2017 16:58
LESS to SCSS Regexps
var mixinsDef = /\.([\w-]+)\(([\w-;\$\s]*)\)\s+?{/i; // Replace with: @mixin $1($2) {
var mixinsCall = /\.([\w-]+)\(([\w-;\$\s]*)\);/i; // Replace with: @include $1($2);