Skip to content

Instantly share code, notes, and snippets.

@Fedjmike
Fedjmike / with_request_values_positionally.py
Last active November 30, 2016 17:11
with_request_values_positionally
@decorator_with_args
def with_request_values_positionally(view, keys=[], optional_keys=[],
error_view=request_by_json_missing_value):
try:
values = [request.values[key] for key in keys]
#Only catch a KeyError from that particular lookup, not the whole view function
except KeyError:
return error_view()
@Fedjmike
Fedjmike / relative_datetime.py
Created January 1, 2017 22:31
Concise and precise relative datetime
def relative_datetime(then):
delta = arrow.now() - then
years, days_of_year = delta.days // 365, delta.days % 365
months_of_year, days_of_month = days_of_year // 30, days_of_year % 30
hours_of_day, seconds_of_hour = delta.seconds // (60*60), delta.seconds % (60*60)
minutes_of_hour, seconds_of_minute = seconds_of_hour // 60, seconds_of_hour % 60
if years != 0:
@Fedjmike
Fedjmike / README.md
Last active October 30, 2018 18:01 — forked from cjrd/README.md
Interactive tool for creating directed graphs using d3.js.

directed-graph-creator

Interactive tool for creating directed graphs, created using d3.js.

Demo: http://bl.ocks.org/cjrd/6863459

Operation:

  • drag/scroll to translate/zoom the graph
#!/usr/bin/env python3
import sys, os
def fix_eol(filename):
with open(filename) as f:
contents = f.read()
if not contents.endswith("\n"):
contents += "\n"