Skip to content

Instantly share code, notes, and snippets.

View mpenick's full-sized avatar
🍵

Michael Penick mpenick

🍵
View GitHub Profile
"log"
"net"
"time"
)
func loadBytes(file *zip.File) ([]byte, error) {
r, err := file.Open()
if err != nil {
return nil, err
}
@mpenick
mpenick / main.go
Created March 1, 2021 17:44
Minimal gocql tracing example
package main
import (
"github.com/gocql/gocql"
"log"
)
type MyTracer struct { }
func (t *MyTracer) Trace(traceId []byte) {
@mpenick
mpenick / dial.go
Last active December 4, 2020 18:13
package main
import (
"log"
"net"
"os"
"strconv"
"sync"
"sync/atomic"
"time"
@mpenick
mpenick / some.md
Last active December 3, 2020 15:24

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;
// 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);
#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
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 14:32
A tiny, malloc-based GC that uses a radix tree to store GC metadata (1.5% - 3% overhead)
#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
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.
-- 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)