Skip to content

Instantly share code, notes, and snippets.

View madcato's full-sized avatar
🪲
Building future bugs!!

Dani Vela madcato

🪲
Building future bugs!!
View GitHub Profile
// Asyncronous programming
import Foundation
// # Async-await samples
// ## Instead of using callbacks, ...
func getEmployeesJSON(url: URL, callback: @escaping ([Employee]) -> ())) {
URLSession.shared.dataTask(with: url), let response, response as? HTTPURLResponse, error == nil else {
if let let error = error {
print("Error downloading: \(error)")
import Foundation
import var CommonCrypto.CC_MD5_DIGEST_LENGTH
import func CommonCrypto.CC_MD5
import typealias CommonCrypto.CC_LONG
extension String {
func md5() -> String {
let length = Int(CC_MD5_DIGEST_LENGTH)
let messageData = data(using: .utf8)!
var digestData = Data(count: length)
@madcato
madcato / gist:a713fffa732d32a52dbc777b7791b885
Created February 22, 2021 11:16 — forked from itsmattsoria/gistfil1.textile
Mac Terminal Cheat Sheet

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@madcato
madcato / remotize.rb
Last active April 26, 2020 09:29
From an existing git repo, create a bare git repository on a remote server and configure its remote.
#!/usr/bin/env ruby
begin
project = ARGV[0]
server = ARGV[1]
if project.nil?
raise "<project> not specified"
end
if server.nil?
//
// OSDNIValidator.swift
// OSFramework
//
// Created by Daniel Vela on 21/09/2016.
// Copyright © 2016 Daniel Vela. All rights reserved.
//
import Foundation
/**
// To decode a json where the type to decode is in the json itself like:
// [{ "type": "foo", "payload": { "word": "hello" "push_id": 3711282988, "size": 1, } }, { "type": "bar", "payload": { "size": 1, "radious": 0.5 } }]
struct FooPayload: Codable {
var word: String
var push_id: Int
var size: Int
}
@madcato
madcato / BlinkingImage.swift
Last active March 23, 2020 06:26
UIImage that continuously blink. "Assign it in the storyboard"
import UIKit
class BlinkingImage: UIImageView {
override func awakeFromNib() {
super.awakeFromNib()
UIView.animate(withDuration: 1.2,
delay: 0.0,
options: [.autoreverse, .repeat, .curveEaseInOut],
animations: {
self.alpha = 0.10
//
// Optional.swift
// UserLogin
//
// Created by Daniel Vela Angulo on 17/03/2020.
// Copyright © 2020 TBM. All rights reserved.
//
extension Optional where Wrapped == String {
var isNilOrEmpty: Bool {
@madcato
madcato / Observer.swift
Created January 12, 2020 18:02
Observer sample class using @propertyWrapper and class extension
//
// Observer.swift
// TestAspect
//
// Created by Daniel Vela on 12/01/2020.
// Copyright © 2020 veladan. All rights reserved.
//
protocol Observer {
associatedtype Value
@madcato
madcato / PropertyLogger.swift
Created January 12, 2020 17:42
Logger sample to explain how to use @PropertyWarpper
//
// User.swift
// TestAspect
//
// Created by Daniel Vela on 12/01/2020.
// Copyright © 2020 veladan. All rights reserved.
//
@propertyWrapper
struct Logger<Value> {