Skip to content

Instantly share code, notes, and snippets.

View cobusc's full-sized avatar

Cobus Carstens cobusc

View GitHub Profile
swagger: "2.0"
info:
title: Catalogue API version 2
description: The new generation Catalogue API
version: "1.0.0"
host: catalogue-api-v2.master.env
schemes:
- http
produces:
- application/json
@cobusc
cobusc / lookups.md
Last active July 9, 2020 10:32
PostgreSQL comparison of IN, ANY, VALUES

Different options

1. For very big sets, create a temporary table with an indexed column and do a SELECT with a JOIN.

2. For large sets, use VALUES. It will create a table like structure which can be JOINed with.

catalogue=> explain select productline_id from productline_tsin_product as ptp, (values (1), (7), (9), (4), (123), (1234)) as lookup where ptp.productline_id = lookup.column1;
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                          QUERY PLAN                                                          │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
@cobusc
cobusc / test_transformation.py
Last active December 4, 2023 18:23
Python dictionary transformations useful for mapping generated model classes to each other
from datetime import date, timedelta
from unittest import TestCase
from integration_layer.transformation import Mapping, Transformation
def tomorrow(today: date) -> date:
return today + timedelta(days=1)
class TestTransformation(TestCase):
@cobusc
cobusc / protected_media.md
Last active August 31, 2021 17:32
Protected Media in Django

Protected Media in Django

Introduction

Django manages media based on the following definitions:

BASE_DIR = /var/praekelt/telkom-spliceworks/
MEDIA_ROOT = "%s/media/" % BASE_DIR
@cobusc
cobusc / System Design.md
Created April 18, 2016 06:44 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Interview Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@cobusc
cobusc / postgres_queries_and_commands.sql
Created April 13, 2016 08:23 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@cobusc
cobusc / category_trees.md
Created September 15, 2015 12:46
Category trees revisited

Category trees revisited

Introduction

Category trees are an important classification utility for e-commerce sites. It is allows similar products to be grouped in a single category and related categories to be grouped together, e.g.

Games + Platform + Xbox
@cobusc
cobusc / why_postgresql.md
Last active August 29, 2015 14:23
Why Postgresql

The good stuff

  • Aggregate functions
  • Function indexes
  • Partial indexes
  • CTEs (WITH clauses)
  • FDW (foreign data wrappers)
  • Interesting types
    • Array
  • UUID
@cobusc
cobusc / rotate_backend_server.sh
Created March 3, 2015 04:58
Helper script to rotate varnish backends
#!/bin/bash
# This script is can be used to enable/disable varnish backends associated
# with a specified server. The state of the varnish backends are displayed
# after the changes have been applied.
#
# At the time of writing the varnish backend names are constructed as a
# concatenation of the servername (with hyphens replaced by underscores) and
# the port on which it listens.
#
@cobusc
cobusc / jsonvi.sh
Created November 12, 2014 07:11
Utility to validate, pretty-print and syntax highlight JSON data
#!/bin/bash
#
# Utility to display JSON data in a pretty-printed, syntax highlighted form.
# If the data is not valid JSON, an error will be reported.
#
# An optional filename can be specified, otherwise input is read from stdin.
#
set -o pipefail