Skip to content

Instantly share code, notes, and snippets.

@shirou
shirou / Jackson Stream API (JSON Parser)
Created October 26, 2010 00:59
Jackson JSON Stream parser example
JsonFactory fac = Util.getJsonFactory(); // recycle JsonFactory
// JsonFactory fac = new JsonFactory(); // or just use once.
JsonParser jp = null;
try {
jp = fac.createJsonParser(json);
jp.nextValue(); // responseData
jp.nextValue(); // null
jp.nextValue(); // results
@shirou
shirou / FileObserver on Android
Created November 2, 2010 02:24
Detect file change using FileObserver on Android
private class PathFileObserver extends FileObserver{
static final String TAG="FILEOBSERVER";
/**
* should be end with File.separator
*/
String rootPath;
static final int mask = (FileObserver.CREATE |
FileObserver.DELETE |
FileObserver.DELETE_SELF |
FileObserver.MODIFY |
@shirou
shirou / Using FileObserver
Created November 2, 2010 02:25
Detect File Change using FileObserver on Android
FileObserver f;
f = createWatchList("/sdcard/");
f.startWatching();
watchList.add(f);
f = createWatchList("/sdcard/tmp");
f.startWatching();
watchList.add(f);
}
@shirou
shirou / gist:666116
Created November 7, 2010 13:03
DefaultHttpClient
static DefaultHttpClient mHttpClient = null;
final static int RETRY_COUNT = 2;
static SchemeRegistry mSchemeRegistry = null;
public static void createConnManager(){
mSchemeRegistry = new SchemeRegistry();
mSchemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
mSchemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
@shirou
shirou / DB for Android
Created November 30, 2010 05:29
DB access for Android
public class StocksDb {
private static final String DB_NAME = "stocks.db";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "stock";
private static final String CREATE_TABLE = "CREATE TABLE " +
TABLE_NAME + " (id INTEGER PRIMARY KEY, symbol TEXT, max_price DECIMAL(8,2), " +
"min_price DECIMAL(8,2), price_paid DECIMAL(8,2), " +
"quantity INTEGER)";
private static final String INSERT_SQL = "INSERT INTO " + TABLE_NAME +
" (symbol, max_price, min_price, price_paid, quantity) " +
@shirou
shirou / python
Created December 6, 2010 04:30
How to use i18n in the jinja2
from jinja2 import Environment
env = Environment(extensions=['jinja2.ext.i18n'])
template = env.get_template('foo.html')
template.render()
@shirou
shirou / gist:748143
Created December 20, 2010 08:01
Sphinx environment bundle for pip
Jinja2==2.5.5
PIL==1.1.7
Pygments==1.3.1
Sphinx==1.0.5
blockdiag==0.5.2
docutils==0.7
funcparserlib==0.3.4
reportlab==2.5
rst2pdf==0.16
sphinxcontrib-blockdiag==0.6
@shirou
shirou / gist:754367
Created December 24, 2010 16:08
Secure filename it removes slash, null and all other un-secure strings.
import os, re
_split = re.compile(r'[\0%s]' % re.escape(''.join(
[os.path.sep, os.path.altsep or ''])))
def secure_filename(path):
return _split.sub('', path)
@shirou
shirou / gist:779271
Created January 14, 2011 06:33
sphinx document environment pip requirement file.
Jinja2
PIL
Pygments
Sphinx
blockdiag
docutils
funcparserlib
reportlab
rst2pdf
sphinxcontrib-blockdiag
@shirou
shirou / gist:802881
Created January 30, 2011 14:08
ikazuchi.el
;;; ikazuchi-mode.el --- ikazuchi, translate using web APIs, minor mode.
;;;
;;; Currently can use only Google.
;;;
(provide 'ikazuchi-mode)
;; set path to ikazuchi if you have not set PATH.
(defvar ikazuchi-path "ikazuchi")