Skip to content

Instantly share code, notes, and snippets.

View illescasDaniel's full-sized avatar
💻
Learning something new

Daniel Illescas Romero illescasDaniel

💻
Learning something new
View GitHub Profile
@illescasDaniel
illescasDaniel / guardStatement.cpp
Created December 26, 2016 14:39
Guard statement from Swift in C++
#include <iostream>
#define guard(_condition) if (bool(_condition)){}
using namespace std;
// Example inside a function
template <typename Type>
Type biggestNumber(Type* numbers, const size_t& size) {
guard(numbers != nullptr) else {
@illescasDaniel
illescasDaniel / benchmark.hpp
Last active March 1, 2017 17:57
Easy benchmark [C++]
#include <chrono>
#include <chrono>
namespace evt {
template <typename Function>
float benchmark(const Function& function, size_t iterations = 1) {
float averageTime = 0.0;
@illescasDaniel
illescasDaniel / Any.cpp
Created January 14, 2017 18:24
"Any" Class that stores values of any type
#include <iostream>
using namespace std;
string to_string(const string& str) { return str; }
class Any {
shared_ptr<void*> value_ { nullptr };
@illescasDaniel
illescasDaniel / String+Email.swift
Last active March 26, 2017 21:18 — forked from DaveWoodCom/String+Email.swift
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
import Foundation
extension String {
mutating func isValidEmail() -> Bool {
guard !self.lowercased().hasPrefix("mailto:") else { return false }
guard let emailDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else { return false }
@illescasDaniel
illescasDaniel / UITextView+Extension.swift
Created May 20, 2017 22:52
UITextView Center text Vertically
//
// UITextView+Extension.swift
//
// Created by Daniel Illescas Romero on 21/05/2017.
//
import UIKit
extension UITextView {
@illescasDaniel
illescasDaniel / slider.html
Last active December 13, 2017 09:23
HTML Slider (with JS)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>hola</title>
</head>
<body>
<input id="sliderValueInput" type="text" style="width: 3em" value="0">
<input id="slider" type="range" value="0">
</body>
@illescasDaniel
illescasDaniel / shuffleCollection.swift
Created June 24, 2017 20:49
Shuffle Collection [Swift]
import GameplayKit
extension Collection {
func shuffled() -> [Iterator.Element] {
let shuffledArray = (self as? NSArray)?.shuffled()
let outputArray = shuffledArray as? [Iterator.Element]
return outputArray ?? []
}
mutating func shuffle() {
if let selfShuffled = self.shuffled() as? Self {
@illescasDaniel
illescasDaniel / randomNumber.cpp
Last active June 27, 2017 11:57
Function to generate random 64bits numbers
#include <iostream>
#include <random>
using namespace std;
unsigned long long randomNumber(unsigned long long upperLimit = mt19937_64::max()) {
random_device rd;
mt19937_64 generator(rd());
return generator() % upperLimit;
}
@illescasDaniel
illescasDaniel / UIColor+Extensions.swift
Created September 12, 2017 15:42
UIColor RGB, Hex and P3 support. Also property to get components
import UIKit
extension UIColor {
convenience init(P3ReadyRed red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1.0, forceP3IfAvailable: Bool = true) {
if #available(iOS 10.0, *), forceP3IfAvailable {
self.init(displayP3Red: red, green: green, blue: blue, alpha: alpha)
} else {
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
@illescasDaniel
illescasDaniel / SlideAnimationTabBarController.swift
Last active April 11, 2022 14:03 — forked from benvium/MyTabBar.m
[Updated to Swift 4] - UITabBarController slide animation. Slide left and right when tabs are selected. Based on code from StackOverflow
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let fromView = tabBarController.selectedViewController?.view,
let toView = viewController.view, fromView != toView,
let controllerIndex = self.viewControllers?.index(of: viewController) {
let viewSize = fromView.frame
let scrollRight = controllerIndex > tabBarController.selectedIndex
// Avoid UI issues when switching tabs fast