Skip to content

Instantly share code, notes, and snippets.

@socketbox
socketbox / rngchk.c
Created October 23, 2019 22:40
Unbiased Random Integer Generator Over a Range
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <time.h>
/*
* generates an unsigned int between low and high, inclusive of both
* taken from: https://en.cppreference.com/w/c/numeric/random/rand
*
@socketbox
socketbox / Exercise4Mod.java
Created November 1, 2019 01:52
Brute force method of arriving at values for modular hashing of a small set of strings
//Borrowed from https://github.com/reneargento/algorithms-sedgewick-wayne/blob/master/src/chapter3/section4/Exercise4.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/**
* Created by Rene Argento on 19/07/17.
* Modified on 10/30/2019
*/
public class Exercise4Mod
@socketbox
socketbox / cube_solver.adoc
Last active May 23, 2022 21:17
Instructions for Solving Rubik's Cube as Presented by Robbie Gonzalez of Wired

Attributions

These instructions are an amalgam of steps presented by Wired’s Robbie Gonzalez, Phil of thecubicle.com, and JPerm of YouTube fame.

Definitions

A right trigger is R U R'

A left trigger is L' U' L

An r-alg is R U R' U'

@socketbox
socketbox / toggle_monitor_input.sh
Created January 11, 2020 23:34
Toggle monitor input from keyboard in linux
#!/usr/bin/env bash
#TODO: call ddcutil detect and parse output for actual devices; only constants should be VCP code and vars
# related to ddcutil
BUS_FLAG="-b"
I2C_ID=5
CMD="ddcutil"
GETTER=getvcp
SETTER=setvcp
@socketbox
socketbox / looping_temp_test.sh
Created March 29, 2020 02:17
Raspberry Pi Cooling Test
#!/bin/bash
clear
for f in {1..10}
do
vcgencmd measure_temp
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run > /dev/null 2>&1
done
vcgencmd measure_temp
@socketbox
socketbox / gcloud_secret_revealor.sh
Last active June 15, 2022 23:53
Get all secrets and sensitive data for a GCP project
#!/usr/bin/env bash
set -eou pipefail
sec_list=$(gcloud secrets list --format="table[no-heading](name.basename())")
for s in ${sec_list[*]};
do
sec=$(gcloud secrets versions access latest --secret="$s")
printf "%s: %s\n" $s $sec
done
@socketbox
socketbox / terraform_secret_import.sh
Last active February 27, 2021 06:30
Script to automate importing of existing secrets in a GCP project
#!/bin/bash
set -euo pipefail
filename='secmgr.tf'
proj_id=$1
sec_list=$(gcloud secrets list --format="table[no-heading](name.basename())")
for s in ${sec_list[*]};
do
@socketbox
socketbox / watch_log.sh
Last active July 2, 2021 07:37
Watch logs on data pipeline
watch -n5 \
"ls -al; echo; free -h; echo;\
ps axo pid,ppid,psr,pri,start:18,etime:12,pcpu,pmem,rss:12,vsz:12,cmd; echo;\
tail -n15 elt.log; echo;"
@socketbox
socketbox / psql-13.sh
Created July 6, 2021 16:43
Install postgresql-client-13 on Debian Buster
apt update
apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
apt update
apt -y install postgresql-client-13
@socketbox
socketbox / postgres_queries_and_commands.sql
Created September 23, 2021 18:54 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'