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
#!/usr/bin/env python3 | |
from collections import deque | |
from dataclasses import dataclass, field | |
from typing import Set, Optional, List, Generator, Dict, Deque | |
from unittest import TestCase, main | |
@dataclass | |
class GraphNode: | |
label: str |
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
#!/usr/bin/env python3 | |
from collections import deque, defaultdict | |
from dataclasses import dataclass | |
from typing import Generator, Optional, Deque, List, Tuple, DefaultDict | |
from unittest import TestCase, main | |
@dataclass | |
class BinaryTree: | |
value: int |
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
#!/usr/bin/env bash | |
set -euo pipefail # See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
IFS=$'\n\t' | |
if [[ -d ~/.portable-pypy ]]; then | |
echo "Directory already exists: ~/.portable-pypy" | |
exit 0 | |
fi | |
echo "Installing portable pypy for user '${USER}' at location '${HOME}/.portable-pypy'" |
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
#!/usr/bin/env node | |
// | |
// Count the number of comparisons required by quicksort using the following | |
// three pivot-selection strategies: | |
// | |
// 1. Always pick the first element. | |
// 2. Always pick the last element. | |
// 3. Pick the median of the first, last, and middle elements. If the list | |
// length is even, pick the element with the smaller index. | |
// |
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
#!/usr/bin/env node | |
// | |
// The point of this program is to count the number of inversions in a list of | |
// integers using merge sort. The number of inversions can be used to calculate | |
// similarity between two ranked lists. | |
// | |
// For example, consider a case where two people are asked to rank a list of 10 | |
// movies by some qualitative measure. We can use the sorted list from | |
// [1,...,10] to represent the first person's rankings, where the numbers 1-10 | |
// represent the movies they've chosen to inhabit those ranks. The second |
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
// | |
// Component with ES2015 features | |
// | |
import React, {PropTypes} from 'react'; | |
const List = React.createClass({ | |
propTypes: { | |
items: PropTypes.array.isRequired, | |
onItemClick: PropTypes.func.isRequired |
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
// Given a random array of words, find all duplicates of words and return the | |
// 1st "n" in order from most frequent to least frequent (words with identical | |
// frequency would be listed alphabetically) | |
/** | |
* Find the most frequent words in an array of words | |
* | |
* @param {array} words - The list of words | |
* @param {number} n - The number of results to show | |
* @return {array} - An array of word+count objects, sorted |
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
// | |
// Find all permutations of a string using base case & build approach | |
// | |
// See: https://en.wikipedia.org/wiki/Permutation | |
// | |
'use strict'; | |
if (!String.prototype.splice) { | |
/** | |
* @method - Add "splice" to String |
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
// | |
// Compute the distance between two points using the Haversine formula | |
// | |
// See: https://en.wikipedia.org/wiki/Haversine_formula | |
// | |
// Example: geoCoordDistance( | |
// {lat: '48° 12′ 30″ N', lng: '16° 22′ 23″ E'}, | |
// {lat: '23° 33′ 0″ S', lng: '46° 38′ 0″ W'} | |
// ) => 10130 | |
// |
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
/** | |
* Google Color Palette: http://www.google.com/design/spec/style/color.html | |
*/ | |
$materialize-red-lighten-5: #fdeaeb; | |
$materialize-red-lighten-4: #f8c1c3; | |
$materialize-red-lighten-3: #f3989b; | |
$materialize-red-lighten-2: #ee6e73; | |
$materialize-red-lighten-1: #ea454b; | |
$materialize-red-base: #e51c23; |
NewerOlder