This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
import json | |
from flask import url_for | |
class CachedUrlFor(): | |
def __init__(self): | |
self._cache = defaultdict(dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const simplify = sample => { | |
let deDup = []; | |
for (let current of sample) { | |
deDup[current] = true; | |
} | |
return Object.keys(deDup) | |
.map(i => +i) | |
.sort((a, b) => a - b); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* genRange(start, stop) { | |
let curr = 0; | |
while (curr < stop) yield curr++; | |
} | |
const gen = genRange(0, 3); | |
console.log("generator:"); | |
for (let i of gen) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.6 | |
# create working directory | |
RUN mkdir -p /usr/src/app | |
RUN mkdir -p /usr/src/py | |
# install virtualenv globally | |
RUN pip install virtualenv | |
# create app user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import ReactTable from "react-table"; | |
import "react-table/react-table.css"; | |
class App extends Component { | |
// Constructor is not needed if you don't need to compute initial state | |
state = { data: [] }; | |
indexData = (item, index) => ({ ...item, id: index + 1 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEBUG = JSON.parse(process.env.DEBUG) || false; | |
const logger = wrapped => (...args) => { | |
const results = wrapped(...args); | |
if (DEBUG) { | |
console.log(`Function: ${wrapped.name}; ${args} => ${results}`); | |
} | |
return results; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const benchmark = arr => { | |
arr = arr | |
? arr | |
: [...Array(1000)].map(() => Math.floor(Math.random() * 1000)); | |
const versions = [ | |
{ arr: [...arr], title: "Random" }, | |
{ arr: [...arr.sort((a, b) => a - b)], title: "Sorted" }, | |
{ arr: [...arr.reverse()], title: "Reversed" }, | |
{ arr: new Array(1000).fill(8), title: "Equal" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const radixSort = arr => { | |
const maxNum = Math.max(...arr) * 10; | |
let divisor = 10; | |
while (divisor < maxNum) { | |
let buckets = [...Array(10)].map(() => []); | |
for (let num of arr) { | |
buckets[Math.floor((num % divisor) / (divisor / 10))].push(num); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start with an unsorted array | |
[95, 93, 36, 74, 33] | |
// Place them in the appropriate buckets for the least significant digit | |
{3: [93, 33], 4: [74], 5: [95], 6: [36]} | |
// And extract them back into an array | |
[93, 33, 74, 95, 36] | |
// Repeat for the next significant digit | |
{3: [33, 36], 4: [43], 7: [74], 9: [93, 95]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const quickSort = arr => { | |
if (arr.length < 2) return arr; | |
const pivot = arr[Math.floor(Math.random() * arr.length)]; | |
let left = []; | |
let equal = []; | |
let right = []; | |
for (let element of arr) { |
NewerOlder