Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
@samuelbeek
samuelbeek / Compare.swift
Created May 6, 2015 09:29
Compare Sizes (CGSize) in Swift
func isSmaller(smaller: CGSize, bigger: CGSize) -> Bool {
if(smaller.width >= bigger.width) { return false }
if(smaller.height >= bigger.height) { return false }
return true
}
@samuelbeek
samuelbeek / backgrounds.css
Last active August 29, 2015 14:23
Random Background Directive
// backgrounds:
.bgRed {
background-color: rgba(255,0,0,0.5)!important;
}
.bgYellow {
background-color: rgba(255,204,0,0.5)!important;
}
.bgGreen {
@samuelbeek
samuelbeek / LogHelper.swift
Last active August 29, 2015 14:24
Amazing logging in swift.
//
// LogHelper.swift
//
// Created by Samuel Beek on 24/06/15.
// Copyright (c) 2015 Samuel Beek. All rights reserved.
// http://twitter.com/samuelbeek
/// Logs objects
func log<T>(object: T) {
@samuelbeek
samuelbeek / Local.swift
Last active August 29, 2015 14:24
Awesome local storage usage with Realm in Swift
// this code does work, but since it's from a 'secret' project, I can't display
// the other code. Implement it in your own project, it'll work.
//
// LOCAL.swift
// Wildcard
//
// Created by Samuel Beek on 08/07/15.
// Copyright (c) 2015 Wildcard. All rights reserved.
//
//
// ColorHelper.swift
// Wildcard
//
// Created by Samuel Beek on 24/06/15.
// Copyright (c) 2015 Wildcard. All rights reserved.
//
import UIKit
@samuelbeek
samuelbeek / DeviceHelper.swift
Created October 8, 2015 10:46
detect iOS devices
// example if(Devices.iPhone4) { view.alpha = 0 }
struct Devices {
static let iPhone4 = UIScreen.mainScreen().bounds.size.height == 480.0
static let iPhone5 = UIScreen.mainScreen().bounds.size.height == 568.0
static let iPhone6 = UIScreen.mainScreen().bounds.size.height == 667.0
static let iPhone6plus = UIScreen.mainScreen().bounds.size.height == 736.0
}
@samuelbeek
samuelbeek / Analytics.swift
Created October 21, 2015 09:07
Google Analytics Helper (Work In Progress)
//
// Analytics.swift
// Instant
//
// Created by Samuel Beek on 21/10/15.
// Copyright © 2015 Samue Beek. All rights reserved.
//
struct Analytics {
@samuelbeek
samuelbeek / constants.swift
Last active October 21, 2015 18:55
Constants in Swift
// My way of doing constants in Swift.
// Usage example: if(Constants.debug) { println("debug message") }
struct Constants {
// App wide things:
static let debug = true
static let production = true
static let appVersion = "iOS-0.1.0b300"
static let apiBase = "http://api.com/1"
[
{
"code": "AD",
"emoji": "🇦🇩",
"unicode": "U+1F1E6 U+1F1E9",
"name": "Andorra",
"title": "flag for Andorra"
},
{
"code": "AE",
@samuelbeek
samuelbeek / Upload.swift
Last active November 10, 2015 11:16
Upload a file in a Multipart form
struct Uploader {
static let baseUrl = "YOUR API URL"
static func multipartBody(filePathKey: String, imageDataKey: NSData, boundary: String) -> NSData {
let body = NSMutableData();
let filename = "user-profile.jpg"
let mimetype = "image/jpg"
body.appendString("--\(boundary)\r\n")