Skip to content

Instantly share code, notes, and snippets.

View diegolameira's full-sized avatar

Diego Lameira diegolameira

View GitHub Profile
@diegolameira
diegolameira / Back 'n Forth
Last active July 28, 2016 15:00
Just a reference to go back and forth into an array with loop. See it in action: http://run.plnkr.co/plunks/7ngbHx/
var step = 1,
active = 0,
items = new Array();
function next(){
active = (active + step) % items.length;
// active = ++active % items.length;
}
function prev(){
@diegolameira
diegolameira / Queue (FIFO)
Last active January 3, 2017 15:39
Just a wrapper Class for FIFO, obviously Array.shift do the job standalone.
var FIFO = (function () {
'use strict';
// Load Dependencies
var _ = require('lodash');
// Set default configurations
var defaultConfig = {
type: 'number',
random: false,
@diegolameira
diegolameira / Stack (LIFO)
Last active January 3, 2017 15:38
Just a wrapper Class for LIFO, obviously Array.pop do the job standalone.
var Stack = (function(){
'use strict';
// Class private shared vars
var place = 'kitchen';
// Constructor
function Stack(some){
// Instance private vars
@diegolameira
diegolameira / increment_build_number.js
Created February 17, 2017 15:03
Cordova hook for incrementing build numbers
#!/usr/bin/env node
// Save hook under `project-root/hooks/before_prepare/`
//
// Don't forget to install xml2js using npm
// `$ npm install xml2js`
var fs = require('fs');
var xml2js = require('xml2js');
@diegolameira
diegolameira / bingen.ts
Last active March 18, 2018 04:06
Binary Based Enum Read Sum
function bingen(size) {
let c;
return Array.from({length: size}, (y, k) => c = (c||1) * 2);
}
@diegolameira
diegolameira / removeAccents.js
Last active March 19, 2018 00:25
Remove Accents
function removeAccents(string) {
const special = 'ÀÁÂÃÄÅĄàáâãäåąßÒÓÔÕÕÖØÓòóôõöøóÈÉÊËĘèéêëęðÇĆçćÐÌÍÎÏìíîïÙÚÛÜùúûüÑŃñńŠŚšśŸÿýŽŻŹžżź';
const stripped = 'AAAAAAAaaaaaaaBOOOOOOOOoooooooEEEEEeeeeeeCCccDIIIIiiiiUUUUuuuuNNnnSSssYyyZZZzzz';
return string
.split('')
.map((letter) => {
const index = special.indexOf(letter);
return index !== -1 ? stripped[index] : letter;
@diegolameira
diegolameira / string-utils.js
Created March 19, 2018 00:26 — forked from jonlabelle/string-utils.js
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str){
return str.toLowerCase();
import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';
let props;
beforeEach(() => {
props = {
isPrimary: false,
isDanger: false,
const missingInteger = (A) => {
// remove dups and filter by integers
A = Array.from(new Set(A)).filter((i) => i > 0);
if (!A.length) return 1;
const max = Math.max.apply(Math, A);
const items = new Array(max);
A.forEach((x) => (items[x - 1] = x));
@diegolameira
diegolameira / getChangeInCoins.js
Created November 22, 2020 18:44
given money and price it would return coins as [1c, 5c, 10c, 25c, $1]
/**
* getChangeInCoins
* @description given money and price it would return coins as [1c, 5c, 10c, 25c, $1]
* @param {float} money
* @param {float} price
*/
const getChangeInCoins = (money, price) => {
let value = (money - price) * 100;
return [100, 25, 10, 5, 1]
.map((coin) => {