Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
@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 / 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"
@samuelbeek
samuelbeek / RandomBackgroundcolor.js
Created June 18, 2015 09:56
Random Background Color Directive for Angularjs
// just add random-backgroundcolor to the element you want to give a random background color
app.directive("randomBackgroundcolor", function () {
return {
restrict: 'EA',
replace: false,
link: function (scope, element, attr) {
//generate random color
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
@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 / 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 / DistanceHelper.swift
Created May 1, 2015 11:41
Distance Formatter for Swift
//
// DistanceHelper.Swift
// Wildcard
//
// Created by Samuel Beek on 01-05-15.
// Copyright (c) 2015 Wildcard. All rights reserved.
//
import Foundation
@samuelbeek
samuelbeek / movieService.js
Last active August 29, 2015 14:20
MovieService to use OMDB API with Angular
// movieService can be used in a controller like this:
// movieService.getMovieDetails("Pulp Fiction").success(function (data) {
// $scope.movie = data
// }
app.factory('movieService', ['$http', function ($http) {
return {
getMovieDetails: function (title) {
var getData = {
method: 'jsonp',
url: 'http://www.omdbapi.com/?t=' + title, //add +'&apikey=YOUR_API_KEY' if you have one.
@samuelbeek
samuelbeek / generateCode.swift
Created April 29, 2015 07:39
Generate 4 digit code in Swift
// Verification code is at least for digit long
let verificationCode = String(1000+arc4random_uniform(8999))
@samuelbeek
samuelbeek / sendText.swift
Last active January 30, 2020 11:58
Send Text with MessageBird
import Foundation
import Alamofire // installation instructions for Alamofire can be found here: https://github.com/Alamofire/Alamofire
// Sends text message to phone number
func sendText(phoneNumber: String, message: String) {
let apiKey = "AccessKey YOUR_ACCES_KEY"
let originator = "YOUR_NAME"
// create a new manager instance (so you don't overwrite any other API's authorization)
var manager = Manager.sharedInstance
@samuelbeek
samuelbeek / VerticalCenteredTextView.swift
Last active January 6, 2019 23:37
Vertically aligned text in textview
class VerticalCenteredTextView: UITextView {
override init(frame: CGRect) {
super.init(frame: frame)
addContentSizeObserver()
}
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
}