Skip to content

Instantly share code, notes, and snippets.

View akash0x53's full-sized avatar
๐Ÿš€
Watching Rockets

Akash Shende akash0x53

๐Ÿš€
Watching Rockets
View GitHub Profile
@akash0x53
akash0x53 / gist:6094731
Last active May 12, 2017 17:13
Terminal greeting.
# Terminal greeting.
# Whenever you open a terminal, it will show a man page of randomly selected command.
# [useful for beginner.]
# source : efytimes.com
#append this line to ~/.bashrc
man `ls /usr/bin | shuf -n1`
@akash0x53
akash0x53 / gist:30e2f72be1881829939e
Last active August 29, 2015 14:10
Split single python list into 'n' length lists.
#
# chunk given list
#
from itertools import islice
def chunked_list(lst, n):
itr = iter(lst)
return iter(lambda: list(islice(itr, n)), [])
@akash0x53
akash0x53 / gist:9490cbcf75bf1fe91ce2
Last active August 29, 2015 14:10
How to design classes in python.
http://stackoverflow.com/questions/4203163/how-do-i-design-a-class-in-python/4203836#4203836
#TLDR:
How to design a class.
Write down the words. You started to do this. Some people don't and wonder why they have problems.
Expand your set of words into simple statements about what these objects will be doing. That is to say, write down the various calculations you'll be doing on these things. Your short list of 30 dogs, 24 measurements, 4 contacts, and several "parameters" per contact is interesting, but only part of the story. Your "locations of each paw" and "compare all the paws of the same dog to determine which contact belongs to which paw" are the next step in object design.
@akash0x53
akash0x53 / gist:afc9cd14198923a0fbdf
Created December 14, 2014 06:47
find & replace with sed
find . -iname '*py' -exec sed -i 's/foo/bar/g' {} \;
@akash0x53
akash0x53 / gist:49b80559bdf1384c4566
Last active August 29, 2015 14:11
Python decorator with argument to check HTTP request method.
class CheckHttpMethod(object):
"""
Decorator check whether HTTP request is as per your need,
if not it redirects to '/'.
This is a decorator with *mandatory* argument, a HTTP method
you want to check.
>>>@CheckHttpMethod('POST')
...def handler(*args, *kwargs):
... pass
"""
@akash0x53
akash0x53 / held_futex.sh
Last active August 29, 2015 14:11
check processes for futex_wait
TRUE=0
FALSE=1
held_futex(){
tot=`ps -eo "%p %u %a"|awk '{ print ($2=="user") ? $0: ""}'|grep -c -i '[p]rocess'`
i=0
for pid in `ps -eo "%p %u %a"|awk '{ print ($2=="user") ? $0: ""}'|grep -i '[p]rocess'|awk '{ print $1 }'`
do
cnt=`cat /proc/${pid}/wchan|grep -c -i 'futex_wait_'`
if [ $cnt -gt 0 ];then
i=$((i+=1))
@akash0x53
akash0x53 / hg_diff.sh
Created December 21, 2014 06:18
generate hg diff
#Generate Mercurial diff and save in `diffs' subdir.
generate_diff(){
diff_dir="diffs"
mkdir -p ${diff_dir}
branch=`hg branch`
now=`date +"%F_%T"`
file_path="${PWD}/${diff_dir}/${branch}_${now}.diff"
`hg diff > ${file_path}`
[ $? -eq 0 ] && echo "created diff ${file_path}"
@akash0x53
akash0x53 / extract_info.py
Created December 24, 2014 09:27
Extract key, certificate from pkcs12
def extract_cert_key(certpath=None):
"""
Extracts private key & certificate and returns as pem string.
params:
certpath = Valid P12 certificate file path.
returns:
(certificate, privatekey)
"""
import os
import getpass
@akash0x53
akash0x53 / gist:29113421e621753a3e67
Created February 12, 2015 18:14
Remove duplicate dict from list of dicts
a = {
"a": 123,
"b": 456
}
l = [a, a]
print l
remove_dups = [dict(t) for t in set([tuple(d.items) for d in l])]
@akash0x53
akash0x53 / gist:2bc7e6efe089a79eb8a0
Created February 13, 2015 11:34
convert uuid.getnode to MAC address format
>>> import uuid
>>> mac="%12X" % uuid.getnode()
>>> mac
'48D224921B7C'
>>> mac[::2]
'4D2917'
>>> mac[1::2]
'8242BC'
>>> map(None, *(mac[::2], mac[1::2]))