Skip to content

Instantly share code, notes, and snippets.

@kennyp
kennyp / layout_postgres.sh
Created March 22, 2024 16:43
Postgresql Layout for direnv
layout_postgres() {
export PGDATA="$(direnv_layout_dir)/postgres"
export PGHOST="$PGDATA"
if [[ ! -d "$PGDATA" ]]; then
initdb
cat >> "$PGDATA/postgresql.conf" <<-EOF
listen_addresses = ''
unix_socket_directories = '$PGHOST'
EOF
@kennyp
kennyp / .vimrc
Last active May 24, 2017 20:40
Format Expanded Postgres Output As YAML
function! ExpandedToYaml()
'<,'>s/ t$/ true/e
'<,'>s/ f$/ false/e
'<,'>g!/| \(true\|false\|[0-9\.]*\)$/s/| \(.*\)/| "\1"/
'<,'>s/[^ ]*\zs[ ]*|/:/e
'<,'>s/^/ /
'<,'>g/:$/d
endfun
vmap <silent> <Leader>c :<C-U>call ExpandedToYaml()<cr><cr>
nmap <silent> <Leader>c :set paste<cr>"+p:set nopaste<cr>`[v`]:<C-U>call ExpandedToYaml()<cr><cr>
require Logger
defmodule Playground do
def accept(port) do
{:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :line,
active: false, reuseaddr: true])
Logger.info "Accepting connections on port #{port}"
loop_acceptor(socket)
end

Keybase proof

I hereby claim:

  • I am kennyp on github.
  • I am kennyp (https://keybase.io/kennyp) on keybase.
  • I have a public key whose fingerprint is AD71 68B5 CDE0 5949 1FB5 D5DD 8B0A 18B9 0F71 1788

To claim this, I am signing this object:

defmodule TestApp.PageController do
use Phoenix.Controller
plug :action
def test(conn, _params) do
conn |> text "OK"
end
end
# Sinatra/Ruby
[~]» wrk -t 12 -c400 -d30s http://127.0.0.1:4567/test
Running 30s test @ http://127.0.0.1:4567/test
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 215.89ms 283.31ms 1.06s 80.72%
Req/Sec 259.81 272.75 1.21k 84.97%
44630 requests in 30.11s, 9.92MB read
Socket errors: connect 0, read 0, write 0, timeout 4110
Requests/sec: 1482.10
" Notes {
" vim: set foldmarker={,} foldlevel=0 spell:
"
" Kenny Parnell <k.parnell@gmail.com>
" }
" General {
execute pathogen#infect()
set background=dark
set cmdheight=2
@kennyp
kennyp / .bashrc
Created July 3, 2014 15:49
Make love for bashrc.
_make () {
local curw=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
COMPREPLY=($(compgen -W "$(make -qp | grep : | grep '^[a-z]' | cut -d: -f1)" -- $curw))
return 0
}
complete -F _make make
function local_server() {
cp ~/lib/favicon.ico .
ruby -run -e httpd -- -b 127.0.0.1 -p 8080 . &> /dev/null &
local pid=$!
ngrok -subdomain=kennyp 8080
kill $!
rm favicon.ico
}
@kennyp
kennyp / no_role.rb
Created March 10, 2014 15:07
Users without a role.
Spree::User.joins('LEFT JOIN "spree_roles_users" ON "spree_roles_users"."user_id" = "spree_users"."id" LEFT JOIN "spree_roles" ON "spree_roles"."id" = "spree_roles_users"."role_id"').group('spree_users.id').having('count(spree_roles.id) = 0')