Skip to content

Instantly share code, notes, and snippets.

View carlsverre's full-sized avatar
🪐
Building SQLSync

Carl Sverre carlsverre

🪐
Building SQLSync
View GitHub Profile
create database kv;
use kv;
/*
possibly add a namespace to all of this
lets start with BLOB for values
GLOBAL:
exists key
@carlsverre
carlsverre / analytics_graph.sql
Created January 21, 2022 02:45
Example of using a graph model for analytics
DROP database if exists analytics;
CREATE DATABASE analytics;
USE analytics;
CREATE TABLE entities (
ts DATETIME(6) NOT NULL,
id BIGINT NOT NULL,
kind TEXT NOT NULL,
SORT KEY (ts, id),
@carlsverre
carlsverre / analytics_visitors.sql
Last active January 21, 2022 23:31
Example of an analytics schema including a visitors table as well as a property bag for each event with multiple value datatypes
DROP database if exists analytics;
CREATE DATABASE analytics;
USE analytics;
create table visitors (
visitor_id BIGINT NOT NULL,
props JSON NOT NULL,
PRIMARY KEY (visitor_id)
);
@carlsverre
carlsverre / setup.sh
Created December 9, 2021 22:57
Setup script for google cloud instances with local disks
#!/usr/bin/env bash
set -euo pipefail
METADATA_BASE="http://metadata.google.internal/computeMetadata/v1/instance/attributes"
log() {
local msg="${*}"
logger -p syslog.info -t "startup-script" -- "${msg}"
}
@carlsverre
carlsverre / setup.sh
Created July 16, 2021 16:11
Setup HTTP api on all SingleStore Aggregators
sdb-admin list-nodes --role aggregator -q \
| xargs -I NODEID sdb-admin -y update-config --memsql-id NODEID --key http_api --value on
sdb-admin list-nodes --role aggregator -q \
| xargs -I NODEID sdb-admin -y update-config --memsql-id NODEID --key http_proxy_port --value <port>
sdb-admin list-nodes --role aggregator -q \
| xargs -I NODEID sdb-admin -y query --memsql-id NODEID --sql "RESTART PROXY"
@carlsverre
carlsverre / !SingleStore Data Hiding Demo.md
Last active June 30, 2021 17:13
Simple data hiding demo using RBAC in SingleStore

This is an example of how you can use RBAC and the CURRENT_SECURITY_GROUPS function to implement data hiding in SingleStore.

  1. Get a SingleStore free license key from https://portal.singlestore.com
  2. Set your SingleStore license key as an environment variable
export LICENSE_KEY="PUT YOUR LICENSE KEY HERE"
  1. Run SingleStore cluster in a box
docker run -it \
create database if not exists t;
create database if not exists t2;
use t;
create table if not exists x (id int);
delimiter //
create or replace procedure foo (i int) as
begin
@carlsverre
carlsverre / README.md
Created December 9, 2020 00:02
Output all the IP addresses (not CIDR's) for each of the major cloud providers (gcp, azure, aws)
  1. Download process.py
  2. Run
~/csp $ python3 process.py
usage: process.py aws|azure|gcp

~/csp $ python3 process.py aws | head -n 10
3.5.140.0
3.5.140.1
@carlsverre
carlsverre / ec2-ephemeral-setup.sh
Created July 15, 2020 17:30
Setup & merge all ephemeral drives on an EC2 instance
#!/usr/bin/env bash
set -eux
DEVICES=$(ls /dev | egrep -o nvme.n1 | sort -u | grep -v $(df -h | egrep -o nvme.n1) | sed 's_\<_/dev/_g')
echo "Setting up the following devices:"
echo ${DEVICES}
read -p "Are you sure? " -n 1 -r
echo