Skip to content

Instantly share code, notes, and snippets.

View NinoScript's full-sized avatar
🎩
Working my way to FI/RE

Cristián Arenas Ulloa NinoScript

🎩
Working my way to FI/RE
View GitHub Profile
@NinoScript
NinoScript / APV.md
Created December 28, 2021 15:06
Explicación sobre el Ahorro Previsional Voluntario (APV) en Chile

Ahorro Previsional Voluntario (APV)

El APV es un instrumento para incentivarte a ahorrar más de lo que ahorras en la AFP.

Este incentivo tiene dos regímenes, el A y el B. Ambos te incentivan de maneras distintas, a veces conviene uno más que el otro, a veces conviene tener los dos. Y el incentivo tiene un tope combinado de 600UF de ahorro al año.

APV régimen A

export function groupBy<T, K>(array: T[], getKey: (value: T) => K): Map<K, T[]> {
return array.reduce(
(groups, item) => {
const key = getKey(item);
const innerArray = groups.get(key);
if (innerArray === undefined) {
groups.set(key, [item])
} else {
innerArray.push(item)
}
@NinoScript
NinoScript / randomColorGenerator.js
Last active November 28, 2021 15:57
You can use this generator to get nicely distributed color with the same saturation and lightness.
// TIL that a `function *` in JavaScript makes a generator.
// Generators "yield" values and their execution is paused until next() is called.
function * randomColorGenerator(initialHue, saturation, lightness) {
const phi = 0.618033988749895;
let hue = initialHue;
while(true) {
yield `hsl(${Math.round(hue)}, ${saturation}, ${lightness})`;
hue = (hue + phi * 360) % 360;
}
declare module 'post-robot' {
// Warning: This is not actually a Promise, but the interface is the same.
type ZalgoPromise<T> = Promise<T>;
// For our purposes, Window is cross domain enough. For now at least.
type CrossDomainWindowType = Window;
type WindowResolverType = CrossDomainWindowType | string | HTMLIFrameElement;
// Client
// Loosely based on: https://github.com/krakenjs/post-robot/blob/master/src/public/client.js
@NinoScript
NinoScript / UIViewRotate.playground
Created March 8, 2018 15:37
Rotate UIView with anchorPoint
//: Playground - noun: a place where people can play
import UIKit
let r = UIView(frame: CGRect(
x: 0,
y: 0,
width: 200,
height: 200
))
@NinoScript
NinoScript / mnesia_test.ex
Last active January 22, 2018 19:05
Macro for running tests that use Mnesia in a transaction
defmacro mnesia_test(description, context \\ quote(do: _), do: block) do
quote do
test unquote(description), unquote(context) do
{:aborted, error} =
Mnesia.transaction(fn ->
unquote(block)
Mnesia.abort(:ok)
end)
case error do
@NinoScript
NinoScript / SignalProducer+D3.swift
Created March 23, 2017 20:43
D3.js-like enter and exit functions for ReactiveSwift
//
// SignalProducer+D3.swift
//
// Created by Cristián Arenas Ulloa on 3/23/17.
// WTFPLv2
//
// This overcomplicated tool fits my use case.
// It will probably make a lot of sense to you too if you've ever used D3.js.
// There was probably an easier way to do it,
// but I'm just learning ReactiveSwift so don't hate me .
@NinoScript
NinoScript / ThrowingUtils.swift
Last active March 9, 2017 16:48
Just some utility functions for when you are working inside a throwing function
//
// ThrowingUtils.swift
//
// Created by Cristián Arenas Ulloa on 1/13/17.
// WTFPLv2
//
// Usage example: try maybeValue.unwrapped()
extension Optional {
func unwrapped() throws -> Wrapped {
//
// ThrowingUtils.swift
//
// Created by Cristián Arenas Ulloa on 1/13/17.
// WTFPLv2
//
import Foundation
// Usage example: try maybeValue.unwrapped()
@NinoScript
NinoScript / Emptiable.swift
Last active January 26, 2017 17:11
Playing around with the concept of "emptiable" values
//: Playground - noun: a place where people can play
import Cocoa
protocol Emptiable {
static var emptyValue: Self { get }
}
extension Emptiable where Self: Equatable {
var nonEmptyValue: Self? {