Skip to content

Instantly share code, notes, and snippets.

@mdipierro
mdipierro / fileio.js
Created February 2, 2013 04:11
HTML5 JS that allows saving and loading client side of any textarea. The example assume jQuery but fileio.js does not need jQuery.
/* example:
<script src='fileio.js'>
<script>FileIO.check_browser()</script>
<textarea id="code">
hello world
</textarea>
<a href="#" id="load-button">Load</a>
<a href="#" id="save-button" onclick="FileIO.save(jQuery('#code').val())">Save</a>
<script>FileIO.load('load-button',function(f){jQuery('#code').val(f.result)})</script>
@mdipierro
mdipierro / get_time_slices
Created December 4, 2012 17:47
Given a start_date/stop_date and start_time/stop_date and a set of weekdays, returns all hourly time intervals in that range
def get_time_slices(vars):
slices = []
nd = (vars.stop_date - vars.start_date).days
weekdays = [k for k,name in enumerate('monday|tuesday|wednesday|thusrday|friday|saturday|sunday'.split('|')) if vars.get(name)]
hours = vars.stop_time.hour - vars.start_time.hour
for d in range(nd):
day = vars.start_date + timedelta(days=d)
if day.weekday() in weekdays:
zero = datetime(day.year, day.month, day.day,
vars.start_time.hour,