Skip to content

Instantly share code, notes, and snippets.

View martin-wintz's full-sized avatar

Martin Wintz martin-wintz

View GitHub Profile

In the past 7 months I've gone from hating running to being a runner, from running 6 miles straight for the first time in my life to running a 43:22 10k, from running 5-10 miles a week to 40+. Here are the most important things I've learned.

Improve your cadence

Your feet should hit the ground this often, even if you are going slow. This is the single easiest and most valuable improvement you can make to all aspects of your running. This might not feel natural at first, so you have to be intentional about it.

Build a base of easy weekly miles and run slow

If you're starting out totally untrained, some sort of alternating running/walking program is the best way to start. C25K seems to be the most popular one.

@martin-wintz
martin-wintz / gist:085021ef22eafcd280ee
Last active August 29, 2015 14:22
Scheduling Abstraction Architecture
// Scheduler interface
function Scheduler () {}

// After this is called, distribution will go out to its channel on publishDate
Scheduler.prototype.schedule = function (distribution) { throw new NotImplementedError(); }

// If this is called on a scheduled distribution, the distribution will not go out
Scheduler.prototype.unschedule = function (distribution) { throw new NotImplementedError(); }
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 1
---

`_processRequest` is unecessary indirection. People expect methods to get called, not pass in as parameters.

If we want to factor out `parseJson`, we should make a patched version of the request methods that automatically parse json, that way we reduce duplication without introducing a confusing method call.

---

These tests don't do anything. Not only are they broken because even though they are asynchronous, the done() parameter isn't being used, but even when I get them working, I can delete most of the method body and still get the tests to pass.

This actually does very little as far as refactorings go. Lines 276, 279, 283 are essentially the only things that are deduplicated. The rest is still duplicated, just within the function instead of in two separate functions.

The result is that there isn't really much gain. Theoretically, if you wanted to implemented a third field that works similarely to settings/preferences, you couldn't reuse this method. You'd have to walk through it, try to understand what it does, and add the appropriate if statements and so forth. No abstraction was really created.

I personally couldn't understand what the differences were between the two objects based on this, so I refactored it as I went through:

// This object is a good reflection of the key differences between these two objects
// We can then effectively ask ourselves why these differences exist:
var perOrganizationUserDataMapping = {
@martin-wintz
martin-wintz / gist:7933420
Last active December 31, 2015 04:19
asyncWithRetry
// Takes an asynchronous function func and returns an asynchronous function decoratedFunc that
// calls func until it either runs out of tries or doesn't pass an error into the callback
// makes numRetries available as the last argument in func
var asyncWithRetry = function (func, numRetries) {
var decoratedFunc = function () {
var currentRetry, args, callback, newCallback, callbackArgs, err;
currentRetry = 0;
args = Array.prototype.slice.call(arguments, 0);
@martin-wintz
martin-wintz / word-puzzle.py
Last active December 15, 2015 08:09
Little word puzzle solver: save as python script and run with -h for usage
import re
import argparse
def getSortedLetterList(wordList):
# Calculate the frequency with which characters appears in the dictionary
letterCount = {}
totalCount = 0
for word in wordList:
@martin-wintz
martin-wintz / ui-sortable-connectwith-compatible.coffee
Last active December 10, 2015 09:39
Changes to ui-sortable for compatibility with ConnectWith option.
onStart = (e, ui) ->
# Save position of dragged item, original model, and original element parent
ui.item.data('ui-sortable-start', ui.item.index())
ui.item.data('ui-sortable-start-model', ngModel)
ui.item.data('ui-sortable-start-parent', ui.item.context.parentElement)
onUpdate = (e, ui) ->
# Fetch saved and current position of dropped element
start = ui.item.data('ui-sortable-start')
end = ui.item.index()