Skip to content

Instantly share code, notes, and snippets.

View ixqbar's full-sized avatar
💭
I may be slow to respond.

Well ixqbar

💭
I may be slow to respond.
View GitHub Profile
@ixqbar
ixqbar / gist:66d229317f8cceddf74f
Last active August 29, 2015 14:18
php自定义异常类
zend_class_entry *wcx_exception_ce;
PHP_WCX_API zend_class_entry *wcx_get_exception_base(int root TSRMLS_DC) {
#if HAVE_SPL
if (!root) {
if (!spl_ce_RuntimeException) {
zend_class_entry **pce;
if (zend_hash_find(CG(class_table), "runtimeexception", sizeof("RuntimeException"), (void **) &pce) == SUCCESS) {
spl_ce_RuntimeException = *pce;
return *pce;
@ixqbar
ixqbar / gist:d95a876c0e5cf4cea69c
Created April 2, 2015 02:02
php扩展-字符串组装
char *host=NULL;
int host_len;
host_len = spprintf(&host, 0, "%s:%d", redis_sock->host, redis_sock->port);
@ixqbar
ixqbar / gist:0259a6bfe28c83aa9829
Created May 8, 2015 07:20
krmt-geo代码分析-排序
//https://github.com/mattsta/krmt
static int sort_gp_asc(const void *a, const void *b) {
const struct geojsonPoint *gpa = a, *gpb = b;
/* We can't do adist - bdist because they are doubles and
* the comparator returns an int. */
if (gpa->dist > gpb->dist)
return 1;
else if (gpa->dist == gpb->dist)
return 0;
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
#define D_R (M_PI / 180.0)
const double EARTH_RADIUS_IN_METERS = 6372797.560856;
@ixqbar
ixqbar / gist:69206bc9892e71ae2530
Created June 3, 2015 07:10
Swift synchronous request
class Request : NSObject {
func send(url: String, f: (String)-> ()) {
var request = NSURLRequest(URL: NSURL(string: url)!)
var response: NSURLResponse?
var error: NSErrorPointer = nil
var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: error)
var reply = NSString(data: data!, encoding: NSUTF8StringEncoding)
f(reply as! String)
}
}
class SwiftSingleton {
class var shared: SwiftSingleton {
return Inner.instance
}
struct Inner {
static let instance: SwiftSingleton = SwiftSingleton()
}
}
@ixqbar
ixqbar / gist:7b7263d9c749be7bb903
Created June 9, 2015 04:13
ios之contentOffset
The point at which the origin of the content view is offset from the origin of the scroll view
content view origin相对于scroll view origin的偏移
可以把content view理解为设备屏幕,scroll view origin是要显示的内容
显示内容下拉时content view origin 在 scroll view origin 上面, 此时contentOffset.y < 0, 这就是为什么下拉scroll view时contentOffset.y < 0
func randomInRange(range: Range<Int>) -> Int {
let count = UInt32(range.endIndex - range.startIndex)
return Int(arc4random_uniform(count)) + range.startIndex
}
for _ in 0...10 {
print(randomInRange(1...20))
}
// TargetName-Bridging-Header.h
#import <CommonCrypto/CommonCrypto.h>
// StringMD5.swift
extension String {
var MD5: String {
let cString = self.cStringUsingEncoding(NSUTF8StringEncoding)
let length = CUnsignedInt(
self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)
)
@ixqbar
ixqbar / gist:3a5c1e46bd09112acda1
Created June 19, 2015 02:56
check log errors
#!/bin/sh
#
#
if [ "$#" -ge 1 ]; then
LOG_DIR=$1
else
LOG_DIR=/data/wwwroot/game_server/logs
fi