Skip to content

Instantly share code, notes, and snippets.

@erans
erans / get_lat_lon_exif_pil.py
Created May 20, 2011 21:16
Get Latitude and Longitude from EXIF using PIL
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
@halilim
halilim / move_heroku_pg_to_aws_rds.md
Last active February 22, 2021 14:13
Move Heroku Postgres to Amazon AWS RDS
  1. Prepare your RDS instance and [authorize access to it][1] (basically make it public).

  2. Put your app in maintenance mode:

    heroku maintenance:on
  3. Save the latest SQL dump of the DB:

@catherinekerr
catherinekerr / README.md
Last active December 5, 2023 09:28
D3 with embedded SVG map

Embedding SVG Map

This example uses a map that was created in Adobe Illustrator and exported as an SVG file. Although it might be preferable to use GeoJSON files for geographical maps, they are not always available in the detail that is required. In any case, we could be using any irregular shaped SVG graphic created by an application like Illustrator - this example shows how to embed the SVG into D3 and bind data to the paths.

The SVG file is quite simple. Each county is identified by a path and an id. Some paths are grouped together to denote Northern Ireland and the Republic. The path titles are dynamically created in the program.

The data in this case comes from the Irish Central Statistics Office and gives the average rental prices for houses/apartments in each county in the Republic of Ireland in 2015. The map is a chloropleth using a quantize scale. Another useful feature of this example is the zoom and center feature which centers the county's bounding box in the

@mayukh18
mayukh18 / flask_setup_heroku.md
Created September 28, 2017 19:38
How to setup flask app with database on heroku

Setting up flask app in heroku with a database

The below article will cover the intricacies of setting up databases and heroku in respect to a flask app. This is more like a memo and will have out of sequence instructions or solutions to errors so read thoroughly.

Setting up a database

You'll need the packages

Preface

This article walks you through an example of deploying a Python 3.6 application that uses Pandas and AWS S3 on AWS Lambda using Boto3 in Python in 2018. No shell, no bash, no web console, everything is automated in Python. The previous article of a Hello World example can be found here.

Again, the reason to use Python Boto3 to interact with AWS is that,

  1. I'm more familiar with Python than Bash, which means a Python script can be more flexible and powerful than Bash for me.
  2. I'm not a fun of the AWS web console. It might be easier to do certain things, but it is definitely not automated.

Introduction

@MichaelSimons
MichaelSimons / RetrievingDockerImageSizes.md
Last active July 16, 2024 09:04
Retrieving Docker Image Sizes

Retrieving Docker Image Sizes

There are two metrics that are important to consider when discussing the size of Docker images.

  1. Compressed size - This is often referred to as the wire size. This affects how fast/slow images can be pulled from a registry. This impacts the first run experience on machines where images are not cached.
  2. Uncompressed size - This is often referred to as the size on disk. This affects how much local storage is required to support your Docker workloads.

The example commands shown below will work on Windows, MacOS, and Linux.

How to Measure the Compressed Size

@frankie567
frankie567 / cloudflare_stream_token.py
Created December 28, 2021 14:50
Generate signed tokens for Cloudflare Stream in Python
import base64
from datetime import datetime
from jwcrypto import jwt, jwk # pip install jwcrypto
b64_jwk = "XXXX" # Base64-encoded JWT you get from Cloudflare Stream API (https://developers.cloudflare.com/stream/viewing-videos/securing-your-stream#step-1-call-the-streamkey-endpoint-once-to-obtain-a-key)
jwk_key = jwk.JWK.from_json(base64.b64decode(b64_jwk))
def get_video_token(video_id: str, lifetime: int = 3600) -> str:
header = {"kid": jwk_key["kid"], "alg": "RS256"}