Skip to content

Instantly share code, notes, and snippets.

View cfilipov's full-sized avatar
💭
Yak shaving

Cristian Filipov cfilipov

💭
Yak shaving
View GitHub Profile
@cfilipov
cfilipov / WakeHelper.m
Created October 13, 2015 03:39
Wake iOS application via SpringBoardServices
// Inspired [copied] from: http://pastie.org/pastes/4855500#7-8,11-13
#import "WakeHelper.h"
#import <mach/mach.h>
#import <dlfcn.h>
#define SB_SERVICES_PATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
typedef mach_port_t sig_SBSSpringBoardServerPort();
typedef mach_error_t sig_SBSetApplicationNextWakeDate(mach_port_t sbsPort, double wakeTime, int flags);
@cfilipov
cfilipov / GraphTraversable.swift
Last active November 10, 2015 22:10
A Protocol-Oriented Approach for Graph Traversal in Swift
import Foundation
protocol GraphTraversable {
typealias GraphType : Hashable
var nodes: [GraphType] { get }
}
enum Status {
case Continue
case Stop
@cfilipov
cfilipov / InsertInterval.md
Last active November 20, 2015 17:19
Insert Interval Problem in Swift

Insert Interval Problem in Swift

I was working on this problem and wondered how it would look in Swift.

Given an array of non-overlapping and sorted intervals, insert a new interval into the array and merge with existing intervals if necessary.

For example, given intervals:

  [(1,3), (6,9)]

>

Just playing around with ASCII/Unicode art

 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
▕          ░|  ░░░░|  ░|  ░|          ░|          ░|         ░|        ░░▏
▕░░░|  ░░░░░|  ░░░░|  ░|  ░░░░░|  ░░░░░░░░░|  ░░░░░|  ░░░░░░░░|  |░░░░  ░▏
▕░░░|  ░░░░░|  ░░░░|  ░|  ░░░░░|  ░░░░░░░░░|  ░░░░░|  ░░░░░░░░|  |░░░░░  ▏
▕░░░|  ░░░░░|  ░░ ░|  ░|  ░░░░░|  ░░░░░░░░░|  ░░░░░|       ░░░|         ░▏
▕▒▒▒|  ▒▒▒▒▒|  ▒|  |  ▒|  ▒▒▒▒▒|  ▒▒▒▒▒▒▒▒▒|  ▒▒▒▒▒|  ▒▒▒▒▒▒▒▒|  ▒▒|  ▒▒▒▏
▕▓▓▓|  ▓▓▓▓▓|    ▓    ▓|  ▓▓▓▓▓|  ▓▓▓▓▓▓▓▓▓|  ▓▓▓▓▓|  ▓▓▓▓▓▓▓▓|  ▓▓▓|  ▓▓▏
▕███| █████| ████| █| █████| █████████| █████| █| ████| █▏ 
@cfilipov
cfilipov / IntCollectionType.swift
Created November 24, 2015 06:40
Abusing Swift's CollectionType protocol with Int indexing
import Darwin
infix operator ** { associativity left precedence 151 }
func **(x: Int, n: Int) -> Int {
if n == 0 { return 1 }
var p = abs(x)
for _ in 1..<n {
p *= abs(x)
}
@cfilipov
cfilipov / PhoneWords.swift
Created November 24, 2015 22:42
Generating Phone Words in Swift
/*:
## Phone Words
Generate a collection of words that can be represented by a given phone number. If a phone number contains the digits `1` or `0` then split up the phone number and find the words for each of the substrings as long as each substring has more than one digit. Non-keypad characters can be ignored. Optionally, filter out words so that only dictionary words are present in the result.
╔═════╦═════╦═════╗
║ 1 ║ 2 ║ 3 ║
║ ║ abc ║ def ║
╠═════╬═════╬═════╣
║ 4 ║ 5 ║ 6 ║
/*:
## Phone Words
Generate a collection of words that can be represented by a given phone number. If a phone number contains the digits `1` or `0` then split up the phone number and find the words for each of the substrings as long as each substring has more than one digit. Non-keypad characters can be ignored. Optionally, filter out words so that only dictionary words are present in the result.
╔═════╦═════╦═════╗
║ 1 ║ 2 ║ 3 ║
║ ║ abc ║ def ║
╠═════╬═════╬═════╣
║ 4 ║ 5 ║ 6 ║
@cfilipov
cfilipov / StringsAndUnicode.swift
Created December 2, 2015 21:36
Strings & Unicode in Swift
/*:
# Strings and Unicode
*/
import Foundation
/*: Some things we can't do */
//let ❤ = "❤" // error: Expected a pattern
//let ☆ = "☆" // error: Expected a pattern
//: Playground - noun: a place where people can play
import Cocoa
protocol Feed: Equatable {
var url: String {get}
}
func ==<F: Feed>(lhs: F, rhs: F) -> Bool {
return lhs.url == rhs.url
// In the previous version https://gist.github.com/cfilipov/c9929dcb2cffcbf52a22, LocalFeed could only contain one type of Feed, this one allows it to store any feed type.
import Cocoa
protocol Feed: Equatable {
var url: String {get}
}
func ==<F: Feed>(lhs: F, rhs: F) -> Bool {
return lhs.url == rhs.url