Skip to content

Instantly share code, notes, and snippets.

View ololobus's full-sized avatar
👹

Alexey Kondratov ololobus

👹
View GitHub Profile
@ololobus
ololobus / dijkstra-functional-way.py
Last active August 29, 2015 14:05
Dijkstra algorithm
graph = [[0, 7, 9, -1, -1, 14], [7, 0, 10, 15, -1, -1], [9, 10, 0, 11, -1, 2], [-1, 15, 11, 0, 6, -1], [-1, -1, -1, 6, 0, 9], [14, -1, 2, -1, 9, 0]]
start = 3
def dijkstra(graph, start):
r = range(len(graph))
def perform(results, work_results, visited, path, current):
tested = set(filter(lambda i: (graph[current][i] >= 0) and not visited[i] and ((results[current] + graph[current][i]) < results[i]), r))
@ololobus
ololobus / README.md
Last active August 29, 2015 14:04
bem-history doc

bem-history

EN

What is this?

BEM wrap for History API:

  • supports browsers with a native History API and hashchange event;
  • provides manipulations with url, browser location and history in the terms of BEM (http://bem.info/).
@ololobus
ololobus / url-parsing-speed.js
Last active August 29, 2015 13:55
Small script for a measurement of url parsing speed by RegEx and by <a> DOM-element
function parseByRegEx (url) {
var parser = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
parserKeys = ['source', 'protocol', 'authority',
'userInfo', 'user', 'password', 'host', 'port',
'relative', 'path', 'directory', 'file', 'query', 'anchor'],
m = parser.exec(url || ''),
parts = {};
parserKeys.forEach(function(key, i) {
parts[key] = m[i] || '';