Skip to content

Instantly share code, notes, and snippets.

View javenfang's full-sized avatar

Javen Fang javenfang

View GitHub Profile
@javenfang
javenfang / pg transaction
Created June 7, 2017 03:41 — forked from zerbfra/index.js
node-postgres connection and query with async/await
const pg = require('pg')
// create a config to configure both pooling behavior
// and client options
// note: all config is optional and the environment variables
// will be read if the config is not present
var config = {
user: '', // env var: PGUSER
database: '', // env var: PGDATABASE
password: '', // env var: PGPASSWORD

最近因为百度的后门事件,打算给应用换个推送,最后选择了极光推送,结果在接入之后出了一些比较诡异的问题,花了几天才跟踪到问题,大概就是极光推送会导致所有的Activity被重复的实例化,而我们的应用在每个Activity都会维护一个网络请求队列,总之就是几个诡异的坑碰到一起了。

简单测试了一下

  • 测试代码

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
@javenfang
javenfang / pgessays.py
Created February 18, 2016 23:52 — forked from olasitarska/pgessays.py
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <ola@sitarska.com>
Copyright: Licensed under the GPL-3 (http://www.gnu.org/licenses/gpl-3.0.html)
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""
@javenfang
javenfang / gist:7501835
Created November 16, 2013 15:59
Passing Parameters in Clojure
Clojure has support for a number of ways of passing parameters. A function body can have multiple function bodies associated with it, each with different arity. This isn't any where near as general as Haskell's pattern matching (see [1]).
user> (defn foo ([x] x) ([x y] (+ x y)) ([x y z] (+ x y z)))
#'user/foo
user> (foo 1)
1
user> (foo 1 2)
@javenfang
javenfang / delay-process-log-streaming
Last active December 28, 2015 00:39
Based on Redis to implement delayed processing log streaming.
## filename: execute-tasks.py ---------------------------------
#! /usr/bin/env python
import sys
import redis
import time
r = redis.Redis(host="192.168.249.103", port=6379)
KEY = "tag-jobs"
@javenfang
javenfang / gist:7033784
Created October 17, 2013 22:56
用于持续从 tail -f 读取日志信息,输出的也是流式,塞到 Redis List 里。 调用例: tail -f logs/tag-alias-processor.log | grep "Processing" | awk '{print $8}' | python -u ~/mq-from-log2.py
import sys
import redis
r = redis.Redis(host="192.168.250.211", port=10000)
KEY = "tag_alias_list_bk"
try:
while 1:
line = sys.stdin.readline()
if not line: break