Skip to content

Instantly share code, notes, and snippets.

View kevinnio's full-sized avatar

Kevin Perez kevinnio

View GitHub Profile
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts on multiple book purchases.
One copy of any of the five books costs $8.
If, however, you buy two different books, you get a 5% discount on those two books.
If you buy 3 different books, you get a 10% discount.
If you buy 4 different books, you get a 20% discount.
kevinnio / AreaConocimiento.php
Last active February 27, 2020 05:25
Ejemplo para obtener areas de conocimiento según categoría
public class AreaConocimiento extends Siiutem\Modelo {
public categoria() {
return $this->belongsTo(CategoriaAreaConocimiento::class, "categoria_id");
kevinnio /
Last active June 17, 2019 03:18
Adding Jest to a Babel 6 project

Jest is an amazing testing tool developed by the folks at Facebook and maintained by a vast community of developers. Is one of the best ways to write and run Javascript tests. It should be really easy to setup starting from scratch, but what if we want to integrate it into an already initialized project? One which uses Babel 6 and already has a .babelrc file.

The problem with Babel 6

Jest requires Babel to transpile Javascript code that doesn't normally run on NodeJS environments, most commonly ES2015 modules. Problem is Jest dropped support for Babel 6 since 24.0.0 in favour of Babel 7, which introduces a lot of changes to how devs work with Babel. Jest recommends upgrading if your project is still on Babel 6, but not all projects can upgrade quickly. This blog post is for those kinds of projects.

Alternative setup

Let's start by i

kevinnio /
Last active May 27, 2019 15:04
Mario Kart Tournament Rules

Mario Kart Tournament Rules

First stage

  • Groups will be composed of 4 players max.
  • Each group will play 1 Versus Mode round with the following rules:
    • 150cc race
    • Teams: No
    • Items: Normal
    • CPU Level: Hard
kevinnio / code.txt
Created May 22, 2019 19:54
Example of Fira Code on GitHub
object o;
if (o is int i || (o is string s &&
int.TryParse(s, out i)) { /* use i */ }
var x = 0xABCDEF;
-> --> ==> != === !== && ||<=<
<=><!-- HTML Comment -->
i++; #### ***
.highlight pre,
code {
font-family: 'Fira Code'
kevinnio / md5rename
Last active May 2, 2019 01:56
Renames all files in the current dir using their MD5 checksums.
#! /bin/bash
md5 * | sed -e 's/MD5 (\([^.]*\)\(.[^)]*\)) = \(.*\)$/mv -v "\1\2" \3\2/' | sh
kevinnio / spree_decorator.rb
Last active October 24, 2018 01:10
Spree/Solidus Module Decorator pattern
require 'active_support/concern'
module MyNamespace::SpreeDecorator
extend ActiveSupport::Concern
included do
# Call base class methods here!
some_class_method :foo
some_class_method_with_block do
another_class_method :bar
kevinnio / app.rb
Last active October 4, 2018 17:38
The OddEven kata
require './oddeven'
oddeven =
(1..100).each { |number| puts oddeven.print_number(number) }
kevinnio / app.rb
Last active October 4, 2018 16:18
The FizzBuzz kata
require './fizzbuzz'
fizzbuzz =
(1..100).each { |number| puts fizzbuzz.print_number(number) }