query = '''SELECT COALESCE(SUM(imp), 0) AS imps,
COALESCE(SUM(click), 0) AS clicks
FROM logCuDate
WHERE id=%s
AND date >= %s
AND date <= %s'''
res = db.executesql(query, args, as_dict=True)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an example of metaprogramming in the Elixir language. | |
# | |
# We will define a domain specific language (DSL) for the definition | |
# of a service which is watched by several sensors. | |
# Each sensor watches some property/functionality of the service and | |
# returns the result of the check. | |
# | |
# To determine if the service is functioning properly, we need functions | |
# to run all the sensors' code and gather the returned data. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticsearch import Elasticsearch | |
es = Elasticsearch() | |
res = es.get(index="belajar", doc_type='pesan', id=1) | |
print(res['_source']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This script help you extract image files from an APK file. | |
# Author : Daehee Han (https://github.com/booknara, @daniel_booknara) | |
# Date : August 21 2013 | |
# Basic Usage | |
# (1) img_extractor.py --ifile <APK file> --ofile <Destination Directory> | |
# (2) img_extractor.py --ifile <APK file> --ofile . | |
# (3) img_extractor.py --ifile <APK file> --ofile .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- ** setting up example tables and data ** | |
-- | |
-- | |
CREATE TABLE task ( | |
id BIGSERIAL , | |
name TEXT, | |
parent_id BIGINT REFERENCES task(id), | |
PRIMARY KEY (id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Backend(object): | |
def __init__(self): | |
engine = create_engine("mysql://{0}:{1}@{2}/{3}".format(options.mysql_user, options.mysql_pass, options.mysql_host, options.mysql_db) | |
, pool_size = options.mysql_poolsize | |
, pool_recycle = 3600 | |
, echo=options.debug | |
, echo_pool=options.debug) | |
self._session = sessionmaker(bind=engine) | |
@classmethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from termcolor import colored | |
class ColorLog(object): | |
colormap = dict( | |
debug=dict(color='grey', attrs=['bold']), | |
info=dict(color='white'), | |
warn=dict(color='yellow', attrs=['bold']), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
import sys, Image | |
if __name__ == '__main__': | |
fn = sys.argv[1] | |
img = Image.open(fn).convert('YCbCr') | |
w, h = img.size | |
data = img.getdata() | |
cnt = 0 |
NewerOlder