Skip to content

Instantly share code, notes, and snippets.

@zhaoyk
zhaoyk / SwipeArea.qml
Created January 11, 2016 01:01 — forked from kovrov/SwipeArea.qml
Swipe
/* This code was written by Sergejs Kovrovs and has been placed in the public domain. */
import QtQuick 2.0
MouseArea {
property point origin
property bool ready: false
signal move(int x, int y)
signal swipe(string direction)
@zhaoyk
zhaoyk / sqlcipher_android_build.mk
Created February 28, 2015 09:20
build sqlcipher for android
LOCAL_PATH := $(call my-dir)
android_sqlite_cflags := -DHAVE_USLEEP=1 \
-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 -DSQLITE_THREADSAFE=1 -DNDEBUG=1 \
-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 -DSQLITE_TEMP_STORE=3 \
-DSQLITE_ENABLE_FTS3_BACKWARDS -DSQLITE_ENABLE_LOAD_EXTENSION \
-DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_RTREE \
-DSQLITE_SOUNDEX -DSQLITE_ENABLE_STAT3 -DSQLITE_ENABLE_FTS4_UNICODE61 \
-DSQLITE_THREADSAFE
# -*- coding: utf-8 -*-
import thread
import time
def real_add(a, b, cb):
def add():
print("[LOG] count add (%d + %d)...." % (a, b))
time.sleep(3)
c = a + b
@zhaoyk
zhaoyk / test.js
Last active August 29, 2015 14:04
loadData(["test</ul><img src='#' onerror='alert(1)'/><ul>test2"])
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@zhaoyk
zhaoyk / createImageWithCorner
Created March 28, 2014 06:00
生成一个带圆角的图片
/*
使用
view.layer.masksToBounds = YES; // slow
view.layer.cornerRadius = 4;
画圆角非常慢, 这个方法用来生成一张图片, 带圆角, 有背景色;
*/
+ (UIImage *)buttonBgImageWithSize:(CGSize)size color:(UIColor *)color cornerRadius:(CGFloat)cornerRadius {
// 不要用 UIGraphicsBeginImageContext(size);
// 第三个参数 0 表示 scale是屏幕的scale, 即使 2; 否则默认的是 1
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
@zhaoyk
zhaoyk / call_selector
Created March 28, 2014 02:57
call any selector, no error
// same as [obj someSelector]
SEL selector = @selector(someSelector);
IMP imp = [obj methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(obj, selector);
@zhaoyk
zhaoyk / UIFont - CTFontRef 转换
Last active March 8, 2022 11:12
UIFont 与 CTFontRef 互相转换
+ (UIFont *)uifontFromCTFontRef:(CTFontRef)ctFont {
CGFloat pointSize = CTFontGetSize(ctFont);
NSString *fontPostScriptName = (NSString *)CFBridgingRelease(CTFontCopyPostScriptName(ctFont));
UIFont *fontFromCTFont = [UIFont fontWithName:fontPostScriptName size:pointSize];
return fontFromCTFont;
}
+ (CTFontRef)ctFontRefFromUIFont:(UIFont *)font {
CTFontRef ctfont = CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL);
return CFAutorelease(ctfont);
@zhaoyk
zhaoyk / endian_test.h
Created December 23, 2013 01:19
copy from node/src/node_internals.h
enum Endianness {
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
kBigEndian
};
inline enum Endianness GetEndianness() {
// Constant-folded by the compiler.
const union {
uint8_t u8[2];
uint16_t u16;
@zhaoyk
zhaoyk / ffr.c
Created December 22, 2013 08:06 — forked from cloudwu/ffr.c
#include <stdint.h>
#include <stdlib.h>
// assert(RAND_MAX >= 0x7fff)
float
random_0_to_1() {
union {
uint32_t d;
float f;
} u;