Skip to content

Instantly share code, notes, and snippets.

View kwilczynski's full-sized avatar
:octocat:

Krzysztof Wilczyński kwilczynski

:octocat:
View GitHub Profile
with_entries(if .key == "Version" then . + {value: (.value | tonumber)} else . end)
@kwilczynski
kwilczynski / content.js
Last active May 13, 2023 09:09
Simple Chrome extension that replaces Git commit IDs and URL with proper links
var textAreasCount = 0;
var linesCount = 0;
var linesReplaced = 0;
var linesSkipped = 0;
var start = performance.now();
function formatMilliseconds(ms) {
return Number.parseFloat(ms.toFixed(3))
@kwilczynski
kwilczynski / script.sh
Last active March 14, 2023 23:50
Use extra metrics output with cURL
fetch_with_curl() {
local url=$1
local timeout=${2:-10}
url="$url?q=$(date +'%s')"
curl -s -w "%{http_code} %{speed_download} %{size_download} %{time_namelookup} %{time_connect} %{time_total}\n" \
-H "Pragma: no-cache" -H "Cache-Control: no-cache" -H "Expires: 0" \
-o /dev/null --connect-timeout $timeout $url
}
ARG go_version=1.11.3
ARG alpine_version=latest
FROM golang:${go_version}-alpine AS builder
ENV GOPATH /build
ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 0
@kwilczynski
kwilczynski / retry.sh
Last active March 14, 2023 23:49
Retry something in Bash shell
retry() {
local n=1
local max=5
local delay=15
while true; do
"$@" && break || {
if [ $n -lt $max ]; then
n=$((n+1))
# No output on failure to allow redirecting output
sleep $delay;
#!/bin/bash
set -u
set -o pipefail
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
CIDR=${CIDR-}
GATEWAY=${GATEWAY-}
DEVICE=${DEVICE:-'eth0'}
@kwilczynski
kwilczynski / list.sh
Last active March 14, 2023 23:49
List AMI from Jenkins ...
#!/bin/bash -eu
export PATH=${PATH}:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
_string_to_lower() {
echo "$*" | tr '[:upper:]' '[:lower:]'
}
_sanitize_platform() {
case "$1" in
@kwilczynski
kwilczynski / strip-deb.sh
Created November 19, 2017 15:39
Remove preinst, postinst, prerm and postrm scripts from inside a Debian package.
#!/bin/bash
# To make it work, set the following:
# $ echo 'DPkg::Pre-Install-Pkgs { "xargs -r bash /home/vagrant/strip-deb.sh"; }' > /etc/apt/apt.conf.d/00strip-deb
set -e
set -u
set -o pipefail
generate_ldconfig_script() {
ARG go_version=1.17
ARG alpine_version=latest
FROM golang:${go_version}-alpine AS builder
ARG GOOS=linux
ARG GOARCH=amd64
ENV GOOS=${GOOS}
ENV GOARCH=${GOARCH}
@kwilczynski
kwilczynski / test.c
Last active March 14, 2023 23:46
Test for AES NI in the CPU.
#include <stdio.h>
int main (int argc, char **argv)
{
unsigned int eax, ebx, ecx, edx;
asm(
"xchg{l}\t{%%}ebx, %1\n\t" \
"cpuid\n\t" \
"xchg{l}\t{%%}ebx, %1\n\t" \