Writing by shivdev on Thursday, 20 of November , 2014 at 1:47 am
If you have several epoch times that you want to convert to human readable date then here’s a great post from spreadsheetpage.com on converting Unix Timestamps.
In a nutshell … you use the provided formula and then format to date.
For GMT
=(((A1/60)/60)/24)+DATE(1970,1,1)
For Pacific
=(((A1/60)/60)/24)+DATE(1970,1,1)+(-8/24)
Right Click the Cell –> Format Cells –> Date
Category: Tips and Tricks
Writing by shivdev on Wednesday, 12 of November , 2014 at 4:43 am
Here’s a list of Apps that I must have on my Mac:
Category: Apple
Writing by shivdev on Tuesday, 11 of November , 2014 at 9:20 pm
If you’re having trouble selecting entries one at a time (because there’s no Select All option available) then here’s a quick workaround to selectively clear your Google Chrome History.
- In the Chrome Address Bar type chrome://history
- To Filter and Delete Selective history, enter search criteria and hit Search History
- There’s no Select All Option but here’s a workaround …
- Select the first entry from where you want deletion to begin
- Scroll down to the end or desired entry and Shift Click that item
- Scroll up top and hit Remove Selected Items
That should be quicker than individually selecting the entries.
Category: Tips and Tricks
Writing by shivdev on Saturday, 8 of November , 2014 at 10:05 pm
I was running into several errors while accessing a dictionary persisted in MongoDB as JSON (with Unicode) until I found this post on stackoverflow.com.
TypeError: string indices must be integers, not unicode
So basically the way to workaround the problem is as follows:
import json, ast
# You would assume this would work ...
somekey_val = dict[SOME_KEY]
# but due to frustrations with unicode in python handle it
try:
somekey_val = ast.literal_eval(dict[SOME_KEY])
except Exception, e:
print 'unicode conversion not needed for some_key'
# do regular processing from here on
process( somekey_val )
Category: Python
Writing by shivdev on Monday, 3 of November , 2014 at 6:18 pm
This post from stackoverflow.com explains it.
Basically, you will need to use the default=json_util.default argument as defined in the PyMongo Docs
So, while converting a date object in a dictionary to JSON
from bson import json_util
import json
json_str = json.dumps(anObject, default=json_util.default)
print json_str
And while reading back the JSON string into a dictionary
from bson import json_util
import json
json.loads(json_str, object_hook=json_util.object_hook)
Category: Python