Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Cardona Rojas DanielCardonaRojas

View GitHub Profile
View Monoids.swift
protocol Semigroup {
/* A semigroup is a set and a binary operator defined for elements within that
set, to yeild a another element of the same type.
*/
static func combine (_ lhs: Self, _ rhs: Self) -> Self
}
extension Semigroup {
// Extending a protocol enables to get free functions based on the implementation of the protocol
func mappend(_ with: Self) -> Self {
View BezierView.swift
class BezierView: UIView {
private var bezier: UIBezierPath
init(bezier: UIBezierPath) {
self.bezier = bezier
let transform = CGAffineTransform()
transform.scaledBy(x: 2, y: 2)
let rectBounds = bezier.bounds
rectBounds.applying(transform)
@DanielCardonaRojas
DanielCardonaRojas / ArrayExtensions.swift
Last active Mar 5, 2018
Some array extensions following the FP bloodline
View ArrayExtensions.swift
var str = "hhhhh Hello playground"
extension String {
static func groupBy(_ string: String, _ f: (Character, Character) -> Bool) -> [String] {
let array = Array(string) as! [Character]
let groups = Array.groupBy(array, f)
return groups.map { g in String(g) }
}
static func group(_ string: String) -> [String] {
View FunctionCombinators.swift
/* -------------- Higher order function combinators ---------------- */
// Composition operators
infix operator >>>
func >>> <A,B,C> (aToB: @escaping (A) -> B, bToC: @escaping (B) -> C) -> (A) -> C {
return { a in aToB(a) |> bToC }
}
infix operator <<<
func <<< <A,B,C> (bToC: @escaping (B) -> C, aToB: @escaping (A) -> B) -> (A) -> C {
View StringExtensions.swift
import Foundation
// MARK: - Getting substrings
// String API lacks take(while:) and suffix(while:) but has drop(while:) and prefix(while:)
extension String {
func prefix(while predicate: (Unicode.Scalar) -> Bool) -> Substring {
return self.prefix(while: { (c: Character) -> Bool in
return c.unicodeScalars.contains(where: predicate)
})
}
View ProgressView.swift
//
// ProgressView.swift
// ProgressView
//
// Created by Daniel Cardona on 4/26/18.
// Copyright © 2018 Daniel Cardona. All rights reserved.
//
import UIKit
@DanielCardonaRojas
DanielCardonaRojas / DecodeJwt.sh
Created May 2, 2018
Decode Jwt from command line
View DecodeJwt.sh
# Decode the payload
echo $token | cut -d '.' -f2 | base64 -D
# Decode the header
echo $token | cut -d '.' -f1 | base64 -D
@DanielCardonaRojas
DanielCardonaRojas / MyCustomElement.js
Created Jul 9, 2018
CustomElement WebComponent Template
View MyCustomElement.js
class MyCustomElement extends HTMLElement {
constructor(){
super();
}
static get observedAttributes() {
return [];
}
// Life Cycle
@DanielCardonaRojas
DanielCardonaRojas / Coordinates.elm
Created Jul 19, 2018
Elm google-map custom element
View Coordinates.elm
module Data.Coordinates exposing (..)
import Json.Decode as Decode exposing (Decoder, float, Value)
import Json.Encode as Encode
import Json.Decode.Pipeline as Pipeline exposing (required)
import Geolocation
type alias Coordinates =
{ latitude : Float
, longitude : Float
View pascal.elm
module Main exposing (main)
import Html exposing (Html)
numberRows = 5
generate : (a -> a) -> a -> Int -> List a
generate f seed n =
if n <= 0 then
[f seed]
You can’t perform that action at this time.