Skip to content

Instantly share code, notes, and snippets.

View vukcevich's full-sized avatar

Marijan Vukcevich vukcevich

  • East Side Interactive, LLC
  • Las Vegas, Nevada
View GitHub Profile
@vukcevich
vukcevich / IntExtensions.swift
Created December 22, 2016 05:13 — forked from tanner0101/IntExtensions.swift
Convert an arbitrary length byte array into a Swift Int
/**
IntExtensions.swift
Convert an arbitrary length byte array into a Swift Int
<https://gist.github.com/tannernelson/e720877bf7700138eb99>
*/
extension Int {
static func fromByteArray(bytes: [UInt8]) -> Int {
// Returns `URL?`
public enum SocketEndPoint: String {
case eventSocket = "http://nowhere.com/events"
case liveSocket = "http://nowhere.com/live"
public var url: URL? {
return URL(string: self.rawValue)
}
}
@vukcevich
vukcevich / EnvoyMatrixCountElementsAroundBlock
Created January 19, 2017 22:42 — forked from dautermann/EnvoyMatrixCountElementsAroundBlock
Write a Swift playground that takes an n x n grid of integers. Each integer can be either 1 or 0. The playground then outputs an n x n grid where each block indicates the number of 1's around that block.
// Copyright © 2016 Envoy. All rights reserved.
/*
Write a Swift playground that takes an n x n grid of integers. Each integer can be either 1 or 0.
The playground then outputs an n x n grid where each block indicates the number of 1's around that block, (excluding the block itself) . For Block 0 on row 0, surrounding blocks are (0,1) (1,0) and (1,1). Similary for block (1,1) all the blocks around it are to be counted as surrounding blocks.
Requirements:
@vukcevich
vukcevich / uiimage_check.sh
Created February 1, 2017 16:30 — forked from vdugnist/uiimage_check.sh
Check if UIImage exists in assets
#!/bin/bash
function show_code {
ERROR_LOCATION=$(grep -Ron "\[UIImage imageNamed:\s*@\"$1\"\s*\]" $PROJECT_NAME)
if [[ -z $ERROR_LOCATION ]]; then
ERROR_LOCATION=$(grep -Ron "UIImage(named\:\s*\"$1\"\s*)" $PROJECT_NAME)
fi
ERROR_LOCATION=$(echo $ERROR_LOCATION | cut -d ':' -f 1,2)
echo "$ERROR_LOCATION: error: Missing imageset with name $1"
}
@vukcevich
vukcevich / migrator.rb
Created February 28, 2017 00:02 — forked from davidahouse/migrator.rb
Run the Swift 3 migrator for a project manually from the command line rather than letting Xcode do it
require 'find'
require 'pp'
swift_file_paths = []
Find.find('./') do |path|
if path =~ /.*\.swift$/ and !path.start_with? "./Carthage"
swift_file_paths << path
cmd = "xcrun swift-update -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -target arm64-apple-ios9 #{path} > convert.swift"
system cmd
@vukcevich
vukcevich / for_in_Sequnce.playground
Last active August 15, 2017 15:00
Find sequence of integers in Array of integers - Swift 3
//: Playground - noun: a place where people can play
import UIKit
//Coding Test - Envoy --- Swift 3
//Find sequence in integers in an array of integers
//input: 5,6,7,8
//output: "5-8"
//input: 2,5,6,7,8,10,14,17,18,25
@vukcevich
vukcevich / SampleGrid.playground
Last active August 15, 2017 14:59
Swift playground that takes an n x n grid of integers...
/*
Coding Test -- Envoy:
Write a Swift playground that takes an n x n grid of integers. Each integer can be either 1 or 0.
The playground then outputs an n x n grid where each block indicates the number of 1's around that block, (excluding the block itself) . For Block 0 on row 0, surrounding blocks are (0,1) (1,0) and (1,1). Similary for block (1,1) all the blocks around it are to be counted as surrounding blocks.
Requirements:
@vukcevich
vukcevich / Find_Duplicates_in_Array.playground
Created August 15, 2017 14:55
Find duplicates in array - Swift 3
import UIKit
let ar = [2, 3, 4, 23, 4, 5, 13, 45, 23, 12, 13, 34, 45, 67, 23, 78]
//check how many times O(n) crazy
let duplicates = Array(
Set(
ar.filter({ (i: Int) in
ar.filter({
$0 == i
@vukcevich
vukcevich / ObservableSwift.playground
Created August 15, 2017 16:07
Observable protocol to subscribe and unsubscribe to updates
protocol ObservableProtocol {
associatedtype T
var value: T { get set }
func subscibe(observer: AnyObject, block: @escaping (_ newValue: T, _ oldValue: T) ->())
func unsubscribe(observer: AnyObject)
}
public final class Observable<T>: ObservableProtocol {
typealias ObserverBlock = (_ newValue: T, _ oldValue: T) -> ()
@vukcevich
vukcevich / RemoveDuplicateObjects.playground
Last active August 15, 2017 16:37
Remove duplicate objects in an array - Hashable, CustomStringConvertible
//Reference:
//https://stackoverflow.com/questions/34709066/remove-duplicate-objects-in-an-array
//https://medium.com/@YogevSitton/use-auto-describing-objects-with-customstringconvertible-49528b55f446
func uniq<S: Sequence, E: Hashable>(_ source: S) -> [E] where E == S.Iterator.Element {
var seen = Set<E>()
return source.filter { seen.update(with: $0) == nil }
}