Skip to content

Instantly share code, notes, and snippets.

View jerolan's full-sized avatar

Jerome Olvera jerolan

View GitHub Profile
/**
* From https://v1.dinerojs.com/dinero.js
* Allocates the amount of a Dinero object according to a list of ratios.
*
* Sometimes you need to split monetary values but percentages can't cut it without adding or losing pennies.
* A good example is invoicing: let's say you need to bill $1,000.03 and you want a 50% downpayment.
* If you use {@link module:Dinero~percentage percentage}, you'll get an accurate Dinero object but the amount won't be billable: you can't split a penny.
* If you round it, you'll bill a penny extra.
* With {@link module:Dinero~allocate allocate}, you can split a monetary amount then distribute the remainder as evenly as possible.
*
/**
* First Reverse
* Have the function FirstReverse(str) take the str parameter
* being passed and return the string in reversed order.
* For example: if the input string is "Hello World and Coders"
* then your program should return the string sredoC dna dlroW olleH.
*
* Test Cases
* > firstReverse "Hello World and Coders"
* "sredoC dna dlroW olleH"
@jerolan
jerolan / word_frequencies_top.txt
Created June 27, 2016 03:38 — forked from romainmet/word_frequencies_top.txt
Udacity Assessment Answer - Machine Learning Nanodegree
"""Count words."""
count={}
def count_words(s, n):
"""Return the n most frequently occuring words in s."""
wordlist = s.split()
wordfreq = [wordlist.count(p) for p in wordlist]
zip_l=dict(zip(wordlist,wordfreq))
sort=sorted(zip_l.iteritems(),key=lambda(k,v):(-v,k))
function flip(arr, right) {
let temp;
let left = 0;
while (left < right) {
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
// scroll
@jerolan
jerolan / webpack.config.js
Created April 26, 2016 05:06 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
interface Success<a> {
value: a;
}
interface Failure<e> {
error: e;
}
type Result<a, e> = Success<a> | Failure<e>;
@jerolan
jerolan / sharpImageOptim.js
Last active April 27, 2021 15:23
sharpImageOptim.js
const sharp = require('sharp');
const fs = require('fs');
const directory = './public';
const extensions = ['jpeg', 'jpg', 'png', 'webp', 'avif', 'gif', 'svg', 'tiff'];
const breakpoints = [640, 768, 1024, 1280, 1536];
fs.readdirSync(directory)
.filter(filterImagePath)
.forEach((dir) => {
// stringChallenge va a divide el problema en dos pequeñas soluciones
// conocer el valor en 24 horas, para hacer las fácil una comparación de tiempo entre 0 y 24
// convertir las horas en minutos para hacer una diferencia simple
function stringChallenge(strArr) {
// pair nos va a servir como auxiliar para comparar los elementos en el arreglo
// podríamos hacer una doble iteración y seria una solución fácil, pero no optima
let pair = [];
// min es el valor actual, de la diferencia entre las horas
// la estaremos actualizando a medida que hagamos las comparaciones
let min = 0;
function largestPair(num) {
let pair = null;
num
.toString()
.split("")
.forEach((val, index, arr) => {
if (arr.length - 1 !== index) {
let currentPair = parseInt(val + arr[index + 1]);
if (pair < currentPair) pair = currentPair;
function simpleAdding(num) {
let sum = 0;
for (let i = 0; i <= num; i++) sum += i;
return sum;
}