Skip to content

Instantly share code, notes, and snippets.

View linkdd's full-sized avatar
🙂

David Delassus linkdd

🙂
View GitHub Profile
@linkdd
linkdd / README.md
Last active February 5, 2024 11:21
Python Django Dockerfile

Python Django Dockerfile

When setting up a Python/Django project, I like to do a few things:

  • use poetry to manage dependencies and virtualenv
  • use poe to manage tasks (similar to node's scripts)
  • split the django settings.py into multiple files, with one per environment (similar to Elixir compile-time config)
  • use gunicorn and whitenoise to serve the application
  • use a multi-stage Dockerfile making heavy use of the docker layer cache to avoid running intensive steps needlessly
  • use django-tailwind and django-anymail
@linkdd
linkdd / return-generator.rs
Created May 11, 2022 09:29
Return Rust generator from function
use genawaiter::{sync::gen, yield_, Generator};
type MyGen = Box<dyn Generator<Yield = i32, Return = i32>>;
fn make_generator() -> MyGen {
let gen = gen!({
yield_!(1);
yield_!(2);
yield_!(3);
4
@linkdd
linkdd / generators.rs
Created May 11, 2022 09:23
Rust generators (genawaiter)
use genawaiter::{sync::gen, yield_, GeneratorState};
let gen = gen!({
yield_!(1);
yield_!(2);
yield_!(3);
4
});
assert_eq!(gen.resume(), GeneratorState::Yielded(1));
@linkdd
linkdd / generators.py
Created May 11, 2022 09:08
Python Generators
def my_generator():
yield 1
yield 2
yield 3
return 4
gen = my_generator()
next(gen) # 1
next(gen) # 2
next(gen) # 3
@linkdd
linkdd / defer-frame.hpp
Created February 7, 2022 14:30
Golang's defer feature for your C++ functions.
#pragma once
#include <functional>
#include <vector>
#include <algorithm>
class defer_frame {
public:
using function = std::function<void(void)>;
@linkdd
linkdd / github-workflow-step-kind.yml
Created January 23, 2022 03:16
Example of KinD cluster creation in a Github Workflow
- name: setup@kindconfig
run: |
kind_in="${{ github.workspace }}/.github/config/kind.yml.in"
kind_out="${{ github.workspace }}/.github/config/kind.yml"
hostip=$(sh .github/scripts/get-docker-host.sh)
sed "s/127.0.0.1/$hostip/g" $kind_in > $kind_out
- name: setup@kubernetes
uses: engineerd/[email protected]
with:
@linkdd
linkdd / kind-cluster-config.yml
Created January 23, 2022 03:14
Example of KinD cluster configuration
---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "127.0.0.1"
@linkdd
linkdd / github-workflow-step-kubeconfig.yml
Created January 23, 2022 03:08
Github Workflow Step to edit the KinD generated kubeconfig for use inside a Docker container
# uses script from https://gist.github.com/linkdd/4bbd9fc4966e00e067305f1fb8c2588c
- name: setup@kubeconfig
run: |
hostip=$(sh .github/scripts/get-docker-host.sh)
sed "s/127.0.0.1/$hostip/g" $HOME/.kube/config > ${{ github.workspace }}/kubeconfig.yml
@linkdd
linkdd / get-docker-host.sh
Created January 23, 2022 03:05
Get Docker Host IP Address
#!/bin/sh
cat <<EOF | docker run --rm -i alpine:latest sh
apk add --no-cache iproute2 >/dev/null
ip -4 route show default | cut -d' ' -f3
EOF
@linkdd
linkdd / Dockerfile
Created October 19, 2021 10:51
Example Dockerfile for Elixir/Phoenix project
## Layers containing files for the next stages
# Project configuration
FROM scratch AS context
ADD mix.exs mix.lock /workspace/
ADD config /workspace/config
# Asset files
FROM scratch AS assets