Skip to content

Instantly share code, notes, and snippets.

@filipwodnicki
filipwodnicki / cookiecutter.sh
Created February 23, 2021 20:24
Create a new library with cookie cutter
# install CC
brew install cookiecutter
# make a new library
cookiecutter gh:ionelmc/cookiecutter-pylibrary
# run through config again
cookiecutter --overwrite-if-exists --config-file=<rendered_template>/.cookiecutterrc gh:ionelmc/cookiecutter-pylibrary
@filipwodnicki
filipwodnicki / polylines_to_polygons_in_qgis.md
Created September 23, 2020 11:11
Polylines to Polygons in QGIS

How to convert Linestrings to Polygons in QGIS

  1. Import Vector Layer
  2. Select Linestring Layer Vector > Geometry Tools > Extract Vertices
  3. Install Concave Hull extension
  4. Select Points layer, go to Concave Hull extension -> OK
  5. Save Polygon layer
Demo
# Convert notebook to slides
jupyter nbconvert notebook.ipynb --TagRemovePreprocessor.remove_input_tags='{"hide_input"}' --EmbedImagesPreprocessor.resize=small --to slides --post serve
# Set slides to -> Slide
# Set tags to "hide_input"
# Convert mov to mp4
ffmpeg -i demo.mov -vcodec h264 demo.mp4
@filipwodnicki
filipwodnicki / ffmpeg.sh
Created January 14, 2020 10:56
ffmpeg cheat sheet
# install ffmpeg
brew install ffmpeg
# convert .mov file to .mp4
ffmpeg -i demo.mov -vcodec h264 demo.mp4
@filipwodnicki
filipwodnicki / import_local_module.py
Created December 9, 2019 13:52
jupyter notebook import local module
# jupyter notebook import local module
import os
import sys
nb_dir = os.path.split(os.getcwd())[0]
if nb_dir not in sys.path:
sys.path.append(nb_dir)
@filipwodnicki
filipwodnicki / ml-pro-tips.py
Created November 4, 2019 10:05
Machine learning pro tips
# 1. Keep train, validation, and test data straight.
@filipwodnicki
filipwodnicki / pandas_cheatsheet.py
Created November 4, 2019 10:03
Pandas cheatsheet
# 1. Apply works with multiple arguments
## instead of this
binary_test["prediction"] = binary_test["sentence"].apply(lambda x: get_prediction(x, PROJECT_ID, BINARY_MODEL_ID))
## do this
binary_test["prediction"] = binary_test["sentence"].apply(get_predictions, project_id=PROJECT_ID, model_id=BINARY_MODEL_ID
@filipwodnicki
filipwodnicki / good_code.py
Created November 4, 2019 10:00
Good code practices
# 1. Use f-strings
#instead of this
name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id)
# do this
name = f'projects/{project_id}/locations/us-central1/models/{model_id}'
# 2. Explicitly name errors:
# instead of this
try:
import keras
# Integer to categorical
keras.utils.to_categorical(4, num_classes=5, dtype='int')
# pip cheatsheet
# pip install from requirements
pip install -r requirements.txt