Skip to content

Instantly share code, notes, and snippets.

View jozsef-vesza's full-sized avatar
🏡

József Vesza jozsef-vesza

🏡
View GitHub Profile
func someFunction(a: Int, _ b: Int) {
print(a, b)
}
someFunction(1, 2)
@jozsef-vesza
jozsef-vesza / InsertionSort.swift
Last active November 4, 2015 20:01
Int -> Generics -> CollectionType
// Original Solution - Excerpt From: Wayne Bishop. “SWIFT ALGORITHMS & DATA STRUCTURES.”
func insertionSort(var numberList: Array<Int>) -> Array<Int> {
var y, key : Int
for x in 0..<numberList.count {
key = numberList[x]
for (y = x; y > -1; y--) {
private func handleContentChange() {
let tableViewHeight = CGFloat(subViewModel.count()) * rowHeight
let contentHeight = standardPadding + segmentedControlHeight.constant + standardPadding + tableViewHeight + standardPadding + openButtonHeight.constant + standardPadding
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
self.preferredContentSize.height = contentHeight
}
import UIKit
var array = [AnyObject]()
array.append(1)
array.append(2.0)
array.append("3")
array.append([4, 5, 6])
array.append([7: "7", 8: "8"])
// prints "true"
protocol BaseRequirements {
// List common requirements here.
}
protocol AdditionalRequirements {
// Any additional reqs here.
}
struct BasicType: BaseRequirements {
// I will only do the basics.
public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject e) where T : DependencyObject
{
if (e == null) yield break;
VisualTreeHelper.GetChildren(e).Filter(child is T).Map(child => ()
{
if (children != null)
{
yield return children;
}
//
// TableViewController.swift
// TableViewExpansions
//
// Created by Vesza Jozsef on 05/05/15.
// Copyright (c) 2015 Vesza Jozsef. All rights reserved.
//
import UIKit
public class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
public enum ResultType<T> {
case Success(Box<T>)
case Error(String)
}
public class BinaryNode<T: Comparable>: Comparable {
var value: T
var left: BinaryNode<T>?
var right: BinaryNode<T>?
init(value: T) {
self.value = value
}
@jozsef-vesza
jozsef-vesza / gist:5f1784dfd4fadbe826b2
Last active August 29, 2015 14:07
Map extension for Dictionaries in Swift
extension Dictionary {
    func map<U> (transform: Value -> U) -> Dictionary<Key, U> {
        var result = Dictionary<Key, U>()
        for (key, value) in self {
            result[key] = transform(value)
        }
        
        return result
 }