Skip to content

Instantly share code, notes, and snippets.

import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())
@abhi1010
abhi1010 / mailer.py
Created September 24, 2018 06:26
send mails
import httplib2
from email.encoders import encode_base64
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
import base64
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
@abhi1010
abhi1010 / create-class-diagram.md
Last active October 12, 2018 08:57
class diagram from code
@abhi1010
abhi1010 / popen_examples.py
Created June 20, 2018 00:29
run bash commands in python using Popen
def _run_cmd_with_prints(cmd):
proc = subprocess.Popen(
cmd,
bufsize=1,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
for line in proc.stdout.readline():
print('output = {}'.format(line))
@abhi1010
abhi1010 / logging_config.py
Created June 19, 2018 03:07
python logging to console and file
import logging
FORMAT = '%(asctime)-15s %(filename)s <%(lineno)s> %(message)s'
logging.basicConfig(
filename='log-myreport.log', level=logging.DEBUG, format=FORMAT)
stdoutLogger = logging.StreamHandler()
stdoutLogger.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
logging.getLogger().addHandler(stdoutLogger)
@abhi1010
abhi1010 / icecream.sh
Last active May 17, 2018 09:47
icecream setup
sudo dnf install -y icecream.x86_64 icemon.x86_64
# On Main Scheduler server - run both
sudo icecc-scheduler -d
sudo iceccd -d
# On Build Farm Clients
sudo iceccd -d
@abhi1010
abhi1010 / expand_url.py
Created January 6, 2018 16:18 — forked from vgoklani/expand_url.py
Expand shortened URLs in Python
# http://stackoverflow.com/questions/748324/python-convert-those-tinyurl-bit-ly-tinyurl-ow-ly-to-full-urls
#############
# urllib2
import urllib2
fp = urllib2.urlopen('http://bit.ly/rgCbf')
fp.geturl()
# ==> 'http://webdesignledger.com/freebies/the-best-social-media-icons-all-in-one-place'
@abhi1010
abhi1010 / cpp_time_ostream.log
Last active April 23, 2019 06:12
print std::chrono::duration
edit mode | history
10 hours
36000 seconds
60000 intervals of 0.600000 (3/5) seconds each
@abhi1010
abhi1010 / inv_pylib_build.py
Created January 26, 2017 08:55
how to write invoke commands that reach other folders
@task
def find():
with cd('../../pylib/gh_hazardous_sol/'):
print('finding tasks')
res = check_output(['/opt/py27env/bin/invoke', '-l'])
print('results = {}'.format(res))
if 'build' in res:
print('we got build command')
# currently all build code is common across all pylibs, through pylib/tasks.py.
# folders like gh_hazardous_sol simply call pylib/tasks.py->build function if it exists