Skip to content

Instantly share code, notes, and snippets.

@1901
1901 / UITapGestureRecognizer.m
Created April 17, 2012 08:39
Objective-c手势设置(单击双击事件)
{
GridTileItem* tileItem = something;
UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(onGridTileItemTouched:)];
singleFingerOne.numberOfTouchesRequired = 1; //手指数
singleFingerOne.numberOfTapsRequired = 1; //tap次数
singleFingerOne.delegate = self;
UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(onGridTileItemTouched:)];
@1901
1901 / sublimeText2_packageControl.py
Last active October 3, 2015 05:58
SublimeText2安装“Package Control”
# 1、打开 Sublime Text 2,按下 Control + ` 调出 Console
# 2、将以下代码粘贴进命令行中并回车
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())
# 3、重启 Sublime Text 2,如果在 Preferences -> Package Settings中见到Package Control这一项,就说明安装成功了
# Sublime Text 2 和 Sublime Text 3中Package Control安装方法及下载地址:
# https://sublime.wbond.net/installation
# Mac系统下长按重复按键
@1901
1901 / ac.html
Created April 25, 2012 03:48
使用JS+Html动态修改显示内容
<html>
<SCRIPT LANGUAGE='JavaScript'>
function addline(text, textColor) {
var newDiv = document.createElement('DIV');
newDiv.style.color = textColor;
newDiv.innerHTML = text;
document.getElementById('contentDiv').appendChild(newDiv);
window.scroll(0,window.document.body.scrollHeight);
}
@1901
1901 / block.m
Created May 25, 2012 08:27
Objective-C中block的使用
int i = 5;
int (^test1)() = ^() {
return i * i;
};
int (^test2)(int);
test2 = ^(int a) {
return a * a;
};
@1901
1901 / com.apple.mobile.installation.plist
Created October 31, 2012 09:20
iOS安装信息文件
/Private/var/mobile/Library/Caches/com.apple.mobile.installation.plist
@1901
1901 / getTickCount
Created January 5, 2013 14:55
类似于Windows下的GetTickCount函数(但得到的时间不是开机后的时间)。
#include <iostream>
#include <sys/time.h>
//#include <time.h>
long getTickCount()
{
struct timeval tv;
gettimeofday(&tv, NULL);
@1901
1901 / all_class_in_objc.c
Created January 24, 2013 11:26
Objective-C获取所有的类
int numClasses = 0;
Class * classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0 )
{
classes = malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
for (int i = 0; i < numClasses; i++)
@1901
1901 / gitconfig_colorful
Created May 10, 2013 01:56
使Git命令输出变成彩色的方法
# 参数可选(auto, ture, false)
$ git config --global color.status auto
$ git config --global color.diff auto
$ git config --global color.branch auto
$ git config --global color.interactive auto
$ git config --global color.ui auto
@1901
1901 / string_wstring.cpp
Created May 31, 2013 10:28
std::string和std::wstring之间相互转换
// 把一个wstring转化为string
std::string& to_string(std::string& dest, std::wstring const & src)
{
std::setlocale(LC_CTYPE, "");
size_t const mbs_len = wcstombs(NULL, src.c_str(), 0);
std::vector<char> tmp(mbs_len + 1);
wcstombs(&tmp[0], src.c_str(), tmp.size());
dest.assign(tmp.begin(), tmp.end() - 1);
@1901
1901 / sprite_shader.cpp
Created May 15, 2014 01:47
Cocos2d中设置Sprite的Shader
CCGLProgram* p = new CCGLProgram();
p->initWithVertexShaderFilename("shader/BanishShader.vsh", "shader/BanishShader.fsh");
p->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
p->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
p->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
p->link();
p->updateUniforms();
pSprite->setShaderProgram(p);
p->release();