Convert epoch millisecond timestamp to readable datetime

In many cases such as when dealing with API response in JSON format, working on JavaScript assets embedded on websites, and so on, we keep seeing 13-digit long numbers very frequently and we probably know it is epoch timestamp originating from code like new Date().getTime(), however, as a human we just can not quickly tell what date and time it represents. There is a convenient website named Epoch Converter that can help convert it to human-readable format easily but most of the time for developers, there are even quicker ways than opening the website, which is by using the interactive shell that comes with many programming languages.

Python topics of interest

Python topics of interest.

ThreadPoolExecutor map method with multiple parameters

ThreadPoolExeuctor from concurrent.futures package in Python 3 is very useful for executing a task (function) with a set of data (parameter) concurrently and this post lists examples on how to pass MULTIPLE parameters to the task being executed.

Python decorator with class

Python decorators are usually created with function, see another related post, but this post also shows an example on how to create decorators with class.

Async task with celery

A quick guide on how to use celery to accomplish async task in application.

Flask based app consolidated logging

Flask has an "app.logger" which you can use for webapp related logging, and for other libraries or packages that flask app is using usually python standard logging is used. There are issues reported that logs from various sources in flask based app sometimes get missed out or get messy. See the references section at the bottom for details about the issues. A workaround is to set global root logging config and override that from flask.

Huey as crontab alternative in python

Huey as crontab alternative in python.

Pathos solves PicklingError for multiprocssing

Python multiprocssing is useful in executing concurrent tasks with multiple processes. But it also requires the objects being executed support pickling, which is not always true for types like class instance methods, staticmethods and etc. Pathos has a multiprocessing implementation that uses dill on the backend which supports serializing and deserializing for almost all types.

Generate two dimensional arrays with serial numbers

Generate n*n two dimensional arrays with serial numbers in Python.

Insert into mongodb with DBRef

How to insert a new object into mongodb using pymongo with reference to other objects using DBRef.

Print or remove duplicates in list

How to quickly print out or remove duplicated items from given list in python.

SSL error with python requests

Quick fix to an ssl error was encountered with python requests on Ubuntu 14.04.

Compiling error installing lxml on Ubuntu

A compiler error was observed during installing lxml on Ubuntu the error looks something like: error: command 'x86_64-linux-gnu-gcc' failed with exit status 4, and it's most likely caused by low memory.

Quickly share files with Python2 SimpleHTTPServer

With Python2 builtin SimpleHTTPServer (or http.server in Python3), you can start an http service to easily and quickly share a directory with files, which is especially useful and convenient in LAN environments.

Insert into MySQL with Python dict

How to use Python dict as data source for MySQL insert-into statement.

Python connect mysql with pymysql

PyMySQL is a pure-Python MySQL client library which allows you to easily connect to MySQL db and perform db operations in pythonic way.

Elasticsearch python client

Elasticsearch python client and sample code for indices creation and deletion, document indexing, and searching. For elasticsearch installation, see post elk-getting-started-notes.

Python coding style guide

PEP8 (Python Enhancement Proposal 8) is the style guide for python coding and this post lists some of the important rules that should be followed.

Ansible basics

Execute remote command from command line and playbook with Ansible.

Quick steps of using Python virtualenv

Quick steps of using Python virtualenv.

Python fabric

Basic usage of Python fabric.

Python literal conversion

Python literal conversion using the ast.literal_eval() method.

Pywinauto to automate vpn connection

Automate vpn connection (Cisco IPSec VPN Client + SoftToken) using pywinauto package on windows platform.

Python remove duplicate dict in list

Remove duplicate dict from a list in python.

Find max common divisor

Find max common divisor.

Python open file with with statement

It is good practice to use the with keyword when dealing with file objects. This has the advantage that the file is properly closed after its suite finishes, even if an exception is raised on the way. It is also much shorter than writing equivalent try-finally blocks.

Python multiprocessing

Python multiprocessing.

Python multithreading

Python multithreading. NOTE that although multiple threads can run within the python interpreter, ONLY one thread is being executed by the interpreter at any given time, which is ensured by the GIL (global interpreter lock) in python virtual machine. Python multithreading is more appropriate for I/O-bound applications than for CPU-bound applications as I/O releases GIL.

Python file extensions

Common python file/script extensions and the meaning.

Python fabonacci

Python fabonacci implementations.

List installed python packages

How to find out or list the installed python packages.

Python bubble sort

Bubble sort algorithm is comparison based algorithm in which each pair of adjacent elements is compared and elements are swapped if they are not in order. The average and worst case complexity of bubble sort is O(n2) where n is the number of items.

Python timestamp format

How to display timestamp in desired format in python.

Extract the i-th digit of integers

Extract the i-th digit of any integers, where i starts from right to left.

Python encoding and unicode

Python source code encoding and unicode in 2.x.

Python main

What the if __name__ == '__main__' does in python and practice of defining python main functions.

Python function arguments

Python function standard arguments, positional arguments, and keyword arguments.

Python imports and PYTHONPATH

Python imports and PYTHONPATH.

Python aop with decorators

Python aop with decorators