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
/*:
## 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 / 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 β•‘
@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)
}

Just playing around with ASCII/Unicode art

 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
β–•          β–‘|  β–‘β–‘β–‘β–‘|  β–‘|  β–‘|          β–‘|          β–‘|         β–‘|        ░░▏
β–•β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘|  β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|  |β–‘β–‘β–‘β–‘  ░▏
β–•β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘|  β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|  |β–‘β–‘β–‘β–‘β–‘  ▏
β–•β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘ β–‘|  β–‘|  β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|  β–‘β–‘β–‘β–‘β–‘|       β–‘β–‘β–‘|         ░▏
β–•β–’β–’β–’|  β–’β–’β–’β–’β–’|  β–’|  |  β–’|  β–’β–’β–’β–’β–’|  β–’β–’β–’β–’β–’β–’β–’β–’β–’|  β–’β–’β–’β–’β–’|  β–’β–’β–’β–’β–’β–’β–’β–’|  β–’β–’|  ▒▒▒▏
β–•β–“β–“β–“|  β–“β–“β–“β–“β–“|    β–“    β–“|  β–“β–“β–“β–“β–“|  β–“β–“β–“β–“β–“β–“β–“β–“β–“|  β–“β–“β–“β–“β–“|  β–“β–“β–“β–“β–“β–“β–“β–“|  β–“β–“β–“|  ▓▓▏
β–•β–ˆβ–ˆβ–ˆ| β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| β–ˆβ–ˆβ–ˆβ–ˆ| β–ˆ| β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| β–ˆ| β–ˆβ–ˆβ–ˆβ–ˆ| β–ˆβ– 
@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)]

>

@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 / 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);