Skip to content

Instantly share code, notes, and snippets.

View dewe's full-sized avatar
🇸🇪

Johan Dewe dewe

🇸🇪
  • Adaptiv Sthlm AB
  • Stockholm, Sweden
View GitHub Profile
@dewe
dewe / epoch.sh
Created April 12, 2024 06:04
epoch formatting, shell function (mac os / BSD)
# epoch format, use with arg or pipe; no argument -> echo current epoch
function epoch() {
fmt="+%Y-%m-%dT%H:%M:%S%z"
if [ -t 0 ] && [ -z "$1" ]; then
# no input, echo current epoch
date "+%s"
elif [[ -z "$1" ]]; then
# no arg, use piped value
xargs -I {} sh -c "date -r {} $fmt"
else
@dewe
dewe / gist:89a9368b4242a1070f9a7fdbf1c6b2e2
Last active May 30, 2022 11:28
kubectl-cronjob-restarter.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: restarter-job
namespace: podinfo
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
@dewe
dewe / main.go
Created May 13, 2022 21:14
Generate EKS k8s api bearer token, for use in api requests or setting up kubeconfig for accessing a remote cluster.
package main
import (
"context"
"encoding/base64"
"flag"
"fmt"
"strings"
"github.com/aws/aws-sdk-go-v2/config"
@dewe
dewe / convert-ingress-version.sh
Last active May 30, 2021 07:37
Script using jq and yq to upgrade kubernetes ingress version from networking.k8s.io/v1beta1 to networking.k8s.io/v1
#!/usr/bin/env bash
# Upgrade ingress resource api version to v1.
#
# USAGE:
# convert-ingress-version.sh [OPTIONS] <FILE>
#
# OPTIONS:
# -i update the yaml file inplace.
#
@dewe
dewe / Makefile
Created June 26, 2019 06:44
makefile help target with extra line after help printout
help: ## Display this help (thanks to https://suva.sh/posts/well-documented-makefiles)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } /\Z/ { printf "\n"}' $(MAKEFILE_LIST)
@dewe
dewe / keybase.md
Created November 29, 2016 20:55
keybase.md

Keybase proof

I hereby claim:

  • I am dewe on github.
  • I am dewe (https://keybase.io/dewe) on keybase.
  • I have a public key ASCpOsl9PZ0aK7Avt9bc6iDnHH87fMKhMc-tycshw_kyRQo

To claim this, I am signing this object:

@dewe
dewe / learn.lua
Last active August 29, 2015 14:11 — forked from vdel26/learn.lua
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@dewe
dewe / gist:9d57faf7ae1cb84af941
Created October 25, 2014 18:40
How to mock session data for socket.io 0.9.16 in express.io 1.1.13
var app = require('express.io')();
app.http().io();
app.listen(7076)
// override authorization checks, always true. This works even though app has begun listening.
app.io.set('authorization', function (handshake, accept) { accept(null, true); });
// register a new handler for the message handler under test. The can inject mock data into session.
var handler = app.io.router['get-discussions'];
app.io.router['get-discussions'] = function (request) {
@dewe
dewe / gist:a654380c662e4a5c3828
Last active August 29, 2015 14:08
How to enable socket.io logging for Express.io 1.1.13
var app = require('express.io')();
var log4js = require('log4js');
var logger = log4js.getLogger('io');
app.http().io();
app.listen(7076)
app.io.set('logger', logger);
app.io.set('log level', log4js.levels.TRACE);
@dewe
dewe / gist:f5dd193acae0eb79af01
Created July 1, 2014 05:53
How to set workingdirectory and environment variables local to cmd script
@echo off
setlocal
pushd %~dp0
set APPDATA=%CD%\data
echo APPDATA=%APPDATA%
popd
endlocal