Skip to content

Instantly share code, notes, and snippets.

@pyanfield
pyanfield / PSPDFUIKitMainThreadGuard.m
Created February 7, 2017 03:50 — forked from steipete/PSPDFUIKitMainThreadGuard.m
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@pyanfield
pyanfield / PSPDFThreadSafeMutableDictionary.m
Created February 7, 2017 03:37 — forked from steipete/PSPDFThreadSafeMutableDictionary.m
Simple implementation of a thread safe mutable dictionary. In most cases, you want NSCache instead, but it can be useful in situations where you want to manually control what is evicted from the cache in low memory situations. **Warning:** I only use this for setting/getting keys. Enumeration is not thread safe here and will still throw exceptio…
//
// PSPDFThreadSafeMutableDictionary.m
//
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@pyanfield
pyanfield / main.go
Last active November 11, 2019 00:47
query mysql db with golang
package main
import (
"database/sql"
"fmt"
"runtime"
"strconv"
"time"
_ "github.com/go-sql-driver/mysql"
@pyanfield
pyanfield / springer-free-maths-books.md
Created December 29, 2015 02:04 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links
@pyanfield
pyanfield / introrx.md
Created November 20, 2015 06:45 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
#import <Foundation/Foundation.h>
#import "sqlite3.h"
typedef int64_t timestamp;
NSUInteger randomNumberInRange(NSUInteger start, NSUInteger end);
// Create a sample date using the ISO-8601 format.
// 2013-04-23T16:29:05Z
NSString* generateSampleDate();
@pyanfield
pyanfield / gist:ec0457a77682975c9da2
Created July 22, 2014 02:42
proxy plugin for chrome
很好用的 chrome 代理插件
https://chrome.google.com/webstore/detail/proxy-switchysharp/dpplabbmogkhghncfbfdeeokoefdjegm
@pyanfield
pyanfield / gist:f7b29489eb8c9c9f4092
Created June 17, 2014 03:58
Constants in Objective-C

定义一个全局的常量以便在 Objective-C 的项目中使用。可以通过创建一个头文件,比如 Constants.h,然后在头文件声明如下:

FOUNDATION_EXPORT NSString *const MyFirstConstant;
FOUNDATION_EXPORT NSString *const MySecondConstant;

然后在你的执行文件中 Constants.m 中:

NSString *const MyFirstConstant = @"FirstConstant";
NSString *const MySecondConstant = @"SecondConstant";
@pyanfield
pyanfield / spf13 to support golang.sh
Last active August 29, 2015 14:01
install spf13 to support golang
sh <(curl https://j.mp/spf13-vim3 -L)
echo "let g:spf13_bundle_groups=['general', 'neocomplete', 'programming', 'ruby', 'python', 'go', 'javascript', 'html', 'misc', 'writing' ]" >> ~/.vimrc.before.local
vim +BundleInstall! +qall
使用 tagbar 插件:
-- 首先安装:brew install ctags
-- go get -u github.com/jstemmer/gotags
-- gotags 安装完之后,需要将编译后的 gotags 路径加入到 PATH 路径下,比如在 $GOPATH/bin 下
-- 加入如下内容到 .vimrc.before.local 中:
@pyanfield
pyanfield / test kv db.go
Created March 26, 2014 06:20
test cznic/kv
package main
import (
"fmt"
"github.com/cznic/kv"
"io"
"os"
)
func getBuf(n int) []byte {