Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
# Remove Book
movl L_OBJC_SELECTOR_REFERENCES_13-L1$pb(%ebx), %eax
movl %eax, -36(%ebp) ## 4-byte Spill
movl %eax, 4(%esp)
movl %edi, (%esp)
movl $0, 8(%esp)
calll L_objc_msgSend$stub
@onevcat
onevcat / thread_patch.c
Created May 22, 2014 04:30
Workaround for Unity game slowing in iPhone4 + 7.1
//Workaround for Unity game slowing in iPhone4 + 7.1
//Write in main.mm
#include <pthread.h>
#include <dlfcn.h>
typedef int (*pthread_create_f)(pthread_t * __restrict, const pthread_attr_t * __restrict, void *(*)(void *), void * __restrict);
static pthread_create_f real_create = NULL;
extern "C" int pthread_create(pthread_t * __restrict thread, const pthread_attr_t * __restrict attr, void *(*start)(void *), void * __restrict arg)
@onevcat
onevcat / StringIndex.swift
Created July 4, 2014 09:12
Add index access to Swift String 通过 index 下标来取得 string 中的字符
extension String
{
subscript(integerIndex: Int) -> Character
{
let index = advance(startIndex, integerIndex)
return self[index]
}
subscript(integerRange: Range<Int>) -> String
{
@onevcat
onevcat / MonoBehaviourInvokeExtension.cs
Created July 7, 2014 08:28
MonoBehaviourInvokeExtension
using UnityEngine;
public static class MonoBehaviorInvokeMethodExtension {
public static void Invoke(this MonoBehaviour m, System.Action method, float time) {
string methodName = method.Method.Name;
m.Invoke(methodName, time);
}
}
func Test<T>(input : T, condition : T -> Bool = {t in return true}) -> T {
if condition(input) {
return input
} else {
return input
}
}
let a = Test(1)

Keybase proof

I hereby claim:

  • I am onevcat on github.
  • I am onevcat (https://keybase.io/onevcat) on keybase.
  • I have a public key whose fingerprint is A151 8725 F27D B82C 0655 EE81 E228 6724 C063 4366

To claim this, I am signing this object:

@onevcat
onevcat / Task.swift
Created August 21, 2014 05:32
Execute a task in main queue
//
// Task.swift
// fasfa
//
// Created by 王 巍 on 14-8-21.
// Copyright (c) 2014年 OneV's Den. All rights reserved.
//
import Foundation
typealias Task = (cancel : Bool) -> ()
@onevcat
onevcat / notification.m
Created January 8, 2015 02:25
Post notification in main thread
dispatch_async(dispatch_get_main_queue(),^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ImageRetrieved"
object:nil
userInfo:imageDict];
});
@onevcat
onevcat / thread-safe.swift
Created January 9, 2015 03:51
Thread safe array access with dispatch barrier
private let concurrentPhotoQueue = dispatch_queue_create("com.onevcat.photoQueue", DISPATCH_QUEUE_CONCURRENT)
private var _photos: [Photo] = []
var photos: [Photo] {
var photosCopy : [Photo]!
dispatch_sync(concurrentPhotoQueue) {
photosCopy = self._photos
}
return photosCopy
}
syscall::read:entry
/execname != "iTerm"/
{
printf ("%s called read, asking for %d bytes\n", execname, arg2);
}
syscall::open*:entry
/execname == "backupd"/
{
printf ("%s", copyinstr(arg0));