Skip to content

Instantly share code, notes, and snippets.

@ryderdamen
ryderdamen / Dockerfile
Created January 21, 2020 19:24
The Dockerfile for running our cat facts app.
FROM python:3.7-alpine
WORKDIR /code
COPY ./src/requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt
COPY ./src .
CMD ["app.py"]
@ryderdamen
ryderdamen / requirements.txt
Created January 21, 2020 17:58
An example requirements.txt file for our flask app that displays cat facts.
flask
requests
@ryderdamen
ryderdamen / app.py
Last active January 21, 2020 19:26
An example flask application for retrieving and displaying facts about cats.
import os
from flask import Flask, render_template
import requests
app = Flask(__name__)
def get_cat_fact():
cat_facts_url = 'https://catfact.ninja/fact'
response = requests.get(cat_facts_url)
@ryderdamen
ryderdamen / config.yml
Created January 20, 2020 17:12
An example CircleCI Config file for deploying a Google Cloud Function
version: 2
jobs:
deploy:
docker:
- image: google/cloud-sdk
steps:
- checkout
- run:
name: Authorize GCloud Command Line Tool
command: |
@ryderdamen
ryderdamen / test_connection_to_redis.py
Created October 22, 2019 15:01
An example of a function that tests if a connection to Redis can be established.
import os
import redis
def can_connect_to_redis():
if not os.environ.get('REDIS_URL'):
return False
try:
conn = redis.from_url(os.environ.get('REDIS_URL'))
conn.ping()
return True
@ryderdamen
ryderdamen / calculating_takeoff_distance_cessna_150.md
Last active February 28, 2022 19:56
An example of how to calculate takeoff distance for a Cessna 150. This is an example only.

Calculating Takeoff Distance - Cessna 150

This document is an example for how to calculate takeoff distance for a Cessna 150. Please note, this is an example only. Consult the Pilot Operating Handbook (POH) for your particular airplane for doing real-life calculations. This example assumes you are a Canadian pilot - the logic is all the same as everywhere else, the lookup locations are different.

Summary

To calculate landing distance, the following general steps need to be done.

  1. Calculate pressure altitude
  2. Calculate temperature at altitude
  3. Calculate headwind component
  4. Look up and calculate takeoff distance
@ryderdamen
ryderdamen / triggering_cron_job_manually_on_kubernetes.md
Last active March 6, 2024 15:07
How to trigger a Cron Job manually on Kubernetes

Triggering a Cron Job manually on Kubernetes

So you've defined a cronjob.yaml manifest, but it doesn't run until midnight and you want to test it now? Simply replace the variables, and run the following command to create a job from the cronjob.

kubectl create job --from=cronjob/{{ cron_job_name }} {{ the-name-of-this-one-off-job }}

This will create a one-off job in your cluster based on your cronjob.yaml manifest, which might look something like this.

apiVersion: batch/v1beta1
# Standard Neo4J Reverse Proxy Docker Container
# Forwards traffic to Neo4J Docker Container (with mounted TLS certs)
server {
server_name example.com;
location / {
proxy_pass http://0.0.0.0:7474;
proxy_set_header Host $host;
proxy_redirect off;
@ryderdamen
ryderdamen / gce-to-gcs-uploads.md
Created December 4, 2018 15:43
Uploading Files from Google Compute Engine (GCE) VMs to Google Cloud Storage (GCS)

Uploading Files from Google Compute Engine (GCE) VMs to Google Cloud Storage (GCS)

I had a bit of trouble trying to configure permissions to upload files from my Google Compute Engine instance to my Google Cloud Storage bucket. The process isn't as intuitive as you think. There are a few permissions issues that need to be configured before this can happen. Here are the steps I took to get things working.

Let's say you want to upload yourfile.txt to a GCS bucket from your virtual machine. You can use the gsutil command line tool that comes installed on all GCE instances.

If you've never used the gcloud or gsutil command line tools on this machine before, you will need to initialize them with a service account.