Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
@samuelbeek
samuelbeek / Code.gs
Created May 27, 2024 08:33
Calendar Colors
function ColorEvents() {
var today = new Date();
var nextweek = new Date();
nextweek.setDate(nextweek.getDate() + 14);
var calendars = CalendarApp.getAllOwnedCalendars();
for (var i=0; i<calendars.length; i++) {
var calendar = calendars[i];
@samuelbeek
samuelbeek / ImageTitleButton.swift
Created May 1, 2017 09:43
Button that contains image and title. Their relative position can be modified.
//
// ImageTitleButton.swift
// Coyote
//
// Created by Samuel Beek on 01/05/2017.
// Copyright © 2017 Samuel Beek. All rights reserved.
//
import UIKit
@samuelbeek
samuelbeek / ForceTouchGestureRecognizer.swift
Created January 4, 2017 10:40
Swift 3 implementation of Kraken Devs' force touch recognizer
// Source: https://krakendev.io/force-touch-recognizers/
// Without this import line, you'll get compiler errors when implementing your touch methods since they aren't part of the UIGestureRecognizer superclass
import UIKit.UIGestureRecognizerSubclass
//Since 3D Touch isn't available before iOS 9, we can use the availability APIs to ensure no one uses this class for earlier versions of the OS.
@available(iOS 9.0, *)
public class ForceTouchGestureRecognizer: UIGestureRecognizer {
//Since it also doesn't make sense to have our force variable as a settable property, I'm using a private instance variable to make our public force property read-only
private var _force: CGFloat = 0.0
@samuelbeek
samuelbeek / playground.swift
Created November 16, 2016 16:21
Enums with Associated Values that conform to NSCoding
// Inspiration: https://gist.github.com/NinoScript/47819cf6fe36d6845aee32d19b423e9b
//: Playground - noun: a place where people can play
import UIKit
enum SavableEnum {
case simpleCase
case associatedValue(String)
case anotherAssociated(Int)
}
extension SavableEnum {
@samuelbeek
samuelbeek / RandomColor.swift
Created June 15, 2016 10:08
Return random color (nice for debugging)
extension UIColor {
static func randomColor(alpha: CGFloat?) -> UIColor {
let red:CGFloat = CGFloat(drand48())
let green:CGFloat = CGFloat(drand48())
let blue:CGFloat = CGFloat(drand48())
return UIColor(red: red, green: green, blue: blue, alpha: alpha ?? 1.0)
}
}
@samuelbeek
samuelbeek / CartographyExtensions.swift
Created June 14, 2016 12:54
Making Cartography compile faster.
//
// CartographyExtensions.swift
// portkey
//
// Created by Samuel Beek on 14/06/16.
//
// Note: still WIP. I only dealt with the equality operator (==), haven't worked on <= and ~ yet.
// But adding this won't be bad for you project, it saves me 70% compile time per block on avarage.
import Foundation
@samuelbeek
samuelbeek / UIDeviceHelpers.swift
Created April 21, 2016 10:27
All devices in one big enum
import Foundation
public extension UIDevice {
public enum Model {
case iPodTouch5, iPodTouch6, iPhone4, iPhone4s, iPhone5, iPhone5c, iPhone5s, iPhone6, iPhone6Plus, iPhone6s, iPhone6sPlus, iPhoneSE, iPad2, iPad3, iPad4, iPadAir, iPadAir2, iPadMini, iPadMini2, iPadMini3, iPadMini4, iPadPro, AppleTV, Simulator, None
}
static var model: Model {
var systemInfo = utsname()
@samuelbeek
samuelbeek / TypingLabel.swift
Created December 9, 2015 15:36
Typewriting effect in swift
//
// TypingLabel.swift
//
// Created by Samuel Beek on 09/12/15.
// Copyright © 2015 Samuel Beek. All rights reserved.
//
import UIKit
import SwiftyTimer
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = false
controller.searchBar.barStyle = .Black
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
// remove navigation bar
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true