Skip to content

Instantly share code, notes, and snippets.

View zkan's full-sized avatar
🐻
Stay Hungry. Stay Foolish.

Kan Ouivirach zkan

🐻
Stay Hungry. Stay Foolish.
View GitHub Profile
import random
import unittest
from unittest.mock import patch
class TryMockUsingContextManagerTest(unittest.TestCase):
def test_mock_random_twice(self):
with patch('__main__.random.randrange') as mock_randrange:
with patch('__main__.random.randint') as mock_randint:
try_mock_using_context_manager()
from contextlib import ExitStack
import random
import unittest
from unittest.mock import patch
class TryMockUsingExitStackTest(unittest.TestCase):
def test_mock_random_twice(self):
with ExitStack() as stack:
mock_randrange = stack.enter_context(
import time
from celery import Celery
app = Celery('tasks', broker='redis://localhost:6379')
@app.task
def hello(name):
@zkan
zkan / tavern_workshop_at_pycon_thailand_2018
Last active June 17, 2018 04:58
tavern_workshop_at_pycon_thailand_2018
Hello
@zkan
zkan / second_gist
Created June 17, 2018 05:12
Add a gist using tavern
Woohoo I added a gist using tavern!
@zkan
zkan / __init__.py
Created July 4, 2018 00:45 — forked from timsavage/__init__.py
Customising Django Auth username length for Django 1.8+
default_app_config = 'myapp.auth.apps.MyAuthAppConfig'
import cv2
image = cv2.imread('simplesat.png')
print(type(image)) # <class 'numpy.ndarray'>
print(image.shape) # (224, 224, 3)
b, g, r = image[46, 46]
print(b, g, r) # 152 222 148
@zkan
zkan / life.py
Created August 4, 2018 00:22 — forked from jasonkeene/life.py
Python implementation of Conway's Game of Life
"""Python implementation of Conway's Game of Life
Somewhat inspired by Jack Diederich's talk `Stop Writing Classes`
http://pyvideo.org/video/880/stop-writing-classes
Ironically, as I extended the functionality of this module it seems obvious
that the next step would be to refactor board into a class with advance and
constrain as methods and print_board as __str__.
"""
object HelloWorld {
def main(args: Array[String]): Unit = {
println("From Zero to Hello World!")
}
}