Skip to content

Instantly share code, notes, and snippets.

View ourway's full-sized avatar
🏆

Farshid Ashouri ourway

🏆
View GitHub Profile
@qingfeng
qingfeng / seximage.py
Created October 28, 2008 09:38
Image is a porn image?
#!/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
@brainsik
brainsik / color_log.py
Created September 24, 2011 03:51
ANSI colored Python logging
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']),
@kevinSuttle
kevinSuttle / meta-tags.md
Last active March 31, 2024 14:26 — forked from lancejpollard/meta-tags.md
List of Usable HTML Meta and Link Tags
@dmitric
dmitric / backend.py
Created March 24, 2012 18:06
SqlAlchemy usage with tornado backend
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
@z4y4ts
z4y4ts / gist:3302920
Created August 9, 2012 10:08
SQL complex query with aggregation in web2py DAL way

Raw SQL

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)
@marko-asplund
marko-asplund / advanced-psql-examples.sql
Last active June 15, 2023 02:15
Advanced PostgreSQL feature examples. Includes table DDL, example data and queries.
--
-- ** setting up example tables and data **
--
--
CREATE TABLE task (
id BIGSERIAL ,
name TEXT,
parent_id BIGINT REFERENCES task(id),
PRIMARY KEY (id)
@booknara
booknara / img_extractor.py
Last active July 12, 2016 05:01
This script help you extract image files from an APK file. 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 ..
#!/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 ..
@arisetyo
arisetyo / get.py
Created January 7, 2014 03:01
Using Python ElasticSearch Client
from elasticsearch import Elasticsearch
es = Elasticsearch()
res = es.get(index="belajar", doc_type='pesan', id=1)
print(res['_source'])
@mprymek
mprymek / gist:8379066
Last active July 22, 2022 09:18
Elixir metaprogramming example
# 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.
#
@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()