Skip to content

Instantly share code, notes, and snippets.

@lldong
lldong / church.swift
Created January 5, 2015 05:57
Church Numerals in Swift
// Playground - noun: a place where people can play
import UIKit
func zero<N>(succ: N -> N) -> N -> N {
return { (z: N) in
return z
}
}
// Playground - noun: a place where people can play
import UIKit
// MARK: Utilities
func take<T>(slice: Slice<T>, num: Int) -> Slice<T> {
let n = (num < slice.count) ? num : slice.endIndex
return slice[0..<n]
}
@lldong
lldong / valgrind
Created July 28, 2014 16:49
Install valgrind on 10.9
# Make sure I have autoconf and automake both installed.
sudo port -v install automake
sudo port -v install autoconf
# Grab Frederic's patched valgrind on his "homebrew" branch
cd ~/work # My usual project directory
git clone https://github.com/fredericgermain/valgrind/ -b homebrew
cd valgrind
# Because he placed VEX as a git submodule, we have to make sure we clone it too
git submodule init
git submodule update
@lldong
lldong / objc-debug-env
Last active August 29, 2015 14:00
Objective-C Debug Environment Variables
OBJC_PRINT_IMAGES "log image and library names as they are loaded"
OBJC_PRINT_LOAD_METHODS "log calls to class and category +load methods"
OBJC_PRINT_INITIALIZE_METHODS "log calls to class +initialize methods"
OBJC_PRINT_RESOLVED_METHODS "log methods created by +resolveClassMethod: and +resolveInstanceMethod:"
OBJC_PRINT_CLASS_SETUP "log progress of class and category setup"
OBJC_PRINT_PROTOCOL_SETUP "log progress of protocol setup"
OBJC_PRINT_IVAR_SETUP "log processing of non-fragile ivars"
OBJC_PRINT_VTABLE_SETUP "log processing of class vtables"
OBJC_PRINT_VTABLE_IMAGES "print vtable images showing overridden methods"
OBJC_PRINT_CACHE_SETUP "log processing of method caches"
@lldong
lldong / convert.rb
Created April 4, 2014 11:25
Convert NSDictionary/NSArray to literal syntax
#!/usr/bin/env ruby
# encoding: utf-8
require 'strscan'
def construct_dict_literal(pairs, mutable = false)
output = pairs.each_slice(2).reduce('@{') {
|expr, pair|
value, key = *pair
expr << key.strip << ': '
@lldong
lldong / ruby-gems-for-xcoder.md
Last active March 8, 2020 10:20
Ruby Gems for Cocoa Developer
  • liftoff Xcode 工程配置工具
  • crafter Xcode 工程配置工具,使用 Ruby 进行配置,比 liftoff 灵活
  • xcpretty xcodebuild 输出格式化工具
  • xclisten 测试用例自动执行工具
  • bwoken UIAutomation 脚本执行工具
require 'ampex'
def qs(xs)
return xs if xs.length <= 1
p = xs.length / 2
qs(xs.select &X < xs[p]) +
qs(xs.select &X == xs[p]) +
qs(xs.select &X > xs[p])
end
@lldong
lldong / 18.rb
Created December 1, 2012 18:41
Project Euler - 18
input = """
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33