Skip to content

Instantly share code, notes, and snippets.

View bobvawter's full-sized avatar

Bob Vawter bobvawter

View GitHub Profile
@bobvawter
bobvawter / gist:5f119dcbec8a4e7e1667e068ef1bf00e
Created May 8, 2023 21:27
Version 1 UUID to Timestamp in CockroachDB or PostgreSQL
WITH u (u) AS (VALUES ('4d1e53e2-a182-11ed-a4bf-3f161938a1c4'::UUID::BYTES))
SELECT to_timestamp(
(
(
get_byte(u, 0) << 24
| get_byte(u, 1) << 16
| get_byte(u, 2) << 8
| get_byte(u, 3) << 0
| get_byte(u, 4) << 40
| get_byte(u, 5) << 32
@bobvawter
bobvawter / 00_readme.md
Last active February 8, 2023 20:59
Entity Attribute Timestamp Value in CockroachDB or PostgreSQL

This demonstrates the use of the last_value() window function over a entity-attribute-timestamp-value table in CockroachDB v22.2 to pivot it into a more conventional form. This works in PostgreSQL, too.

It is important to note that even though the last_value() aggregate is operating on windows of data OVER (PARTITION BY entity, attribute ...) the use of the ORDER BY updated_at causes the default window frame to include data only up to the current row in the window. In order to create the desired lookahead behavior, the window frame must be expanded with ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING so that last_value() can indeed see the last value in the window.

Cockroach Labs Enterprise Architect Take-Home Exercise

v2.0

Thank you for being interested in a position at Cockroach Labs! As a part of our interview process, we like to have candidates get their hands dirty with the product. This allows you to get a feel for what it’s like to work with our platform, and it gives us an opportunity to determine where best you will fit in the organization.

You can spend as much time as you’d like working on this exercise, but if you haven’t been able to get through the core portion of it in 2-4 hours please let us know. The extra credit is just that, EXTRA, so don’t feel like you need to do any or all of it. But successful Roachers tend to go above and beyond in at least one area. Don’t feel like it needs to be one of our suggestions though - be creative!

High-Level Goals

Core:

@bobvawter
bobvawter / contention.sql
Last active November 10, 2021 21:02
Summarize contention events in CockroachDB
WITH c AS (
SELECT DISTINCT ON (table_id, index_id)
table_id,
index_id,
num_contention_events AS events,
cumulative_contention_time AS times
FROM crdb_internal.cluster_contention_events
)
SELECT i.descriptor_name, i.index_name, c.events, c.times
FROM crdb_internal.table_indexes AS i
@bobvawter
bobvawter / ReadWriteMutex.kt
Created August 30, 2017 16:19
A very basic Kotlin-Coroutines ReadWriteMutex example
/**
* Copyright 2017 ModelBox Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@bobvawter
bobvawter / description.md
Last active March 24, 2016 19:39
Validation thoughts

If the value != null assertion fails in the leaf component, want the validation root to produce an error object that looks like

{
  "leaf": {
    "inner": {
      "required": true
    }
  }
}
@bobvawter
bobvawter / logging.md
Last active December 19, 2015 16:49
On Logging and Smoothies

#On Logging and Smoothies

At Perka, we have a logging system called "Firehose" that integrates every HTTP envelope, API payload, event dispatch, database query, thrown exception, and console message into a unified dashboard. The dashboard has views for triaging production issues, allowing all records associated with a particular HTTP request to be displayed, and it also supports data-mining by writing JavaScript reduction scripts. Firehose has been a good experiment in determining what "useful logging" really means.

Useful logs should be:

  • Comprehensive
  • Correlated
  • Clearly actionable

Will it blend?