Skip to content

Instantly share code, notes, and snippets.

Avatar
🍵

Michael Penick mpenick

🍵
View GitHub Profile
@mpenick
mpenick / main.go
Created Mar 1, 2021
Minimal gocql tracing example
View main.go
package main
import (
"github.com/gocql/gocql"
"log"
)
type MyTracer struct { }
func (t *MyTracer) Trace(traceId []byte) {
View dial.go
package main
import (
"log"
"net"
"os"
"strconv"
"sync"
"sync/atomic"
"time"
View some.md

CQL tag:

CREATE ROLE IF NOT EXISTS 'web_user' WITH PASSWORD = 'web_user' AND LOGIN = TRUE;
CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'};
CREATE TABLE IF NOT EXISTS store.shopping_cart (userid text PRIMARY KEY, item_count int, last_update_timestamp timestamp);
INSERT INTO store.shopping_cart (userid, item_count, last_update_timestamp) VALUES ('9876', 2, toTimeStamp(toDate(now())));
INSERT INTO store.shopping_cart (userid, item_count, last_update_timestamp) VALUES ('1234', 5, toTimeStamp(toDate(now())));
GRANT MODIFY ON TABLE store.shopping_cart TO web_user ;
GRANT SELECT ON TABLE store.shopping_cart TO web_user;
View viewerSpaces.js
// Done in setup
let xrViewerSpace = await xrSession.requestReferenceSpace("viewer");
let xrReferenceSpace = await xrSession.requestReferenceSpace("some-space-here-like-local-bounded-etc");
// Done per frame
let xrViewerPose1 = xrFrame.getPose(xrViewerSpace, xrReferenceSpace);
View tokens.cpp
#include <cassandra.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <memory>
#include <sstream>
// Requires this PR to reliably query the same coordinator: https://github.com/datastax/cpp-driver/pull/489
View Main.java
package com.datastax;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metadata.NodeStateListener;
import com.datastax.oss.driver.internal.core.loadbalancing.DcInferringLoadBalancingPolicy;
import java.net.InetSocketAddress;
@mpenick
mpenick / radix_tree_gc.c
Last active May 11, 2020
A tiny, malloc-based GC that uses a radix tree to store GC metadata (1.5% - 3% overhead)
View radix_tree_gc.c
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define BITMAP_NUM_BITS 64
#define LG_BITMAP_NUM_BITS 6
View cloud_rr.lua
local Cluster = require 'resty.cassandra.cluster'
local Auth = require 'cassandra.auth'
local Socket = require 'cassandra.socket'
Socket.force_luasocket("timer", true)
-- For performance reasons, the cluster variable
-- should live in an upvalue at the main chunk level of your
-- modules to avoid creating it on every request.
View cloud.lua
-- To run:
-- # cd <some-path>/lua-cassandra
-- # LUA_PATH="lib/?/init.lua;lib/?.lua" resty --errlog-level info --shdict 'cassandra 1m' cloud.lua
local Cluster = require 'resty.cassandra.cluster'
local Auth = require 'cassandra.auth'
local Socket = require 'cassandra.socket'
-- Use luasocket
Socket.force_luasocket("timer", true)
View nulls.cql
CREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '1'};
CREATE TYPE IF NOT EXISTS test.mytype(a int, b text);
CREATE TABLE IF NOT EXISTS test.table_nulls (key text, s set<int>, m map<text, int>, l list<text>, t tuple<int, text>, u mytype, PRIMARY KEY(key));
// set
INSERT INTO test.table_nulls (key, s) VALUES ('set_null', {null}) ;
// list
INSERT INTO test.table_nulls (key, l) VALUES ('list_null', {null}) ;