Skip to content

Instantly share code, notes, and snippets.

@zii
zii / Cmbilling.java
Last active August 29, 2015 14:04
lua调用移动SDK的代码
package org.cocos2dx.lua;
import org.cocos2dx.lib.Cocos2dxLuaJavaBridge;
import org.cocos2dx.lib.Cocos2dxActivity;
import cn.cmgame.billing.api.BillingResult;
import cn.cmgame.billing.api.GameInterface;
import cn.cmgame.billing.api.LoginResult;
import cn.cmgame.gamepad.api.Gamepad;
import cn.cmgame.gamepad.api.KeyState;
@zii
zii / smoothpv.lua
Last active August 29, 2015 14:05
change draging sensitivity of ccui.PageView
-- add dragging sensitive of the ccui.Pageview
function smoothpv(pageview, n)
n = n or 8
local pagen = #pageview:getPages()
for i = 0, pagen-1 do
local page = pageview:getPage(i)
page:addTouchEventListener(function(sender, e)
if e ~= ccui.TouchEventType.canceled then
return
end
@zii
zii / MainActivity.java
Last active August 29, 2015 14:06
android toast, dialog, openurl
package com.example.hello;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@zii
zii / CCSdkUnipay.java
Last active August 29, 2015 14:08
CCSdkUnipay.java
/* Unipay SDK for cocos2d-x */
package com.xingdong.tpyzz;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@zii
zii / ito10.c
Last active August 29, 2015 14:14
fast itoa, 3x speed faster than stdlib.itoa, 19x faster than sprintf("%d")
static char* ito10_tab100[100] = {
"00", "10", "20", "30", "40", "50", "60", "70", "80", "90",
"01", "11", "21", "31", "41", "51", "61", "71", "81", "91",
"02", "12", "22", "32", "42", "52", "62", "72", "82", "92",
"03", "13", "23", "33", "43", "53", "63", "73", "83", "93",
"04", "14", "24", "34", "44", "54", "64", "74", "84", "94",
"05", "15", "25", "35", "45", "55", "65", "75", "85", "95",
"06", "16", "26", "36", "46", "56", "66", "76", "86", "96",
"07", "17", "27", "37", "47", "57", "67", "77", "87", "97",
"08", "18", "28", "38", "48", "58", "68", "78", "88", "98",
@zii
zii / syntax.py
Created February 11, 2015 06:53
add elif to old django
#coding: utf-8
"""Default tags used by the template system, available to all templates."""
from __future__ import unicode_literals
from django.template import (Node, NodeList, Library, TextNode,
TemplateSyntaxError, VariableDoesNotExist)
from django.template.smartif import IfParser, Literal
register = Library()
# Check the alias
keytool -list -keystore ${MYKEY}.jks
# Export to PKCS12
keytool -importkeystore -srckeystore ${MYKEY}.jks -destkeystore ${MYKEY}.pkcs -srcstoretype JKS -deststoretype PKCS12 -alias ${MYALIAS}
# Convert to PEM
openssl pkcs12 -in ${MYKEY}.pkcs -out ${MYKEY}.pem
@zii
zii / id_series.sql
Last active October 14, 2015 04:04
查询缺失的主键ID
# 查询缺失的主键ID
set @a := 0;
select t.r0, t.r1 from
(
select id, @a+1 as r0, id-1 as r1, if(id>@a+1, 0, 1) as 'series', @a:=id as 'a' from test
order by id
) t
where t.series=0
order by t.id
;
#coding: utf-8
"""添加自定义过滤器"""
from jinja2 import Environment
from jinja2.runtime import Undefined
def do_date(date, format):
"""时间格式化
~ 用法:{{xxx|date('%Y-%m-%d %H:%M:%S')}}
"""
s = date.strftime(format.encode('utf-8'))
@zii
zii / struct.py
Last active September 11, 2016 05:05
#coding: utf-8
class Struct(dict):
"""
- 为字典加上点语法. 例如:
>>> o = Struct({'a':1})
>>> o.a
>>> 1
>>> o.b
>>> None
"""