Skip to content

Instantly share code, notes, and snippets.

View DanielCardonaRojas's full-sized avatar

Daniel Cardona Rojas DanielCardonaRojas

View GitHub Profile
@DanielCardonaRojas
DanielCardonaRojas / ArrayExtension.swift
Last active March 27, 2021 01:08
More Array Extensions flattened, unwrapped, all and any.
extension Array {
func flattened<T>() -> [T] where Element == [T] {
return self.flatMap({ $0 })
}
func all(_ pred: (Element) -> Bool) -> Bool {
return self.reduce(true, { acc, v in acc && pred(v) })
}
func any(_ pred: (Element) -> Bool) -> Bool {
@DanielCardonaRojas
DanielCardonaRojas / ProfileInputField.swift
Created September 18, 2018 14:09
An example of a programmatic custom view
//
// ProfileInputField.swift
// CustomViews
//
// Created by Daniel Esteban Cardona Rojas on 9/14/18.
// Copyright © 2018 Daniel Esteban Cardona Rojas. All rights reserved.
//
import UIKit
@DanielCardonaRojas
DanielCardonaRojas / UIStackView+Separator.swift
Last active September 15, 2021 21:35
UIStackView+Extensions
extension UIStackView {
func insertSeparator(_ createSeparator: (() -> UIView)) {
let subviews = self.arrangedSubviews
for v in subviews {
self.removeArrangedSubview(v)
}
for v in subviews {
self.addArrangedSubview(v)
@DanielCardonaRojas
DanielCardonaRojas / IntersperseElement.swift
Last active September 17, 2021 13:50
Extension for swift arrays to intersperse elements
extension Array {
func interspersing(_ element: Element) -> Array {
var newArray: [Element] = []
for (index, item) in self.enumerated() {
newArray.append(item)
if index < self.count - 1 {
newArray.append(element)
}
}
return newArray
extension NSMutableAttributedString {
func replacingOccurrences(of item: String, with replacement: NSAttributedString) {
guard let range: Range<String.Index> = self.string.range(of: item) else {
return
}
let nsrange = NSRange(range, in: self.string)
self.replaceCharacters(in: nsrange, with: replacement)
}
}
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]
@DanielCardonaRojas
DanielCardonaRojas / Coordinates.elm
Created July 19, 2018 14:54
Elm google-map custom element
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
@DanielCardonaRojas
DanielCardonaRojas / MyCustomElement.js
Created July 9, 2018 19:54
CustomElement WebComponent Template
class MyCustomElement extends HTMLElement {
constructor(){
super();
}
static get observedAttributes() {
return [];
}
// Life Cycle
@DanielCardonaRojas
DanielCardonaRojas / DecodeJwt.sh
Created May 2, 2018 00:07
Decode Jwt from command line
# Decode the payload
echo $token | cut -d '.' -f2 | base64 -D
# Decode the header
echo $token | cut -d '.' -f1 | base64 -D
//
// ProgressView.swift
// ProgressView
//
// Created by Daniel Cardona on 4/26/18.
// Copyright © 2018 Daniel Cardona. All rights reserved.
//
import UIKit