Skip to content

Instantly share code, notes, and snippets.

@reinhrst
reinhrst / piplayer.yaml
Last active July 1, 2021 20:51
PipLayer
# Note: this snippet needs to be placed in the Resources section of a CloudFormation template
# By default this will create a layer for the python version that the custom resource lambda is running in, so if you want
# a layer for python 3.6, just replace the runtime of the PipLayerLambda.
# This gist accomanies an article on my blog: https://blog.claude.nl/tech/howto/2021/02/10/aws-lambda-python-with-packages-through-pip-in-cloudformation.html
PipLayerLambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
chosen unit smallest details (design resolution) maximum model size
mm (normal people) 10nm 10 thousand km (bridge from Ireland to New York)
metres (si people) 10μm 10 million km (model saturn plus all its rings)
nanometers (chip engineers?) 10 femtometre (12 protons) 10 metres
inches (imperials) 250nm 250 thousand km (space elevator)
feet (weird imperials) 3μm 3 million km (dyson sphere)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import timeit
import numpy as np
import pyopencl as cl
def setup(count):
return np.arange(3 * count, dtype="uint32").reshape((-1, 3)) & 0x3FF
np_setup_e2 = setup(100)
np_setup_e4 = setup(10000)
Intel Core i7 M1 with Rosetta M1 native i7 to M1 speedup
Python 100 1491.9 1471.4 953.3 1.56
Python 10k 1539.3 1535.3 1026.8 1.5
Python 1M 1534.6 1552.2 1008.9 1.52
Numpy 100 19.3 18.2 10.2 1.89
Numpy 10k 28.3 26.1 17.6 1.61
Numpy 1M 39.9 27.7 24.0 1.66
Python naive 100 7853.1 7848.6 5201.2 1.51
Python naive 10k 7894.0 7867.3 5126.9 1.54
Python naive 1M 7867.3 7878.1 5169.0 1.52
@reinhrst
reinhrst / gist:054685d84587c36edbd0b4200c41a9b0
Created September 25, 2018 09:12
Iterm2 open new tab and have it do something
tell application "iTerm"
activate
tell current window
set mytab to (create tab with default profile)
tell current session
write text "ls -la"
end tell
end tell
end tell
@reinhrst
reinhrst / dates.sh
Last active November 8, 2015 11:57
#!/bin/bash
# oneliner to print a range of dates, ending today
for i in $(seq -f %.0f $(date -j -f %Y-%m-%d 2015-10-15 +%s) $((24 * 60 * 60)) $(date +%s)); do date -jf %s $i +%Y-%m-%d; done
# and one in python
python -c "import datetime; date = datetime.date(2015, 10, 5); days = range((datetime.date.today() - date).days); print(' '.join(str(date + datetime.timedelta(day)) for day in days))"
@reinhrst
reinhrst / server.py
Last active February 26, 2016 15:18
Tornado async testing framework with asyncio and using your own server options
import tornado.web
import tornado.httpserver
def make_app():
app = tornado.web.Application(
[(r"/.*", PageHandler)],
debug=tornado.options.options.serverdebug,
cookie_secret=config.COOKIE_SECRET,
compress_response=True)
return app
@reinhrst
reinhrst / .vimrc
Created August 23, 2015 21:09
Vim function to quickly toggle between dict notation `a["x"]` and dot notation `a.x`. Uses vim-repeat in the end, to enable repeat
function DictDotToggle()
python << endpython
import re, vim
(row, col) = vim.current.window.cursor
line = vim.current.buffer[row - 1]
re_word = "(?P<word>[a-zA-Z_][a-zA-Z0-9_]*)"
dottedwords = re.finditer(r"\." + re_word, line)
for dottedword in dottedwords:
if dottedword.start("word") <= col and dottedword.end("word") > col:
new_line = (
@reinhrst
reinhrst / install_opencv3_python3_osx.sh
Last active September 21, 2016 03:25
Install opencv master (2015-04-02) on python 3 on OSX
brew install python3
pip3 install numpy
brew install cmake
git clone --depth=1 https://github.com/Itseez/opencv.git
cd opencv
mkdir build
cd build
# note: in the next line, adjust paths to point to the correct python version
cmake -DBUILD_opencv_python3=YES -DBUILD_opencv_python2=NO -DINSTALL_PYTHON_EXAMPLES=YES -DPYTHON3_EXECUTABLE=/usr/local/bin/python3 -DPYTHON3_INCLUDE_DIR=/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/include/python3.4m -DPYTHON3_LIBRARY=/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4.dylib -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.4/site-packages/numpy/core/include/ -DPYTHON3_PACKAGES_PATH=/usr/local/lib/python3.4/site-packages/ ..
make -j8