Skip to content

Instantly share code, notes, and snippets.

View onmyway133's full-sized avatar
😇
What you don't know is what you haven't learned

Khoa onmyway133

😇
What you don't know is what you haven't learned
View GitHub Profile
@onmyway133
onmyway133 / shuffle.swift
Created November 27, 2015 02:04 — forked from natecook1000/shuffle.swift
Swift 2.0 shuffle / shuffleInPlace
// (c) 2015 Nate Cook, licensed under the MIT license
//
// Fisher-Yates shuffle as protocol extensions
extension CollectionType {
/// Return a copy of `self` with its elements shuffled
func shuffle() -> [Generator.Element] {
var list = Array(self)
list.shuffleInPlace()
return list
import Foundation
protocol Serializable {
static func deserializeInto(bytePtr: UnsafeMutablePointer<UInt8>, bytes: ArraySlice<UInt8>) -> ArraySlice<UInt8>
}
extension Serializable {
typealias WorkaroundSelf = Self
@onmyway133
onmyway133 / json.swift
Created December 7, 2015 03:46 — forked from chriseidhof/json.swift
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
@onmyway133
onmyway133 / exercise.md
Created December 12, 2015 04:56 — forked from wo0dyn/exercise.md
Find a 9 letter string of characters that contains only letters from “acdegilmnoprstuw” such that the hash(the_string) is “910897038977002”.

Find a 9 letter string of characters that contains only letters from

acdegilmnoprstuw

such that the hash(the_string) is

910897038977002
@onmyway133
onmyway133 / instruction.md
Created December 12, 2015 16:47 — forked from srph/instruction.md
Find a 9 letter string of characters that contains only letters from [acdegilmnoprstuw] such that the hash(the_string) is 910897038977002; If hash is defined with the given pseudo-code

Find a 9 letter string of characters that contains only letters from

acdegilmnoprstuw

such that the hash(the_string) is

910897038977002

if hash is defined by the following pseudo-code:

@onmyway133
onmyway133 / swift_swizzle
Created December 16, 2015 16:44 — forked from ivanbruel/swift_swizzle
Swift Class Method Swizzle
//
// LHNetworking+Endpoint.swift
// magellan
//
// Created by Ivan Bruel on 09/04/15.
// Copyright (c) 2015 Passworks S.A. All rights reserved.
//
import Foundation
import Lighthouse
@onmyway133
onmyway133 / Multiple Storyboard Usage.txt
Created December 17, 2015 02:05 — forked from aryaxt/Multiple Storyboard Usage.txt
Multiple Storyboard Usage
@interface UIStoryboard (Additions)
- (id __nullable)tryInstantiateViewControllerWithIdentifier:(NSString * __nonnull)identifier;
@end
@implementation UIStoryboard (Additions)
- (id)tryInstantiateViewControllerWithIdentifier:(NSString *)identifier {
@try {
return [self instantiateViewControllerWithIdentifier:identifier];
}
@catch (NSException *exception) {
@onmyway133
onmyway133 / ADVPlaceholderViewController.h
Created December 17, 2015 02:17 — forked from advantis/ADVPlaceholderViewController.h
View controller supporting nested storyboard loading
//
// Copyright © 2013 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface ADVPlaceholderViewController : UIViewController
@end
enum StringPaddingStyle {case Left, Right}
func padStringToLength(
sourceString: String,
destinationCount: Int,
paddingStyle: StringPaddingStyle = .Left,
paddingCharacter: Character = " "
) -> String {
let padCount = destinationCount - sourceString.characters.count,
padString = String(count: padCount, repeatedValue: paddingCharacter)