Skip to content

Instantly share code, notes, and snippets.

@gillibrand
Last active January 2, 2016 01:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gillibrand/8233738 to your computer and use it in GitHub Desktop.
Save gillibrand/8233738 to your computer and use it in GitHub Desktop.
A custom preprocessor for Marked.app that makes it into a super simple time tracker. Finds all the hours in a document (e.g., +1h, +2h, +3h, etc.) and shows the total in a floating badge. Only looks for whole number hours (no minutes or fractions). See a screenshot at http://cl.ly/TB7D
#!/usr/bin/env python
import sys, re
hours_re = re.compile(r'([-+] \d+)h \b', re.X)
total = 0
for line in sys.stdin:
total += sum(int(hour) for hour in hours_re.findall(line))
print line.strip()
print """
<style>
.total {
position: fixed;
top: 0px;
right: 10px;
background-color: #ff6f08;
color: white !important;
border-radius: 5px;
padding: 4px 6px !important;
line-height: normal;
}
</style>
<h3 class="total">%s hours</h3>
""" % (total)
@gillibrand
Copy link
Author

Updated to process a line at a time instead of buffering the entire file in memory. Should be faster on very large files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment