Skip to content

Instantly share code, notes, and snippets.

View mika's full-sized avatar

Michael Prokop mika

View GitHub Profile
@mika
mika / psql_internals_cheatsheet.sql
Created June 15, 2019 10:19 — forked from azet/psql_internals_cheatsheet.sql
PostgreSQL internals SQL collection
# long running queries:
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
## active queries and killing them:
@mika
mika / diskchecker.pl
Created May 14, 2019 08:00 — forked from bradfitz/diskchecker.pl
diskchecker.pl
#!/usr/bin/perl
#
# Brad's el-ghetto do-our-storage-stacks-lie?-script
#
sub usage {
die <<'END';
Usage: diskchecker.pl -s <server[:port]> verify <file>
diskchecker.pl -s <server[:port]> create <file> <size_in_MB>
diskchecker.pl -l [port]
@mika
mika / 99-disable-wireless-when-wired
Created April 12, 2019 15:02 — forked from cengiz-io/99-disable-wireless-when-wired
Script should be placed under `/etc/NetworkManager/dispatcher.d/` with a name like `99-disable-wireless-when-wired`. Make sure 1) root owns it 2) it's mod is 755
#!/bin/sh
IFACE=$1
ACTION=$2
ntfy () {
sudo -u cengiz \
DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
notify-send "$1" "$2"
@mika
mika / upgrade.sh
Created October 19, 2018 15:56 — forked from zeha/upgrade.sh
#!/bin/bash
set -x
puppet agent --disable "update Debian"
service keepalived stop
apt-get install udev acl
sed -i'' -e 's/jessie/stretch/g' /etc/apt/sources.list.d/*
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
apt-get update
apt-get install apt dpkg deborphan # openjdk-8-jre-headless
@mika
mika / how-to-upgrade-nvmw-ssd-firmware-on-linux.md
Created October 8, 2018 06:16 — forked from klingtnet/how-to-upgrade-nvmw-ssd-firmware-on-linux.md
How to upgrade [Lenovo] NVMe SSD firmware on Linux

The instructions were tested on a Lenovo X1 Carbon 5th Gen (X1C5) on Arch Linux but should be applicable to other Lenovo models and Linux distributions.

BACKUP YOUR DATA! I created a bootable Ubuntu Image like this:

$ sudo sh -c 'curl --location --silent --fail "http://releases.ubuntu.com/18.04/ubuntu-18.04.1-desktop-amd64.iso" | pv > /dev/<your-usb-drive>'
# note that pv is only there to show progress, it is perfectly fine to redirect curl to the usb drive directly.

then I booted from this drive by pressing F12 on reboot and dumped my NVMe disk to an external hard drive like this:

port=0
interface=enp8s0
bind-interfaces
dhcp-range=192.168.0.50,192.168.0.150,12h
enable-tftp
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-boot=tag:efi-x86_64,grubx64.efi
tftp-root=/tmp/tftpboot
@mika
mika / debian-stretch-ami.py
Created August 16, 2018 22:55
Identify latest Debian stretch EC2 AMI in eu-west-1
#!/usr/bin/env python
from bs4 import BeautifulSoup
import urllib2
page = urllib2.urlopen("https://wiki.debian.org/Cloud/AmazonEC2Image/Stretch")
soup = BeautifulSoup(page, features="html.parser")
region = soup.find(text="eu-west-1")
ami = region.find_next().get_text().strip()
print(ami)
#!/usr/bin/make -f
CRTS := $(wildcard *.crt)
PEMS := $(shell echo $(CRTS) | sed 's,\.crt,.pem,g')
OCSPS := $(shell echo $(CRTS) | sed 's,\.crt,.ocsp,g')
DHS := $(shell echo $(CRTS) | sed 's,\.crt,.dh,g')
all: $(PEMS) $(OCSPS) $(DHS)
chmod 600 *.key
@mika
mika / gist:e30b4e99c338f5d80d7681407708609b
Created May 25, 2018 11:14
zsh with extended vcs_info for git
## customize vcs_info
zstyle ':vcs_info:git*:*' check-for-changes true
zstyle ':vcs_info:git*:*' unstagedstr '|U'
zstyle ':vcs_info:git*:*' stagedstr '|≠'
# enable hooks, requires Zsh >=4.3.11
if [[ $ZSH_VERSION == 4.3.<11->* || $ZSH_VERSION == 4.<4->* || $ZSH_VERSION == <5->* ]] ; then
# hook for untracked files
+vi-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' ]] && \
@mika
mika / main.yml
Created January 4, 2018 23:52 — forked from stefan2904/main.yml
My update role, inspired by nicoo. (roles/update/tasks/main.yml)
---
- name: apt update/upgrade
apt:
autoclean: yes
update_cache: yes
upgrade: "{{ upgrade|default('safe') }}"
- name: Install ansible module dependencies
apt: