Skip to content

Instantly share code, notes, and snippets.

View comfly's full-sized avatar
:electron:

Dmitry Zakharov comfly

:electron:
  • Yandex
  • St. Petersburg
View GitHub Profile
@comfly
comfly / symbolicate.sh
Created June 27, 2016 11:18
Crash symbolication
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash -o symbolicated.crash unsymbolicated.crash
@comfly
comfly / rle.hs
Created June 8, 2016 21:04
Run length encoding
module Main where
import Data.Foldable
rle = (concatMap (\(sym, num) -> sym:show num)) . foldr' collect []
where collect s [] = [(s, 1)]
collect s all@((sym, num):others)
| sym == s = (sym, num + 1):others
| otherwise = (s, 1):all
@comfly
comfly / ProveBST.hs
Created June 7, 2016 22:15
BST Prover
module Main where
data Tree a = Leaf | Node a (Tree a) (Tree a)
isBST :: Tree Double -> Bool
isBST = fst . isBST'
where isBST' Leaf = (True, Nothing)
isBST' (Node n left right) =
let (l, lminmax) = isBST' left
~(r, rminmax) = isBST' right
import Foundation
infix operator <| { associativity right precedence 95 }
func <|<A, R>(@noescape f: A -> R, a: A) -> R {
return f(a)
}
func <|<A, B, R>(@noescape f: (A, B) -> R, a: (A, B)) -> R {
return f(a.0, a.1)
}
func synchronized(object: AnyObject, @noescape closure: () -> Void) {
objc_sync_enter(object)
closure()
objc_sync_exit(object)
}
protocol Lock {
func lock() throws
func unlock()
}
protocol Atomic {
associatedtype Protected
associatedtype Primitive: Lock
var lock: Primitive { get }
let queue = dispatch_queue_create("QUEUE", DISPATCH_QUEUE_CONCURRENT)
var holder: Int = 10
func readSafe() -> Int {
var read: Int!
dispatch_sync(queue) {
read = holder
}
return read
public final class SpinLock {
private var lock: OSSpinLock = OS_SPINLOCK_INIT
public func locked<A>(@noescape f: () throws -> A) rethrows -> A {
OSSpinLockLock(&lock)
defer { OSSpinLockUnlock(&lock) }
return try f()
}
}
@comfly
comfly / Summands.hs
Last active June 8, 2016 21:07
All summands combinations
summands 0 = []
summands n = [n]:concat [summandsOfTwo k (n - k) | k <- [1..n `quot` 2]]
where summandsOfTwo l r =
let le = map (r:) (summands l)
re = map (l:) (summands r)
in if l == r then le else le ++ re
extern NSManagedObjectContext *GetContext(void);
@interface TableViewController () <NSFetchedResultsControllerDelegate>
@property (nonatomic) NSFetchedResultsController *controller;
@end
@implementation TableViewController