Skip to content

Instantly share code, notes, and snippets.

@tahajahangir
tahajahangir / example-mod-wsgi.py
Last active April 22, 2024 00:37 — forked from branneman/example-mod-wsgi.py
Python (2&3 compatible) Equivalent to phpinfo()
def application(environ, start_response):
from pyinfo import pyinfo
output = pyinfo()
# or pyinfo([('custom key', 'custom value'), ...])
start_response('200 OK', [('Content-type', 'text/html')])
return [output]
@tahajahangir
tahajahangir / Tracer.js
Created February 7, 2012 09:26 — forked from cpdean/Tracer.js
Unobfuscated version of tynt Tracer.js
//v26 © 2011 Tynt
Tynt = window.Tynt || [];
if (typeof Tynt.TIL != "undefined") {
} else {
(function () {
var mainTynt = function () {
var body = document.body,
documentElement = document.documentElement,
isIE = eval("/*@cc_on!@*/false"),
repeat = function (a, b) {

Keybase proof

I hereby claim:

  • I am tahajahangir on github.
  • I am jahangir (https://keybase.io/jahangir) on keybase.
  • I have a public key whose fingerprint is E65C 64A6 5648 0BF5 85FE DBB3 B9CA B1E5 5A05 8DA2

To claim this, I am signing this object:

#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis/redis.pid
@tahajahangir
tahajahangir / graceful_http_server.py
Last active June 1, 2016 03:34
Tool to stop a TCPServer (or HTTPServer) in a graceful manner (when the all currently running work is done). This script works either for forked servers or single-process servers.
"""
Graceful Stopper
===================
Tool to stop a TCPServer (or HTTPServer) in a graceful manner (when the all
currently running work is done). This script works either for forked servers or
single-process servers.
The graceful-stop process can be triggered by sending `SIGHUP` to server (in a
forked environment, sending SIGHUP to master server, propagates to all
children). Server immediately releases the listening socket (so another server
@tahajahangir
tahajahangir / gmail_imap_relay.py
Created March 10, 2016 11:55
IMAP Relay for gmail (to inspect/debug imap), prints unencrypted data (without TLS) and disables compression
import tornado
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.tcpclient import TCPClient
from tornado.tcpserver import TCPServer
COLOR_WHITE = 7
COLOR_RECEIVED = 3
COLOR_SENT = 2
@tahajahangir
tahajahangir / mongo_dump.py
Last active December 31, 2015 23:19 — forked from kesor/sql_mongodb_dump_middleware.py
The file is a util for dumping mongo commands/queries. Can be used in any python environment, and included a django middleware.
import struct
import logging
from pymongo import MongoClient
import bson
from bson.errors import InvalidBSON
from pymongo.mongo_replica_set_client import MongoReplicaSetClient
logger = logging.getLogger('mongo_dump')
@tahajahangir
tahajahangir / msync.cpp
Created December 10, 2013 06:51
A simple FreeBSD file syncer that can `fsync` a large file chunk-by-chunk.
/**
* Compile:
* $ g++ -Wall -o msync msync.cpp
* Usage:
* $ msync FILE [WAIT_FACTOR]
* WAIT_FACTOR is a float that changes wait time between syncing two
* chunks (each CHUNK is 10MB). Wait time is factor of sync time, so
* if WAIT_FACTOR is 2.0 (default), if syncing 10MB takes 1 seconds,
* the program waits 2 second after that step.
*/
@tahajahangir
tahajahangir / lof.py
Created June 13, 2012 03:10
An samll mercurial extension to list lastest revision of each file
"""
To install this hg extenstion:
open /path/to/repo/.hg/hgrc
add this lines:
[extenstions]
lof=install/lof.py
"""
#http://selenic.com/pipermail/mercurial/2010-February/029951.html
#http://mercurial.selenic.com/wiki/MercurialApi
@tahajahangir
tahajahangir / yaml-dos.py
Created January 12, 2015 06:07
Yaml load denial-of-service using alias feature
import yaml
yaml.safe_load("""
- &a '1'
- &b [*a,*a]
- &c [*b,*b]
- &d [*c,*c]
- &e [*d,*d]
- &f [*e,*e]
- &g [*f,*f]
- &h [*g,*g]