Skip to content

Instantly share code, notes, and snippets.

View pcdinh's full-sized avatar

Pham Cong Dinh pcdinh

View GitHub Profile
@pcdinh
pcdinh / gist:5395186
Created April 16, 2013 11:21
Note 2 frozen
User 11%, System 11%, IOW 76%, IRQ 0%
User 36 + Nice 0 + Sys 36 + Idle 0 + IOW 233 + IRQ 0 + SIRQ 0 = 305
PID PR CPU% S #THR VSS RSS PCY UID Name
1143 0 25% D 1 0K 0K root mmcqd/0
7714 0 6% S 37 611416K 86376K fg u0_a48 com.google.android.gm
19464 0 3% R 1 1168K 540K shell top
16309 0 0% S 1 0K 0K root kworker/0:3
2297 0 0% S 118 663484K 107920K fg system system_server
20 1 0% S 1 0K 0K root khelper

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
@pcdinh
pcdinh / gist:5249831
Created March 26, 2013 22:19
SQLAlchemy consumes a lot of memory. Not a good sign to a high traffic website
With SQLAlchemy (on top of psycopg2 driver): 71MB per process
=============================================================
top - 14:29:23 up 55 days, 4:18, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 99 total, 1 running, 98 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3840476k total, 3808680k used, 31796k free, 97716k buffers
Swap: 0k total, 0k used, 0k free, 2491464k cached
#!/usr/bin/env python
###############################################################################
# $Id$
#
# Project: GDAL2Tiles, Google Summer of Code 2007 & 2008
# Global Map Tiles Classes
# Purpose: Convert a raster into TMS tiles, create KML SuperOverlay EPSG:4326,
# generate a simple HTML viewers based on Google Maps and OpenLayers
# Author: Klokan Petr Pridal, klokan at klokan dot cz
# Web: http://www.klokan.cz/projects/gdal2tiles/
%%
%% mod_log_remote is a simple Ejabberd module and gen_server that
%% allow for remote logging. It uses the filter_packet hook to
%% intercept <message> stanzas addressed to logger@vhost. These
%% messages are beamed off to the configured Erland node / pid in
%% the form:
%%
%% {Type, LogTime, Payload}
%%
%% where Type and Payload are specified by the caller and LogTime is
import os
import sys
import errno
import fcntl
def file_to_pipe(file, pipe):
if file.closed:
pipe.closed()
return
%% mod_js is a prototype module that uses erlang_js
%% to allow filtering stanza's through JavaScript
%% for altering, dropping, etc.
%%
%% NOTE: The JavaScript path is hardcoded to "test.js"
%% at the end of this file.
%%
-module(mod_js).
-author('[email protected]').
%%
%% mod_msg_filter allows the filtering of "message"
%% stanzas across an HTTP service. The URL of the
%% service must be passed as part of the module's
%% configuration. Both JIDs and their resources are
%% passed as part of the query string and the result
%% is expected to be one of:
%%
%% <status value="denied">
%% <stanza1><error/></stanza1>
%%
%% mod_log_remote is a simple Ejabberd module and gen_server that
%% allow for remote logging. It uses the filter_packet hook to
%% intercept <message> stanzas addressed to logger@vhost. These
%% messages are beamed off to the configured Erland node / pid in
%% the form:
%%
%% {Type, LogTime, Payload}
%%
%% where Type and Payload are specified by the caller and LogTime is
def get_tile_origin(self, tile_x, tile_y, zoom):
'''Return the lat, lng of the northwest corner of the tile.'''
tile_width = 360.0/pow(2,zoom) # degrees
tile_height = tile_width/2 # degrees
n = 90 - tile_y * tile_height
w = -180 + tile_x * tile_width
return (n,w)
def get_bb(self, tile_x, tile_y, zoom):
"""Return bounding coordinates (n, e, s, w) of the tile."""