Skip to content

Instantly share code, notes, and snippets.

View linkdd's full-sized avatar
🙂

David Delassus linkdd

🙂
View GitHub Profile
@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/setup-kind@v0.5.0
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
@linkdd
linkdd / hackernews-new-comms.js
Last active September 20, 2021 22:52
Add a bell emoji to unread comments on HackerNews
// Can be used with https://github.com/xcv58/Custom-JavaScript-for-Websites-2
// This snippet is released under the terms of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/deed.en
const cache_key = 'hn_comments_views'
const cache = JSON.parse(localStorage.getItem(cache_key) || '{}')
document.querySelectorAll('.athing.comtr').forEach(comm => {
if (!cache[comm.id]) {
const span = document.createElement('span')
span.innerHTML = '&#x1f514;' // :bell: emoji
@linkdd
linkdd / config.exs
Created September 14, 2021 22:39
Example of datapio_cluster_config
import Config
config :datapio_cluster,
service_name: [env: "MYAPP_SERVICE_NAME", default: nil],
app_name: [env: "MYAPP_APP_NAME", default: "my_app"],
cache_tables: [
some_set: [:id, :attr1, :attr2],
some_other_set: [:id, :attr]
]
@linkdd
linkdd / mix.exs
Created September 14, 2021 22:30
Sample Mix project configuration with datapio_cluster
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()