Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
func waitUntil(_ done: @escaping (@escaping () -> Void) -> Void) {
var completed: UInt32 = 0
DispatchQueue.main.async {
done { OSAtomicOr32Barrier(1, &completed) }
}
while completed == 0 {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.01))
}
}
struct DecodableArray<T: Decodable>: Decodable {
let value: [T]
static func parse(data: Data) -> DecodableArray<T> {
var value = [T]()
for subData in data {
let result = T.parse(data: data)
value.append(result)
}
return DecodableArray(value: value)
}
Worker information
hostname: worker-jupiter-brain:d6e345e5-61b4-457e-ba9b-6e984ddcaeb1
version: v2.3.1-14-g9243e3b https://github.com/travis-ci/worker/tree/9243e3b08741eb25a197b267e5397812cc14baeb
instance: 10f6c9c4-4f12-49be-943c-a914587d700a:travis-ci-osx10.11-xcode7.3-1467942550
startup: 1m32.27745094s
Build system information
Build language: objective-c
Build group: stable
Build dist: osx
Build id: 152912681
@onevcat
onevcat / iTerm.applescript
Created June 27, 2016 06:41
Fix Tower's "Open in Terminal" command with iTerm 3. Replace the content of /Applications/Tower.app/Contents/Resources/iTerm.applescript to this:
on execute(filename)
set command_string to quoted form of filename
tell application "System Events"
do shell script "Open -a iTerm " & command_string
end tell
end execute
import UIKit
private enum ListNode<Element> {
case End
indirect case Node(Element, next: ListNode<Element>)
func cons(x: Element) -> ListNode<Element> {
// 每次 cons 调用将把 tag 加一
return .Node(x, next: self)
}
}
@onevcat
onevcat / anygenerator_leak.swift.swift
Created April 6, 2016 04:03
AnyGenerator Leak?
let count = 3
var current = 0
let g = AnyGenerator<Int>(body: {
if current < count {
current += 1
return current - 1
} else {
return nil
}
})
@onevcat
onevcat / Jitouch-Restarter
Created February 15, 2016 04:14
This gist kill Jitouch and then restart it. It solves problems when using Jitouch with Magic Trackpad 2
pkill -f "Jitouch"
sleep 5
nohup ~/Library/PreferencePanes/Jitouch.prefPane/Contents/Resources/Jitouch.app/Contents/MacOS/Jitouch > /dev/null 2>&1 &
public func tr_pushViewController<T where T: TRTransition, T.Content == UIViewController>(viewController: T, method: TRPushMethod, statusBarStyle: TRStatusBarStyle = .Default, completion: (() -> Void)? = nil) {
guard let vc = viewController as? T.Content else {
fatalError()
}
let transitionDelegate = TRNavgationTransitionDelegate(method: method, status: .Push, gestureFor: vc)
transitionDelegate.completion = completion
viewController.tr_transition = transitionDelegate
delegate = transitionDelegate
transitionDelegate.previousStatusBarStyle = TRStatusBarStyle.CurrentlyTRStatusBarStyle()
transitionDelegate.currentStatusBarStyle = statusBarStyle
// The plain image data is stored in `bitmap`
NSInteger samplesPerPixel = [bitmap samplesPerPixel];
int rowLength = 0;
int unpackAlign = 0;
// Save original value temporary
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowLength);
glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackAlign);
// Calculate and store necessary values for texture