Skip to content

Instantly share code, notes, and snippets.

View cimmanon's full-sized avatar

cimmanon

View GitHub Profile
CREATE TABLE order_history (
order_id INT NOT NULL,
date_added TIMESTAMPTZ NOT NULL DEFAULT now(),
status TEXT NOT NULL,
PRIMARY KEY (order_id, date_added)
);
CREATE TABLE history_allowed_pattern (
old TEXT NOT NULL,
@cimmanon
cimmanon / psql.md
Created May 2, 2017 17:22
PostgreSQL cheat sheet for MySQL users

I use PostgreSQL via the psql client. If you use a different client (eg. pgAdmin, etc.), I don't know how much will translate over.

One nice difference between psql and mysql (cli) is that if you press CTRL+C, it won't exit the client.

User administration

Login as superuser (via shell)

psql -U postgres
@cimmanon
cimmanon / diagnostics.sql
Last active December 18, 2016 15:20
PostgreSQL function for doing diagnostics on unfamiliar tables
begin;
/*----------------------------------------------------------------------------------------------------*\
| Functions for generating statistics
\*----------------------------------------------------------------------------------------------------*/
create or replace function rel_column_count(schema_name text, table_name text, column_name text, column_type text) returns table
( not_null_count bigint
, distinct_count bigint
, min_length int
@cimmanon
cimmanon / readme.md
Last active March 1, 2018 18:13
Heist Attribute Splices explained with examples

There aren't any good guides for using AttrSplices from Heist. The tutorial from the Snap website fails to show how to bind them, and the only public code I can find that uses them is Digestive Functors Heist.

How does it work?

type AttrSplice m = Text -> RuntimeSplice m [(Text, Text)]

The AttrSplice type signature says that it takes a Text and returns a Monad containing a list of tuples of Text. The first argument would only be used if you're planning on using it as a point of comparison within the template, as shown in the Attribute Splices Tutorial (n.b. the type signature listed here is slightly different, this might reflect an older version of Heist):

@cimmanon
cimmanon / trigger.sql
Last active March 5, 2017 02:02
Example trigger for ensuring that history states are inserted in the proper order. Ever needed to make sure that an order is filled before it gets shipped? This is how you would do it in the database.
CREATE TABLE history_allowed_pattern (
old TEXT NOT NULL,
new TEXT NOT NULL,
UNIQUE (old, new)
);
INSERT INTO history_allowed_pattern
(old, new)
VALUES
@cimmanon
cimmanon / SassMeister-input.scss
Created February 25, 2016 23:47
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
.foo {
outline: #90b2e9 solid 1px;
outline: #90B2E9 solid 1px;
}
@cimmanon
cimmanon / SassMeister-input.scss
Created February 24, 2016 16:55
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
/**
* Little helper to create a circle
* @group control-points
* @access private
* @param {Number} $size - Circle size
* @output Dimensions, margin and border-radius
@cimmanon
cimmanon / SassMeister-input.scss
Created February 14, 2016 23:06
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
.foo {
bar: 1.5em * 2;
}
@cimmanon
cimmanon / SassMeister-input.scss
Last active February 11, 2016 13:27
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
/* test one */
.pfx {
&__one &{
&__two {
color: red;
@cimmanon
cimmanon / SassMeister-input.scss
Created February 7, 2016 20:24
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// Bourbon (v4.2.6)
// ----
@import "bourbon/bourbon";
#loader {
@include position(absolute, 0 0 0 0);