Different ways to convert time between human readable format and timestamps.
import time
# How to convert from human datetime in local time to timestamp (s)
print(int(time.mktime(time.strptime('2017-03-09 15:39:30', '%Y-%m-%d %H:%M:%S'))))| #!/bin/bash | |
| # Tom Hale, 2016. MIT Licence. | |
| # Print out 256 colours, with each number printed in its corresponding colour | |
| # See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163 | |
| set -eu # Fail on errors or undeclared variables | |
| printable_colours=256 |
| #!/usr/bin/env python | |
| # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349 | |
| print "Color indexes should be drawn in bold text of the same color." | |
| colored = [0] + [0x5f + 40 * n for n in range(0, 5)] | |
| colored_palette = [ | |
| "%02x/%02x/%02x" % (r, g, b) | |
| for r in colored |
| #!/usr/bin/env python | |
| # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349 | |
| print "Color indexes should be drawn in bold text of the same color." | |
| colored = [0] + [0x5f + 40 * n for n in range(0, 5)] | |
| colored_palette = [ | |
| "%02x/%02x/%02x" % (r, g, b) | |
| for r in colored |
| import psycopg2 | |
| from sshtunnel import SSHTunnelForwarder | |
| # For interactive work (on ipython) it's easier to work with explicit objects | |
| # instead of contexts. | |
| # Create an SSH tunnel | |
| tunnel = SSHTunnelForwarder( | |
| ('128.199.169.188', 22), | |
| ssh_username='<username>', |
| # reset-sys-unicode.py | |
| # | |
| # http://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte | |
| # | |
| # to encode a text with utf8 in python2 | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf8') |
| # Some common idioms to make Python work both in version 2.7 and 3.x | |
| # For more examples, see: | |
| # http://python-future.org/compatible_idioms.html | |
| # Absolute import | |
| from __future__ import absolute_import | |
| # Floating point division | |
| from __future__ import division |
| # Compute md5sum of a file | |
| # File: md5sum.py | |
| # Debajyoti Nandi | |
| # 2016-11-09 | |
| # Python 2 | |
| import os | |
| import hashlib |
| # Examples of how to walk through a directory (root) | |
| # File: dir-walk.py | |
| # Debajyoti Nandi | |
| # 2016-11-09 | |
| import os | |
| root = "." |