Skip to content

Instantly share code, notes, and snippets.

@pohzipohzi
pohzipohzi / main.rs
Created August 23, 2024 14:10
minimal fft implementation
use std::{
f64::consts::PI,
fs::File,
io::Read,
iter::zip,
time::{Duration, Instant},
};
fn main() {
let mut t = [Duration::ZERO; 4];
@pohzipohzi
pohzipohzi / clangd.md
Last active March 26, 2025 17:03
setting up clangd

Here are some examples of how to setup clangd for a project

If the project:

  • uses meson

meson setup <build_dir> generates a compilation database in <build_dir>/compile_commands.json. Since clangd automatically looks for the compilation database in build, we don't need to do anything else if build is the name of the build directory

meson setup build
@pohzipohzi
pohzipohzi / git-history-reset-authors
Last active March 27, 2021 20:06
reset git history author names
git rebase -i --root
# change verbs for relevant commits to `edit`
while [ $? -eq 0 ]; do git commit --amend --reset-author --no-edit --allow-empty --date="$(git log -n 1 --format=%ad)" && git rebase --continue; done
@pohzipohzi
pohzipohzi / gotraceback.md
Last active September 22, 2019 19:14
sample program to test output for different GOTRACEBACK settings

This is a sample program that tests output on a panicking go program based on different GOTRACEBACK settings. There are several levels that control the amount of output generated - none, single, all, system - each with it's own aliases. More information can be found at https://golang.org/pkg/runtime/.

  • env GOTRACEBACK=none go run main.go

This should give the same output as env GOTRACEBACK=0 go run main.go

panic: f3
exit status 2
@pohzipohzi
pohzipohzi / checksum.md
Created March 31, 2019 10:14
PostgreSQL Page Checksum Protection

PostgreSQL Page Checksum Protection

This gist summarises a way to create corrupted databases. Most of the material is adapted from Luca's Article.

Setup the database

Create and start the server with data checksums enabled

initdb -k -D cluster
@pohzipohzi
pohzipohzi / walg-pitr.md
Last active April 25, 2023 15:47
PostgreSQL Point-In-Time-Recovery (PITR) with WAL-G

WAL-G PITR

This gist summarises a way to simulate point-in-time recovery (PITR) using WAL-G. Most of the material is adapted from Creston's tutorial.

Setup

First we initialize a database cluster

pg_ctl init -D cluster
@pohzipohzi
pohzipohzi / join_test.go
Created December 14, 2018 08:02 — forked from dtjm/join_test.go
strings.Join vs fmt.Sprintf vs string concat (+)
package join
import (
"fmt"
"strings"
"testing"
)
var (
testData = []string{"a", "b", "c", "d", "e"}
@pohzipohzi
pohzipohzi / tree_traversal.py
Last active November 27, 2018 18:11
Recursive and iterative implementations of basic tree traversals in python 3
class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def buildTree(arr):
nodes = [TreeNode(val) for val in arr]
for i in range(len(nodes)):
left, right = (i+1)*2-1, (i+1)*2
@pohzipohzi
pohzipohzi / redis-example.go
Last active March 22, 2022 15:59
Examples from redigo
// this is a file that puts together all redigo examples for convenience
// (see https://godoc.org/github.com/gomodule/redigo/redis#pkg-examples)
//
// start by ensuring that redis is running on port 6379 (`redis-server`)
// uncomment the main method as needed, and run the script (`go run main.go`)
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
@pohzipohzi
pohzipohzi / backup.sh
Created January 15, 2018 07:46
Simple shell script to backup .xlsm files in folder
#!/bin/bash
for filename in *.xlsm; do
cp "$filename" "backup/$(basename "$filename" .xlsm) $(date +'%Y%m%d%H%M%S').xlsm"
done