Skip to content

Instantly share code, notes, and snippets.

View savish's full-sized avatar
🎯
Focusing

Alan K savish

🎯
Focusing
  • Intelligent Routing
  • Pretoria
View GitHub Profile
@savish
savish / mocker.py
Last active July 17, 2021 18:29
Swap out a function based on the runtime environment
import os
def mock(mock_func):
def decorate_inner(func):
# Feel free to use functools wraps to preserve introspection info
def inner(*args, **kwargs):
if os.environ.get("ENV") == "test":
return mock_func(*args, **kwargs)
else:
@savish
savish / roman.exs
Last active December 30, 2017 06:41
Generate decimal numbers from roman numbers (basic, no validation)
defmodule Roman do
@values [i: 1, v: 5, x: 10, l: 50, c: 100, d: 500, m: 1000]
@valid_transitions %{
m: [:c, :d, :l, :x, :v, :i],
d: [:c, :l, :x, :v, :i],
c: [:m, :d, :c, :l, :x, :v, :i],
l: [:x, :v, :i],
x: [:c, :l, :x, :v, :i],
v: [:i],
@savish
savish / listmatrix.py
Last active April 11, 2017 13:46
List matrix thingy
vals = [1,2,3]
def afunc(v1, v2):
return v1 * v2
for k in vals:
for j in vals:
print(afunc(k, j))
# Result