Skip to content

Instantly share code, notes, and snippets.

@Jd007
Jd007 / keybase.md
Created December 11, 2017 20:41
keybase.md

Keybase proof

I hereby claim:

  • I am Jd007 on github.
  • I am jd007 (https://keybase.io/jd007) on keybase.
  • I have a public key whose fingerprint is 0D79 F0DA 5E20 2B01 0567 AEDF E971 B24E D258 104A

To claim this, I am signing this object:

@Jd007
Jd007 / gist:6084243
Created July 25, 2013 22:09
Inception?
Dreamer [Fischer], level [1], priority [19], policy [OTHER]
Dreamer [Cobb], level [1], priority [19], policy [OTHER]
Dreamer [Ariadne], level [1], priority [19], policy [OTHER]
Dreamer [Arthur], level [1], priority [19], policy [OTHER]
Dreamer [Eames], level [1], priority [19], policy [OTHER]
Dreamer [Yusuf], level [1], priority [19], policy [OTHER]
Dreamer [Saito], level [1], priority [19], policy [OTHER]
[Fischer] HIJACKED ! Open up my defense projections in my dream to the hijackers!
[Ariadne] sees Fischers defense projections at work in the dream at level [1]
[Cobb] sees Fischers defense projections at work in the dream at level [1]
@Jd007
Jd007 / gist:5573672
Created May 14, 2013 04:21
Python class that runs fully daemonized (with a double fork)
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
'''
Base Daemon class that takes care of the start, stop, and forking of the processes.
Used to daemonize any Python script.
'''
#!/bin/sh
echo
echo "Executing Fabric deploy command"
echo
branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ $branch = "dev" ]
then
#!/bin/sh
echo
echo "Executing Fabric deploy command"
echo
cd /path/to/fabfiles
branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ $branch = "dev" ]
then
/path/to/fabexec/bin/fab deploy_dev_fabfile
@Jd007
Jd007 / gist:5446475
Created April 23, 2013 19:09
Gitlog extraction
def extract_git_log_by_hashes(hash_file_path, raw_log_path, output_file_path):
f = open(hash_file_path, 'r')
hashes = []
for h in f:
hashes.append(str(h).strip())
f.close()
raw_log_file = open(raw_log_path, 'r')
processed_data = {}
is_in_block = False
@Jd007
Jd007 / gist:5259751
Created March 28, 2013 01:32
How to create timezone aware datetime objects in python given UTC offset in seconds.
import datetime
class AnyTimeZone(datetime.tzinfo):
# Define this somewhere, and import it whenever you need to make TZ aware datetime objects
def __init__(self, utc_offset, is_dst):
self.utc_offset = utc_offset
self.dst_on = is_dst
def utcoffset(self, dt):
def get_geo_hash_redis_result(coord_ui, precision, cache_key, redis_db):
UNSIGNED_BIGINT_MAX = 18446744073709551615
redis_pipe = redis_db.pipeline()
for hilo in geohash.expand_uint64(coord_ui, precision):
if hilo[0] and hilo[1]:
redis_pipe.zrangebyscore(cache_key, hilo[0], (hilo[1] - 1), start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
elif hilo[0]:
redis_pipe.zrangebyscore(cache_key, hilo[0], UNSIGNED_BIGINT_MAX, start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
elif hilo[1]:
redis_pipe.zrangebyscore(cache_key, 0, (hilo[1] - 1), start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
@Jd007
Jd007 / gist:4576256
Last active December 11, 2015 08:58
A basic Python quine.
if __name__ == '__main__':
quote = chr(34)
str_list = [
"if __name__ == '__main__':",
" quote = chr(34)",
" str_list = [",
" ",
" ]",
" for i in range(3):",
" print str_list[i]",