Skip to content

Instantly share code, notes, and snippets.

View lernisto's full-sized avatar

Terrel Shumway lernisto

View GitHub Profile
@lernisto
lernisto / timestamp.py
Last active July 13, 2019 17:19
Various ways to get a current timestamp or convert a timestamp to a `datetime`
#!/usr/bin/env python3
'''
I spent way too much time messing with timestamps.
A timestamp is the number of seconds elapsed since the epoch.
A unix timestamp uses the unix epoch, which is defined as
1970-01-01T00:00:00+00:00
Takeaways
data = [43, 542, 34, 15, 23, 24, 125, 503]
labels = ("even", "odd")
buckets = [list() for x in labels]
n = len(buckets)
for d in data:
buckets[d % n].append(d)
for label, bucket in zip(labels, buckets):
import re
from collections import defaultdict
def wordfreq(words):
freq = defaultdict(int)
for word in words:
freq[word] += 1

Keybase proof

I hereby claim:

  • I am lernisto on github.
  • I am lernisto (https://keybase.io/lernisto) on keybase.
  • I have a public key ASD_COor_N2aq_jjMqnMHoj4ntlMq4W2imfQnKBsDaND4wo

To claim this, I am signing this object:

@lernisto
lernisto / gist:871fb56d94ea6aaf9676
Created November 26, 2014 14:16
replica set startup log files, demonstrates slow start
$ mongod --port 3001 --dbpath data.1 --replSet rs1
Wed Nov 26 06:53:44.447 [initandlisten] MongoDB starting : pid=4991 port=3001 dbpath=data.1 64-bit host=harry
Wed Nov 26 06:53:44.447 [initandlisten] db version v2.4.9
Wed Nov 26 06:53:44.447 [initandlisten] git version: nogitversion
Wed Nov 26 06:53:44.447 [initandlisten] build info: Linux orlo 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 BOOST_LIB_VERSION=1_54
Wed Nov 26 06:53:44.447 [initandlisten] allocator: tcmalloc
Wed Nov 26 06:53:44.447 [initandlisten] options: { dbpath: "data.1", port: 3001, replSet: "rs1" }
Wed Nov 26 06:53:44.517 [initandlisten] journal dir=data.1/journal
Wed Nov 26 06:53:44.518 [initandlisten] recover : no journal files present, no recovery needed
Wed Nov 26 06:53:47.440 [initandlisten] preallocateIsFaster=true 32.44