Skip to content

Instantly share code, notes, and snippets.

View dfcarpenter's full-sized avatar

Daniel Carpenter dfcarpenter

View GitHub Profile
@dfcarpenter
dfcarpenter / machine.js
Last active November 26, 2019 00:50
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@dfcarpenter
dfcarpenter / dependent_objects.sql
Created July 10, 2019 18:13
Find objects that depend on a specific column
SELECT
d.objid::regclass AS owning_object,
d.refobjid::regclass AS dependent_object,
a.attname AS dependent_column,
d.deptype -- The meaning of this type is documented at https://www.postgresql.org/docs/current/catalog-pg-depend.html
FROM pg_catalog.pg_depend d
LEFT JOIN pg_catalog.pg_attribute a ON d.refobjid = a.attrelid
AND d.refobjsubid = a.attnum
WHERE refobjid = '<table>'::regclass
AND a.attname = '<column>';
@dfcarpenter
dfcarpenter / was_relation_rewritten.sql
Created July 10, 2019 18:12
See if DDL causes a relation to be rewritten
SELECT
relname,
relfilenode
FROM pg_catalog.pg_class
WHERE relname in (
'<table>',
'<index>'
)
-- Order by oid for convenience if you're checking multiple relations.
ORDER BY oid;
@dfcarpenter
dfcarpenter / table_statistics.sql
Created July 10, 2019 18:11
Postgres internal statistics about table accesses
SELECT
seq_scan,
seq_tup_read,
idx_scan,
idx_tup_fetch,
n_tup_ins,
n_tup_upd,
n_tup_del
FROM pg_catalog.pg_stat_user_tables
WHERE relname = '<table>';
@dfcarpenter
dfcarpenter / locks_held.sql
Created July 10, 2019 18:10
Find active long running queries and tables they lock
SELECT
psa.datname as database,
psa.query as current_query,
clock_timestamp() - psa.xact_start AS transaction_age,
array_agg(distinct c.relname) AS tables_with_locks
FROM pg_catalog.pg_stat_activity psa
JOIN pg_catalog.pg_locks l ON (psa.pid = l.pid)
JOIN pg_catalog.pg_class c ON (l.relation = c.oid)
JOIN pg_catalog.pg_namespace ns ON (c.relnamespace = ns.oid)
WHERE psa.pid != pg_backend_pid()
@dfcarpenter
dfcarpenter / dependencies.py
Created February 26, 2019 23:05
Wagtail Migrations
dependencies = [
('wagtailcore', '0040_page_draft_title'),
('wagtailredirects', '0006_redirect_increase_max_length'),
('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'),
('wagtailforms', '0003_capitalizeverbose'),
('taggit', '0002_auto_20150616_2121'),
('wagtailimages', '0019_delete_filter'),
]
The dependencies are i'm assuming referencing the old way wagtai modules were named.
@dfcarpenter
dfcarpenter / railway_oriented_programming.clj
Created October 16, 2018 22:30 — forked from ah45/railway_oriented_programming.clj
Railway Oriented Programming in Clojure using (funcool) Cats
(ns railway-oriented-programming
"An adaptation of [Railway Oriented Programming](rop) using the
[Cats](cats) library in Clojure.
[rop]: http://fsharpforfunandprofit.com/posts/recipe-part2/
[cats]: https://github.com/funcool/cats"
(:require [cats.builtin]
[cats.core :as cats]
[cats.monad.either :as either]))
@dfcarpenter
dfcarpenter / CodeEditor.elm
Created August 22, 2018 21:03 — forked from lukewestby/CodeEditor.elm
The custom element and Elm API that will drive Ellie's code editors
module Ellie.Ui.CodeEditor
exposing
( Attribute
, LinterMessage
, Position
, Severity(..)
, linterMessages
, mode
, onChange
, readOnly
@dfcarpenter
dfcarpenter / astar.clj
Created August 16, 2018 23:22 — forked from reborg/astar.clj
Clojure implementation of the A* path finding algorithm
;; This is the Wikipedia entry example encoded graph.
(def graph {:orig [{:a 1.5 :d 2} 0]
:a [{:orig 1.5 :b 2} 4]
:b [{:a 2 :c 3} 2]
:c [{:b 3 :dest 4} 4]
:dest [{:c 4 :e 2} 0]
:e [{:dest 2 :d 3} 2]
:d [{:orig 2 :e 3} 4.5]})
(defn a* [graph orig dest]
@dfcarpenter
dfcarpenter / portal.ini
Created April 14, 2018 21:41
docker uwsgi
[uwsgi]
http = :8000
http-keepalive = 1
http-auto-chunked = 1
wsgi-file = config/wsgi_prod.py
master = true
processes = 8
threads = 2
enable-threads = True
gid = 2000