Skip to content

Instantly share code, notes, and snippets.

🎩
Working my way to FI/RE

Cristián Arenas Ulloa NinoScript

🎩
Working my way to FI/RE
Block or report user

Report or block NinoScript

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View groupBy.ts
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 Aug 30, 2018
You can use this generator to get nicely distributed color with the same saturation and lightness.
View randomColorGenerator.js
// 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;
}
View post-robot.d.ts
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 Mar 8, 2018
Rotate UIView with anchorPoint
View UIViewRotate.playground
//: 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 Jan 22, 2018
Macro for running tests that use Mnesia in a transaction
View mnesia_test.ex
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 Mar 23, 2017
D3.js-like enter and exit functions for ReactiveSwift
View SignalProducer+D3.swift
//
// 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 Mar 9, 2017
Just some utility functions for when you are working inside a throwing function
View ThrowingUtils.swift
//
// ThrowingUtils.swift
//
// Created by Cristián Arenas Ulloa on 1/13/17.
// WTFPLv2
//
// Usage example: try maybeValue.unwrapped()
extension Optional {
func unwrapped() throws -> Wrapped {
View ThrowingUtils.swift
//
// 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 Jan 26, 2017
Playing around with the concept of "emptiable" values
View Emptiable.swift
//: 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? {
@NinoScript
NinoScript / EnumNSCoding.swift
Last active Mar 19, 2018
NSCoding a Swift Enum
View EnumNSCoding.swift
//: Playground - noun: a place where people can play
import Cocoa
enum Enum {
case SimpleCase
case AssociatedValue(String)
case AnotherAssociated(Int)
}
extension Enum {
You can’t perform that action at this time.