Skip to content

Instantly share code, notes, and snippets.

View aychedee's full-sized avatar

Hansel Dunlop aychedee

View GitHub Profile
@aychedee
aychedee / fast_and_slow_tests.py
Last active February 13, 2018 17:52
Fast and slow tests using pytest
import pytest
import requests
def my_fast_func(x, y):
return x * y
@pytest.mark.slow
def test_talk_to_network():
assert requests.get('https://example.com').status_code == 200

Keybase proof

I hereby claim:

  • I am aychedee on github.
  • I am hansel (https://keybase.io/hansel) on keybase.
  • I have a public key whose fingerprint is 0FAB 8D01 5F59 F50D B5F2 1B39 391F 05C7 7331 1A40

To claim this, I am signing this object:

@aychedee
aychedee / reverse_sentence.py
Last active December 16, 2015 02:29
Problem of the week (April 10)
print """
sentence = 'Coding for Interviews contains too many gifs.'
broken = sentence.split()
broken.reverse()
reversed = ' '.join(broken)
assert reversed == 'gifs. many too contains Interviews for Coding'
print reversed
"""
@aychedee
aychedee / url_regex.py
Last active December 15, 2015 14:39
Regex to flexibly match anything that looks url like
import re
url_regex = re.compile(r"""[^\s] # not whitespace
[a-zA-Z0-9:/\-]+ # the protocol and domain name
\.(?!\.) # A literal '.' not followed by another
[\w\-\./\?=&%~#]+ # country and path components
[^\s] # not whitespace""", re.VERBOSE)
test_corpus = """
http://www.example.com and some text. www.example.com/?q=4897&7845%20 example.co.nz example.com/#my-tab
@aychedee
aychedee / gist:5244147
Last active September 8, 2021 10:47
Demonstration running a test multiple times using unittest
import unittest
import random
class NullWriter(object):
def write(*_, **__):
pass
def flush(*_, **__):
pass
import unittest
class A(unittest.TestCase):
def postMessages(self):
print "i post messages in the server!"
class B(A):
@classmethod
def setUpClass(cls):