Skip to content

Instantly share code, notes, and snippets.

View dmmarmol's full-sized avatar

Diego Mármol dmmarmol

View GitHub Profile
@dmmarmol
dmmarmol / env-variable-name.js
Last active July 31, 2023 16:05
Script to check the existing variable names of the .env.example file matches the ones in the sibling .env.development file
import fs from "fs";
import dotenv from "dotenv";
import { fileURLToPath } from "url";
import path from "path";
const referenceFiles = [
".env.development",
".env.local",
".env.production",
".env",
@dmmarmol
dmmarmol / formatCurrency.ts
Created September 22, 2020 14:31
Format Numbers
// Currency
function useCurrencyFormat() {
const { code, currency } = useCountryContext();
const options: Intl.NumberFormatOptions = {
style: 'currency',
currency,
minimumFractionDigits: 0,
maximumFractionDigits: 2,
};
@dmmarmol
dmmarmol / redux-middleware.ts
Created December 30, 2017 15:50
An example of a typed react-redux middleware using Typescript
import { Action } from 'redux/store-types';
import { Dispatch, MiddlewareAPI, Store } from 'redux';
export const authMiddleware = (_api: MiddlewareAPI<Store<void>>) => (
next: Dispatch<void>
) => <A extends Action>(action: A) => {
return next(action);
};
@dmmarmol
dmmarmol / README.md
Last active December 30, 2017 15:52
Email RegEx validation

Email RegEx Validations

Based on urlregex.com

Validate email syntax in JavaScript

Results

Email Is valid
@dmmarmol
dmmarmol / arrayMove.js
Created May 16, 2017 14:47
Move items inside an array and reorder (ES6)
const arrayMove = (array, from, to) => {
// Clone the original array
let newArray = array.slice();
// Get the item that will be moved
const movingItem = newArray.splice(from, 1)[0];
// Replace that item in the 'to' position
newArray.splice(to, 0, movingItem);
return newArray;
};
@dmmarmol
dmmarmol / Permutations.js
Created April 4, 2017 14:38
Create permutations from two or more given list
/**
* Create permutations from two or more given list
* Based on Heap's Algorithm
*/
function permutations() {
var r = [], arg = arguments, max = arg.length-1;
function helper(arr, i) {
for (var j=0, l=arg[i].length; j<l; j++) {
var a = arr.slice(0); // clone arr
a.push(arg[i][j]);
@dmmarmol
dmmarmol / run-mongodb.bat
Last active August 6, 2023 12:08
Simple Batch file for running MongoDB on a windows computer
if not exist "C:\mongodb\data\db\" mkdir C:\mongodb\data\db
if not exist "C:\mongodb\data\log\" mkdir C:\mongodb\data\log
@echo off
:: Update the 3.4 if you have another version
cd C:\Program Files\MongoDB\Server\3.4\bin
::set default port variable
set port=27017
:: add this line at the end of the ~mongod.exe to write the log on a separated file
@dmmarmol
dmmarmol / gulp-iconfont.js
Last active June 23, 2016 17:11
Gulpfile made for creating your custom icon fonts from .svg files.
var gulp = require('gulp');
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var ICONFONT = 'font-file-name';
// Working Dir
var APP = {
FOLDER: APPFOLDER,
ICONS: APPFOLDER+'/src/icons',
@dmmarmol
dmmarmol / Material-Buttons.markdown
Last active February 2, 2016 14:39
Material design click animation effect using SCSS + JS