Skip to content

Instantly share code, notes, and snippets.

@odedlaz
odedlaz / _PyBytes_Resize.c
Created December 1, 2016 10:30
_PyBytes_Resize
/* The following function breaks the notion that bytes are immutable:
it changes the size of a bytes object. We get away with this only if there
is only one module referencing the object. You can also think of it
as creating a new bytes object and destroying the old one, only
more efficiently. In any case, don't use this if the bytes object may
already be known to some other part of the code...
Note that if there's not enough memory to resize the bytes object, the
original bytes object at *pv is deallocated, *pv is set to NULL, an "out of
memory" exception is set, and -1 is returned. Else (on success) 0 is
returned, and the value in *pv may or may not be the same as on input.
@odedlaz
odedlaz / std_print.py
Created December 5, 2016 08:12
std_print.py
from time import time
import os
devnull = open(os.devnull, 'w')
name = "oded"
t = time()
for _ in range(50000):
print("my name is {} & 2*3={}".format(name, 2*3),
file=devnull)
@odedlaz
odedlaz / eval_print.py
Last active December 6, 2016 09:46
eval_print.py
import os
import six
from time import time
from inspect import currentframe
from string import Formatter
string_formatter = Formatter()
devnull = open(os.devnull, 'w')
@odedlaz
odedlaz / exec_print.py
Last active December 6, 2016 09:47
exec_print.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
@odedlaz
odedlaz / compiled_exec_print.py
Last active December 6, 2016 09:47
compiled_exec_print.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
@odedlaz
odedlaz / optimzed_compile_print.py
Last active December 6, 2016 10:13
optimzed_compile_print.py
import os
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
string_formatter = Formatter()
@odedlaz
odedlaz / compiled_print_func_snippet.py
Created December 6, 2016 08:59
compiled_print_func_snippet.py
__keywords = {}
__keywords[GENERATED_NAME] = STATEMENT
__keywords[ANOTHER_GENERATED_NAME] = ANOTHER_STATEMENT
@odedlaz
odedlaz / fast_local_compiled_print.py
Created December 6, 2016 09:01
fast_local_compiled_print.py
def awesome_print(text, **kwargs):
text = "a format with {GENERATED_NAME} and {ANOTHER_GENERATED_NAME}"
std_print(text.format(GENERATED_NAME=(STATEMENT), ANOTHER_GENERATED_NAME=(ANOTHER_STATEMENT), **kwargs))
@odedlaz
odedlaz / python_36_print.py
Created December 6, 2016 09:12
python_36_print.py
name = "oded"
age = 26
print("My name is: {name}, my age is: {age} and 2*3={2*3}!")
# My name is oded, my age is: 26 and 2*3=6!
@odedlaz
odedlaz / python_36_statements_whole_code.py
Last active December 6, 2016 10:14
python_36_statements_whole_code.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from types import CodeType, FunctionType
from functools import wraps
from string import Formatter