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
import time | |
def speed_test(func): | |
def wrapper(*args, **kwargs): | |
t1 = time.time() | |
for x in xrange(5000): | |
results = func(*args, **kwargs) | |
t2 = time.time() | |
print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) | |
return results |
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
import math | |
class MyClass: | |
def method(self): | |
return 'instance method called', self | |
@classmethod | |
def classmethod(cls): | |
return 'class method called',cls |
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
import os | |
from pathlib import Path | |
with open('data.txt', 'w') as f: | |
data = 'some data to be written in a file' | |
f.write(data) | |
with open('data.txt', 'r') as f: | |
data = f.read() |
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
export default function Counter() { | |
const [count, setCount] = useState(0); | |
function handleClick() { | |
setCount(count +1); | |
} | |
return ( | |
<button onClick = {handleClick}> | |
You pressed me {count} times |