Skip to content

Instantly share code, notes, and snippets.

View will's full-sized avatar
🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈

Will Leinweber will

🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈
View GitHub Profile
@will
will / tempdb.nix
Created December 2, 2023 16:14
start temporary postgres dbs with pre-created schema
schema = pkgs.stdenvNoCC.mkDerivation {
name = "schema";
src = schemaSrc;
nativeBuildInputs = [ postgres ];
installPhase = ''
mkdir $out
export PGDATA="$out"
export PGHOST="$out"
export PGUSER=postgres
export PGDATABASE=postgres
@will
will / ec2.nix
Created August 3, 2023 13:47
user data ec2 nixos
{ config, pkgs, ... }:
{
imports = [ <nixpkgs/nixos/modules/virtualisation/amazon-image.nix> ];
ec2.hvm = true;
nix.settings.experimental-features = [ "nix-command" "flakes" ];
networking.hostName = "nixos";
security.sudo.wheelNeedsPassword = false;
parted /dev/vda -- mklabel gpt
parted /dev/vda -- mkpart primary 1GiB -8GiB
parted /dev/vda -- mkpart primary linux-swap -8GiB 100%
parted /dev/vda -- mkpart ESP fat32 1MiB 512MiB
parted /dev/vda -- set 3 esp on
mkfs.ext4 -L nixos /dev/vda1
mkswap -L swap /dev/vda2
mkfs.fat -F 32 -n boot /dev/vda3
@will
will / iptables.sh
Created April 14, 2023 09:04
iptable rule maker
#!/bin/sh
### Generate a list of iptables rules to redirect port 53 traffic (tcp+udp) and echo to console.
### This version of the script does NOT apply anything to the iptables on the machine it is run on.
### IPv4 DNS traffic is redirected to $PRIMARYDNS_IPV4 on port 53
### IPv6 DNS traffic is redirected to $PRIMARYDNS_IPV6 on port 53
# This is the DNS that you want clients to be forced to use on your network
# If you have a secondary DNS, add it to the whitelist below and it will still work.
PRIMARYDNS_IPV4="192.168.1.12"
@will
will / flake.nix
Created April 11, 2023 20:51
home manager 2023-04-11
# switch with `nix run . switch -- --flake .`
# https://www.chrisportela.com/posts/home-manager-flake/
{
description = "My Home Manager Flake";
inputs = {
nixpkgs.url = "nixpkgs";
unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
unstable_nvim.url = "github:GaetanLepage/nixpkgs/neovim";
@will
will / a_ssh_pg_tunnel.cr
Last active April 3, 2023 13:20
tunnel crystal-pg through ssh
require "pg"
require "ssh2"
# Add an initlizer that directly sets the socket
class PQ::Connection
def initialize(@soc, @conninfo)
end
end
# Add a new crystal-pg database context that can store a proc that returns a
{ config, pkgs, ... }:
# https://mipmip.github.io/home-manager-option-search/
{
# Home Manager needs a bit of information about you and the
# paths it should manage.
home = {
stateVersion = "22.05";
username = "will";
@will
will / query_counter.rb
Created July 29, 2022 19:27
rspec sequel query counter
if ENV["COUNT_QUERIES"]
require "stringio"
QUERIES = StringIO.new
RSpec.configure do |config|
config.before(:suite) do
Sequel::Model.db.loggers << Logger.new(QUERIES)
end
config.after(:suite) do
@will
will / ipanema.patch
Created June 10, 2022 02:23
play girl from Ipanema while your query runs
diff --git i/src/bin/psql/mainloop.c w/src/bin/psql/mainloop.c
index b0c4177..dcb4b5a 100644
--- i/src/bin/psql/mainloop.c
+++ w/src/bin/psql/mainloop.c
@@ -82,6 +82,8 @@ MainLoop(FILE *source)
/* main loop to get queries and execute them */
while (successResult == EXIT_SUCCESS)
{
+ system("killall -q afplay");
+
@will
will / init.lua
Created April 12, 2022 16:09
Neovim require all Lua files in directory
local fd = vim.loop.fs_scandir(vim.fn.stdpath('config') .. '/lua/user/')
for name in
function() return vim.loop.fs_scandir_next(fd) end
do require('user.' .. name:gsub('.lua\z', '')) end