Skip to content

Instantly share code, notes, and snippets.

View lucemia's full-sized avatar

David Chen lucemia

View GitHub Profile
@lucemia
lucemia / gist:7414666
Created November 11, 2013 15:15
rtb detected vertical
"http://www.youmaker.com/video/svb5-85bb633c694b402ca21ef7e2cdf49966055.html.%E8%95%AD%E7%85%8C%E5%A5%87-45-%E6%80%9D%E5%BF%B5%E6%9C%83%E9%A9%9A.html"
{'1033': '0.21464726', '3': '0.36757067', '1021': '0.20658995', '979': '1.0', '35': '0.21119212'}
{'1033': '0.22178929', '3': '0.34067592', '1021': '0.21893217', '979': '1.0', '35': '0.21860263'}
"http://www.gj1904.com/a.asp"
{'24': '0.2983656', '8': '0.403966', '447': '1.0', '239': '0.29766843', '105': '0.75'}
{'3': '1.0', '447': '1.0', '926': '0.5', '105': '0.75'}
"http://recipe.ytower.com.tw/Channel/MultiSearchRecipes"
{'909': '0.1554877', '122': '1.0', '912': '0.18566176', '1512': '0.24693201'}
@lucemia
lucemia / gist:7479178
Created November 15, 2013 04:37
searchable model
# coding=utf-8
# This is a CJK language supported Searchable Model based on Google's implementation.
# Hen-Hsen Huang, 2011
# Tagtoo
import re
import string
import sys
from google.appengine.api import datastore
from google.appengine.api import datastore_errors
@lucemia
lucemia / gist:7768545
Created December 3, 2013 12:41
action pattern
patterns = {
0 :[
# Common Pattern
# click ad behavior
(r'utm_source', r'ad'),
(r'utm_source=([\w]+)', r'ad:\1'),
],
28: [
# Mayuki Pattern
(r'mayuki', r'visit'),
# -*- encoding=utf8 -*-
import urllib
import urllib2
import re
html = """
... <option value="台北市">台北市</option>
... <option value="新北市">新北市</option>
... <option value="基隆市">基隆市</option>
@lucemia
lucemia / gist:8026890
Created December 18, 2013 18:00
dynamic class
BigDataApi = RestEndpoint('BigDataApi', (_BigDataApi,), [Reducer])
BigDataApi = type(
'BigDataApi',
(BigDataApi, ),
{
'ReducerList': Reducer.method(
request_fields=('id',),
path='reducer/{id}',
# api_exceptions.py
class BadRequestException(ServiceException):
"""Bad request exception that is mapped to a 400 response."""
http_status = httplib.BAD_REQUEST
class ForbiddenException(ServiceException):
"""Forbidden exception that is mapped to a 403 response."""
http_status = httplib.FORBIDDEN
@lucemia
lucemia / gist:8294130
Created January 7, 2014 03:14
open bidder how to decode ip
This field is indeed a little nasty, for parsing it check the documentation from the protobuf:
// The first 3 bytes of the IP address in network byte order for IPv4, or the
// first 6 bytes for IPv6. Note that the number and position of the bytes
// included from IPv6 addresses may change later.
This means you must first check if the size is 3 or 6 bytes, then depending on the size you can get the raw bytes and create the partial IP of the correct type. The last octet is not provided because Ad Exchange removes this information for privacy reasons.
// old table
CREATE TABLE `user_account_old` (
`user` varchar(255) DEFAULT NULL,
`account` varchar(255) DEFAULT NULL,
`created` timestamp NULL DEFAULT NULL,
`is_add` tinyint(1) DEFAULT NULL,
UNIQUE KEY `user_2` (`user`,`account`),
KEY `user` (`user`),
KEY `account` (`account`)
@lucemia
lucemia / gist:10569670
Created April 13, 2014 04:47
2014 code jam 1 with python
import StringIO
import fileinput
import sys
input = sys.stdin
def main(input):
T = int(input.readline())
for i in range(T):
@lucemia
lucemia / gist:10570268
Created April 13, 2014 05:14
code jam 2014 2
import sys
def test(C, F, X, i):
secs = X / (2.0+F*i)
for j in range(i):
secs += C / (2.0 + F*j)
return secs