This file contains hidden or 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
# OSX specific install commands: | |
brew install pyenv | |
pyenv install 3.6.8 | |
# or if fails: | |
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 3.6.8 | |
# the rest of the commands work both on OSX and Linux: | |
virtualenv -p /Users/alex/.pyenv/versions/3.6.8/bin/python venv | |
source venv/bin/activate |
This file contains hidden or 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 org.scalatest.{Assertion, AsyncFlatSpec} | |
import scala.concurrent.{Future, Await} | |
import org.scalatest.Matchers._ | |
import scala.concurrent.duration._ | |
import scala.language.postfixOps | |
class FutureSpec extends AsyncFlatSpec { | |
// Overriding execution context is not required, unless you want to use Await. | |
// To avoid deadlocking the main thread you need to have multithreaded context. |
This file contains hidden or 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 numpy as np | |
def change_basis(v, dims): | |
""" | |
:param v: vector of any dimension | |
:param dims: basis of new dimension matching dimensions of v | |
:return: the same vector v in new coordinate space | |
""" | |
return [np.dot(v, x) / np.dot(x, x) for x in dims] |
This file contains hidden or 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
# Problem: given this data (xs) and value (x) find it's mapped str value ('SG', ...) | |
# Tuple format: (interval_start_inclusive, interval_end_inclusive, searched_value) | |
db = [(8123, 9888, 'SG'), (1, 1000, 'US'), (1001, 5045, 'CA')] | |
# Solution: sort once | |
db_sorted = sorted(db, key=lambda x: x[0]) | |
# Implement binary search (for practice purposes): | |
def binary_search(x, xs): | |
if not xs: |
This file contains hidden or 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
def height_min_max(tree): | |
if not tree: | |
return 0, 0 | |
else: | |
_, l, r = tree | |
lmin, lmax = height_min_max(l) | |
rmin, rmax = height_min_max(r) | |
return 1 + min(lmin, rmin), 1 + max(lmax, rmax) | |
This file contains hidden or 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
def max_subarray(xs): | |
if not xs: | |
return [], 0 | |
start = 0 | |
end = 1 | |
cur_sum = 0 | |
max_sum = xs[0] | |
for i in range(len(xs)): | |
tmp_sum = cur_sum + xs[i] | |
if xs[i] > tmp_sum: |
This file contains hidden or 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
{-# LANGUAGE NamedFieldPuns #-} | |
-- The Expression Problem and my sources: | |
-- http://stackoverflow.com/questions/3596366/what-is-the-expression-problem | |
-- http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/ | |
-- http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/ | |
-- http://www.ibm.com/developerworks/library/j-clojure-protocols/ | |
-- To begin demonstrating the problem, we first need some |
This file contains hidden or 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
object Main extends App { | |
import math._ | |
// The Expression Problem and my sources: | |
// http://stackoverflow.com/questions/3596366/what-is-the-expression-problem | |
// http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/ | |
// http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/ | |
// http://www.ibm.com/developerworks/library/j-clojure-protocols/ | |
This file contains hidden or 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
set_of_1 = lambda i: i == 1 | |
set_of_1(1) | |
set_of_1(2) | |
empty = lambda i: False | |
empty(1) |
This file contains hidden or 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
sudo dnf install docker | |
# Start/enable service | |
sudo systemctl start docker | |
sudo systemctl enable docker | |
# Allow docker to run without sudo/root privs | |
sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo systemctl restart docker | |
newgrp docker |