Skip to content

Instantly share code, notes, and snippets.

Avatar
🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈

Will Leinweber will

🆒
ه҈ͣفͤ҈ͥ҉ͦ҈ͧ҉ͨ҈ͩ҉ͪ҈ͫ҉ͬ҈ͭ҉ͮ҈ͯ҉ͨ҈ͬ҉ͧ҈ͣ҉ͨ҈ͧ҉ͯ҈ͮ҉ͭ҈ͤ҉ͦ҈ͥ҉ͧ҈ͩ҉ͭ҈ͨ҉ͣ҈ͪ҉ͧ҈ͭ҉ͩ҈ͤ҉ͮ҈ͯ҉ͬ҈
View GitHub Profile
@will
will / ipanema.patch
Created Jun 10, 2022
play girl from Ipanema while your query runs
View ipanema.patch
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 Apr 12, 2022
Neovim require all Lua files in directory
View init.lua
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
@will
will / mode.swift
Last active Mar 9, 2022
print light mode dark mode changes
View mode.swift
import Foundation
import AppKit
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
DistributedNotificationCenter.default.addObserver(
forName: Notification.Name("AppleInterfaceThemeChangedNotification"),
object: nil, queue: nil,
using: self.themeChanged(notification:)
)
View metldown.c
// copied from https://github.com/gkaindl/meltdown-poc/blob/master/meltdown.c
// flush_reload from https://github.com/defuse/flush-reload-attacks
// TSX from https://github.com/andikleen/tsx-tools
// dump_hex from https://gist.github.com/ccbrown/9722406
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
View minimal_libpq.cr
@[Link(ldflags: "-lpq -I`pg_config --includedir` -L`pg_config --libdir`")]
lib LibPQ
fun connect = PQconnectdb(conninfo : UInt8*) : Void*
fun exec = PQexec(conn : Void*, query : UInt8*) : Void*
fun getvalue = PQgetvalue(res : Void*, row : Int32, column : Int32) : UInt8*
end
conn = LibPQ.connect("postgres:///")
res = LibPQ.exec(conn, "select 'Hello it is ' || now()")
String.new(LibPQ.getvalue(res, 0, 0)) #=> "Hello it is 2015-07-15 16:30:44.396092-07"
@will
will / a.md
Created Nov 17, 2016
SameSite strict cookies in rails and pliny/sinatra
View a.md

SameSite=strict cookies is another layer to help prevent CSRF attacts in newer browsers

Rails

(at least 5, no clue about earlier versions)

--- a/config/initializers/session_store.rb
+++ b/config/initializers/session_store.rb
@@ -1,3 +1,3 @@
@will
will / query_collations.sql
Created Sep 2, 2020
check collation for all public text columns postgres
View query_collations.sql
SELECT
n.nspname as "Schema",
c.relname as "Name",
a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
a.attrelid as table_id,
(SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t
WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
@will
will / forward.rb
Created Aug 3, 2020
net::ssh remote port to local socket
View forward.rb
# on remote machine
# nc -l -p 1212
# on local machine
ssh = Net::SSH.start(remote.ip, "centos", keys_only: true, key_data: [remote.ssh_key])
tempfile = Tempfile.new("net_ssh_forward_test")
path = tempfile.path
tempfile.delete
View gist:428b67c8e2afd14d6097a42748ff9d44
/t/test> cat a.cr
def go
a = 0
10.times do
a += 1
end
p a
end