Skip to content

Instantly share code, notes, and snippets.

View Faheetah's full-sized avatar

William Normand Faheetah

View GitHub Profile
@Faheetah
Faheetah / install.sh
Created September 15, 2023 16:30
Install containerd and nerdctl on Ubuntu
# Note: can also just install nerdctl-full
sudo apt-get update
sudo apt-get install containerd
wget https://github.com/containerd/nerdctl/releases/download/v1.5.0/nerdctl-1.5.0-linux-amd64.tar.gz
tar -zxf nerdctl-1.5.0-linux-amd64.tar.gz nerdctl
sudo mv nerdctl /usr/bin/nerdctl
rm nerdctl-1.5.0-linux-amd64.tar.gz
@Faheetah
Faheetah / Jenkinsfile.groovy
Last active March 6, 2024 18:14
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
@Faheetah
Faheetah / Dockerfile
Last active October 19, 2022 15:22
Docker patterns/anti-patterns
### Generic Dockerfile demonstrating good practices
### Imports
# Bad-ish, we do not need Ubuntu for this, nor do we want latest if we are using in a build system, predictable is better
FROM ubuntu:latest
# Better, using a small image since our app has no dependency on Ubuntu
FROM alpine:3.3
@Faheetah
Faheetah / module.sh
Last active March 18, 2022 01:01
Ansible bash module boilerplate
#!/bin/bash
# Source arguments from Ansible
# These are passed into the module as $1 with a key=value format
# Sourcing this file sets the variables defined in the Ansible module
# Note that variables that are unused in the module are silently ignored
source $1
# Helper function to fail the module with the specified error
# This can accept $@ in printf for the full error
@Faheetah
Faheetah / README.md
Created March 15, 2022 16:29
Add Tailwind to Phoenix

Make all the changes described in these files. Delete assets/css/phoenix.css as it is no longer used.

  • config/dev.exs
  • assets/package.json
  • assets/postcss.config.js
  • assets/tailwind.config.js
  • assets/css/app.css
  • mix.exs
@Faheetah
Faheetah / README.md
Created May 1, 2021 18:00
Log commands to a .history file for repos

A problem with repositories is sometimes you do not remember what commands you ran to bootstrap the application, or what generators were used. A history file similar to .bash_history would be handy for a per-project basis. The h command above provides a wrapper around this functionality. It should be portable across any system with bash.

Run a command and write out the command to the git project's .history file, this logs $@ to .history

$ h mix phx.new project_name
$ h mix deps.get
$ h mix ecto.create
$ cat .history
mix phx.new project_name
# set a loop for running commands, will run unit tests on enter
while read; do go test ./...; done
# set a loop that runs once a second (like watch), can be used in cases watch doesn't fit as well
while sleep 1; do ls; done
# do something with the previous command
pwd
ls $(!!) # equivalent to ls $(pwd)
nothing:
literally_nothing:
@Faheetah
Faheetah / README.md
Last active September 29, 2021 19:26
Golang: pass in a struct and a map and retrieve values

This is handy for cases such as needing to dynamically assign structs, for example when use with marshalling or when assigning the results of a SQL query into a struct, without duplicating code for each type. This is a naive implementation as it takes absolutely no error checking into account. It is not production safe and is meant to demonstrate how to iterate through and populate a struct.

Example usage

type Foo struct {
	Int        int
	String     string
	Unassigned string
}
@Faheetah
Faheetah / struct_parser.exs
Last active June 23, 2021 15:58
An example of parsing C with Elixir nimble_parsec, specifically Libvirt XDRs
defmodule StructParser do
import NimbleParsec
@space 0x0020
@tab 0x009
whitespace = utf8_char([@space, @tab, ?\n])
ignore_whitespace =
lookahead(whitespace)