Skip to content

Instantly share code, notes, and snippets.

View sger's full-sized avatar

Spiros Gerokostas sger

View GitHub Profile
@sger
sger / SessionManager.swift
Last active September 1, 2015 18:28
Simple AFHTTPSessionManager subclass
class SessionManager: AFHTTPSessionManager {
typealias SuccessCompletionBlock = (session:NSURLSessionDataTask!, responseObject:AnyObject!) -> Void
typealias ErrorCompletionBlock = (session:NSURLSessionDataTask!, error:NSError!) -> Void
class var sharedInstance: SessionManager
{
struct Static
{
static var onceToken: dispatch_once_t = 0
@sger
sger / duplicates
Created May 11, 2015 16:29
Remove duplicates from an Array with Swift and generics
func uniq<S : SequenceType, T : Hashable where S.Generator.Element == T>(source: S) -> [T] {
var buffer = [T]()
var added = Set<T>()
for elem in source {
if !added.contains(elem) {
buffer.append(elem)
added.insert(elem)
}
}
return buffer
@sger
sger / MyClass.swift
Created May 1, 2015 17:21
MyClass.swift
class MyClass: NSObject {
// MARK: Singleton
class var sharedInstance : MyClass {
struct Static {
static var onceToken:dispatch_once_t = 0
static var instance:MyClass? = nil
}
dispatch_once(&Static.onceToken) {
Static.instance = MyClass()
}
@sger
sger / hostname
Created October 19, 2014 14:40
set hostname on os x
sudo scutil --set HostName name
sudo scutil --set ComputerName name
scutil --get ComputerName
scutil --get HostName
@sger
sger / Optional.swift
Created September 22, 2014 18:02
Simple optional extension
extension Optional {
public var hasValue: Bool {
return (self != nil)
}
}
@sger
sger / Thinline.swift
Created September 2, 2014 19:41
How to remove navigation bar thin bottom line in Swift (Xcode 6 beta 7)
for parent in self.navigationController!.navigationBar.subviews {
for childView in parent.subviews {
if(childView is UIImageView) {
childView.removeFromSuperview()
}
}
}
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "fishhook.h"
int slient_fprintf(FILE * restrict stream, const char * restrict format, ...)
{
if (strncmp(format, "AssertMacros:", 13) == 0)
{