Skip to content

Instantly share code, notes, and snippets.

View kreiger's full-sized avatar

Christoffer Hammarström kreiger

View GitHub Profile
@kreiger
kreiger / git-hook.sh
Last active December 8, 2022 12:13
Run Git hooks in "$somedir/$hook.d/*" before local repo hooks. Create symlinks in "$somedir" to this for each Git hook e.g. `ln -s git-hook.sh commit-msg`, then `git config --global core.hookspath $somedir`
#!/bin/sh
dir=$(dirname $0)
name=$(basename $0)
export GIT_DIR="${GIT_DIR:-`git rev-parse --absolute-git-dir`}"
status=0
for hook in $dir/$name.d/* "$GIT_DIR"/hooks/$name; do
if [ -x "$hook" ]; then
echo "Executing $name hook $hook"
"$hook" "$@" || status=$?
@kreiger
kreiger / kube-molly-guard
Last active June 30, 2023 14:35
Prevent accidental kubernetes commands on the wrong context, by prefixing kubernetes authentication command with this script.
#!/bin/bash
function kube_molly_guard() {
local maxage=600
local context="$(kubectl config current-context)"
local tsfile=~/.kube/ts/"$context"
local ts=0
@kreiger
kreiger / kube.sh
Last active February 13, 2020 13:26
Bash function to switch KUBECONFIG between files in ~/.kube/clusters/. Source it in e.g. .bashrc
kube() {
local cluster="$1"
if [ -z "$cluster" ]; then
cluster="$(kubectl config current-context)"
if [ -n "$cluster" ]; then
export KUBECONFIG=/dev/null
return
fi
@kreiger
kreiger / include-build.gradle
Last active November 22, 2019 15:23
Put this Gradle init script in `~/.gradle/init.d/`. It will read a list of other Gradle projects from `.gradle/include`. and include them in the build.
def includePath = '.gradle/include'
settingsEvaluated { settings ->
File include = new File(settings.rootDir, includePath)
if (!include.file) return
include.eachLine {
if (it.trim() =~ /^#/) return
if (it.trim().empty) return
@kreiger
kreiger / gw
Last active April 7, 2025 13:25
gw - gradlew wrapper
#!/bin/sh
set -e
while [ "$PWD" != "/" ]; do
if [ -f "./build.gradle" ]; then
echo "$PWD/build.gradle"
break;
fi
if [ -f "./build.gradle.kts" ]; then
@kreiger
kreiger / A professional takes the risk on what they know what must be done.
Last active August 22, 2019 10:13
"Uncle" Bob Martin - "The Future of Programming"
https://www.youtube.com/watch?v=ecIWPzGEbFc&t=3864s
"But the Business does not understand us [programmers]." ...
"These technical disciplines are not within the expertise of [the] Business. And they shouldn't be. They belong to us. That's part of our tech expertise." ...
"And the risk frankly, is ours to take. We own that risk. That is us."
"We are the ones who know that things need to be tested."
"We are the ones who know that things need to be refactored."
"We are the ones who know how to get software done, and so we have to take the risk, as part of our normal professional operation."
gradle.afterProject { p ->.
if (!rootProject.hasProperty("idea")) {
println "Not an IDEA root project: ${rootProject.name}"
return
}
if (!p.hasProperty("idea")) {
println "Not an IDEA project: ${p.name}"
return
}
@kreiger
kreiger / nvidia-experimental
Created September 19, 2018 15:55
/etc/apt/preferences.d/nvidia-experimental
Package: *nvidia* *nvidia*:i386
Pin: release a=experimental
Pin-Priority: 950
#!/bin/sh
objectpath=$1
if [ -z "$objectpath" ]; then
echo "Usage:\n\t$(basename "$0") <path> < blob" >&2
exit 1
fi
objectid=$(git hash-object -w --stdin)
git update-index --add --cacheinfo 100644,"$objectid","$objectpath"
#!/bin/sh
format='%(color:magenta)%(objectname:short) %(color:blue)%(authordate:iso) %(authordate:relative);%(color:green)%(authorname);%(color:bold)%(color:white)%(HEAD)%(color:reset)%(color:yellow)%(refname:short)%(if)%(upstream:track)%(then)%(color:red) %(upstream:track)%(end);%(color:reset)%(contents:subject)'
git branch --sort=-creatordate --format="$format" --color=always|column -s ';' -t|less -RS -F