Skip to content

Instantly share code, notes, and snippets.

View chmouel's full-sized avatar
☸️
Kuberneting

Chmouel Boudjnah chmouel

☸️
Kuberneting
View GitHub Profile
@chmouel
chmouel / pytest.golden.py
Last active November 14, 2024 10:41
golden files comparaison and update on python with pytest
import json
import os
import pathlib
import pytest
@pytest.fixture
def fixtdir(request):
return pathlib.Path(request.module.__file__).parent / "fixtures"
from datetime import datetime, timedelta
def calculate_start_date_and_months(end_date_str, num_weeks):
# Convert end_date_str to a datetime object
end_date = datetime.strptime(end_date_str, "%Y-%m-%d")
# Calculate the number of days to subtract
num_days = num_weeks * 7
@chmouel
chmouel / focus_or_open.ahk
Last active October 1, 2024 18:33
Focus or open msedge or windowsterminal on win+w or win+j
#Requires AutoHotkey v2.0
global previousWindow := ""
; Define a function to focus or open
FocusOrOpen(exe, runit) {
global previousWindow
edgeWindow := "ahk_exe " . exe
; Check if Microsoft Edge is already open
if WinExist(edgeWindow) {
@chmouel
chmouel / README.md
Last active November 1, 2023 18:37
hide-password-multi-writer.go

This will hide passwords implemented as a writer.

the example in main will create two writer one to stdout and one to a file, and hide a list of passwords

It tries to be a bit smart to print the characters as soon as possible

% cat test.txt
hello this is a password that string should be hidden now!!
I hope the string anotherpassword2 will be kept secret
@chmouel
chmouel / magit-log-trace-definition-ts.el
Created October 22, 2023 19:58
Magit log trace definition using TS for function name
(defun my-magit-log-trace-definition-ts()
(interactive)
(let ((funcname
(substring-no-properties
(treesit-node-text
(treesit-node-child-by-field-name (treesit-defun-at-point) "name")))))
(magit-log-trace-definition (or (magit-file-relative-name)
(user-error "Buffer isn't visiting a file"))
(or funcname
(user-error "No function at point found"))
@chmouel
chmouel / drop-git-commit.bash
Created October 10, 2023 05:58
Drop a git commit from a branch in a middle non interactive
#!/usr/bin/env bash
# Copyright 2023 Chmouel Boudjnah <[email protected]>
set -eufo pipefail
commit=$(git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
env FZF_DEFAULT_OPTS="--bind=ctrl-d:preview-half-page-down,ctrl-u:preview-half-page-up,ctrl-j:preview-down,ctrl-k:preview-up" \
fzf --ansi -m --no-sort --reverse --tiebreak=index)
sha=$(echo "${commit}" | grep -o '[a-f0-9]\{7\}' | head -1)
[[ -z ${sha} ]] && exit 1
#!/usr/bin/env bash
TMP=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f $TMP; }
trap clean EXIT
query=
[[ -n $@ ]] && query="--query=$@"
case "$(uname -a)" in
*Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;;
package main
import (
"fmt"
"log"
"regexp"
)
type Option interface {
Validate(opt any) error
---
apiVersion: v1
kind: Secret
metadata:
annotations:
pipelinesascode.tekton.dev/sha: 0aa87a87791bca86efc57676fbc5453948ae668d
pipelinesascode.tekton.dev/url: https://github.com/pdaverh/nodejs-rhtap-sandbox
pipelinesascode.tekton.dev/url-org: pdaverh
pipelinesascode.tekton.dev/url-repository: nodejs-rhtap-sandbox
creationTimestamp: null
#!/usr/bin/env bash
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
TMP=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f ${TMP}; }
trap clean EXIT