Skip to content

Instantly share code, notes, and snippets.

View moijes12's full-sized avatar

Alex moijes12

View GitHub Profile
@moijes12
moijes12 / timezone_conversion_blog.md
Last active October 15, 2019 13:07
Converting an aware datetime object from one timezone to another in python

Converting an aware datetime object from one timezone to another in python

Problem

I recently ran into a beginner problem at work where I had to write a utility method that would receive a timestamp and the timezone of the timestamp and convert it into a human readable form for UTC timezone. Now, this looked straightforward except that I hadn't worked with the datetime library before. So after much searching, I came across the very useful datetime.astimezone() method which helped solve the problem.

About the datetime.astimezone(tz=None) method

The astimezone(tz=None) takes in a datetime object and returns a new datetime object with the time set to the equivalent time in the datetime.tzinfo attribute tz. If no tz object is not provided, it defaults to UTC timezone.

>>> from datetime import datetime
@moijes12
moijes12 / gist:b8a5899a63a09ddc4f794856f177fda5
Last active October 2, 2017 14:11
Command to loading a scheme file in the interpreter
Command to loading a scheme file in the interpreter -> (load "filename.scm")
The result will be something as below
1 ]=> (load "pascals.scm")
;Loading "pascals.scm"... done
;Value: pascals
@moijes12
moijes12 / gist:a20dce23a6436829ce91cec93a604d8b
Created July 2, 2017 05:42
Starting the Python SimpleHTTPServer and keeping it running even after logging out
Below is a command I used to start the Python provided SimpleHTTPServer in a session and have it running even after I logout.
I found this command on the web and found it quite useful. This work is attributed to that original author.
The command will run a python based webserver on port 8000 of the host on which it was called.
screen -d -m python -m SimpleHTTPServer 8000