Skip to content

Instantly share code, notes, and snippets.

@munckymagik
munckymagik / pg-vacuuming
Last active November 26, 2022 03:43
A handy script that outputs reports to help understand how auto-vacuuming has been configured for a PostgreSQL database
#!/bin/sh
# This script runs queries that interrogate vacuuming config and statistics.
set -e
function execute_query() {
local query="$1"
"$psql_cmd" "$database_url" -c "$query"
}
@munckymagik
munckymagik / PostgreSQL - EXPLAIN cheatsheet.md
Last active July 2, 2024 08:12
PostgreSQL - EXPLAIN cheatsheet

PostgreSQL - EXPLAIN cheatsheet

  • -> Marks the start of info on a "plan node"
  • Work from the leaves to the root to understand what happened first
(cost=0.00..5.04 rows=101 width=0)
  • (cost=
@munckymagik
munckymagik / rev.cpp
Created August 2, 2020 09:48
Visualising Redis' SCAN iteration
#include <iostream>
#include <bitset>
static uint8_t rev(uint8_t v) {
uint8_t s = 8 * sizeof(v); // bit size; must be power of 2
uint8_t mask = ~0;
while ((s >>= 1) > 0) {
mask ^= (mask << s);
v = ((v >> s) & mask) | ((v << s) & ~mask);
}
@munckymagik
munckymagik / toggle-dark-mode.js
Last active January 29, 2020 09:17
An Apple JXA script that toggles dark mode for the macOS desktop and Terminal
#!/usr/bin/osascript -l JavaScript
// Update these with your chosen themes for Apple Terminal
const TERMINAL_DARK_THEME_NAME = "YourDarkTheme"
const TERMINAL_LIGHT_THEME_NAME = "YourLightTheme"
const app = Application.currentApplication()
app.includeStandardAdditions = true
const SysEvents = Application("System Events")
// run with node --harmony
(() => {
'use strict'
function zip(... arrays) {
return arrays[0].map(function(_,i){
return arrays.map(function(array){return array[i]})
});
}
@munckymagik
munckymagik / tasks.json
Created January 15, 2020 19:49
VSCode tasks with problem matchers for Rust
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "cargo build",
"group": {
@munckymagik
munckymagik / hack_day_2019.rs
Created December 5, 2019 21:05
Constructors for concrete instances of a parameterized type
trait Animal {
fn make_sound(&self);
}
struct Dog {}
impl Animal for Dog {
fn make_sound(&self) {
println!("My signature bark!");
}
@munckymagik
munckymagik / CMakeLists.txt
Created August 31, 2019 07:20
Trying out OpenMP
# Basic CMake project
cmake_minimum_required(VERSION 2.8.11)
# Name the project after the exercise
project(omptryout CXX)
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib")
find_package(OpenMP REQUIRED)
@munckymagik
munckymagik / range.cpp
Created August 31, 2019 07:14
Trying out building a Range class in C++
// clang++ -std=c++11 -o range range.cpp && ./range
// Based on http://stackoverflow.com/questions/7185437/is-there-a-range-class-in-c11-for-use-with-range-based-for-loops
// However https://en.wikipedia.org/wiki/Generator_%28computer_programming%29#C.2B.2B is a way simpler example
#include <iostream>
template <class T>
class RangeClass {
public:
@munckymagik
munckymagik / CMakeLists.txt
Created August 31, 2019 07:13
Trying out "moves" in C++
# Basic CMake project
cmake_minimum_required(VERSION 2.8.11)
# Name the project after the exercise
project(moving CXX)
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall -Werror")
add_executable(moving moving.cpp)