Skip to content

Instantly share code, notes, and snippets.

Avatar
:electron:

Dmitry Zakharov comfly

:electron:
View GitHub Profile
@comfly
comfly / symbolicate.sh
Created Jun 27, 2016
Crash symbolication
View symbolicate.sh
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 Jun 8, 2016
Run length encoding
View rle.hs
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
View ProveBST.hs
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
View shit.swift
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)
}
View synchronized.swift
func synchronized(object: AnyObject, @noescape closure: () -> Void) {
objc_sync_enter(object)
closure()
objc_sync_exit(object)
}
View Atomic.swift
protocol Lock {
func lock() throws
func unlock()
}
protocol Atomic {
associatedtype Protected
associatedtype Primitive: Lock
var lock: Primitive { get }
View Using queues.swift
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
View SpinLock.swift
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 Jun 8, 2016
All summands combinations
View Summands.hs
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
View FRC for Dependent entities.m
extern NSManagedObjectContext *GetContext(void);
@interface TableViewController () <NSFetchedResultsControllerDelegate>
@property (nonatomic) NSFetchedResultsController *controller;
@end
@implementation TableViewController
You can’t perform that action at this time.