Skip to content

Instantly share code, notes, and snippets.

View maxjustus's full-sized avatar

Max Justus Spransy maxjustus

  • People With Jetpacks
  • Los Angeles, CA
View GitHub Profile
@maxjustus
maxjustus / clickhouse-client-examples.sh
Last active May 24, 2024 17:25
clickhouse client examples
# The clickhouse client --format flag specifies the output format of query results that
# get printed to the console by clickhouse client. There are a many options. See: https://clickhouse.com/docs/en/interfaces/formats
# The Null format will not print any query results for the console, which in this case is useful because we are only
# interested in analyzing the trace logs that are printed to the console and any query output just adds noise.
# inline query example:
clickhouse client --send-logs-level="trace" --database=test --progress --query="select* from system.numbers limit 10;" --format=Null
# Multi statement query file example:
echo "
@maxjustus
maxjustus / sqlglot_transform.py
Created May 2, 2024 23:01
simple example of using transform with sqlglot to implement custom rewrite rules
from sqlglot import exp, parse_one
expression_tree = parse_one("SELECT a FROM x")
def transformer(node):
if isinstance(node, exp.Column) and node.name == "a":
return parse_one("FUN(a)")
return node
transformed_tree = expression_tree.transform(transformer)
require "minitest/autorun"
require 'yaml'
`make test-render`
def flatten_hash(object, current_path = [], result = {})
case object
when Hash
object.each do |key, value|
flatten_hash(value, current_path + [key], result)
@maxjustus
maxjustus / pipe.sh
Created February 21, 2024 20:02
Pipe a continuous stream into a clickhouse table and insert in chunks
./s5cmd ls s3://mybucket/* | parallel --pipe -N 1000 'clickhouse client --query "insert into some_table FORMAT TSVRaw settings async_insert=1"'
sed 's/,/,:/g' my_file.csv | column -t -s:
#!/usr/bin/env ruby
require 'bundler/inline'
begin
gemfile do
source 'https://rubygems.org'
gem 'tty-prompt', '~> 0.23.1', require: false
end
rescue => e
@maxjustus
maxjustus / parmap.go
Created September 13, 2023 00:20
golang parallelMap
func parallelMap[T any, V any](input []T, f func(T) (V, error)) ([]V, error) {
outChan := make(chan V, len(input))
errChan := make(chan error, len(input))
for i, val := range input {
go func(i int, val T) {
out, err := f(val)
if err != nil {
errChan <- err
} else {
@maxjustus
maxjustus / as-source.tsx
Created November 5, 2020 23:37
A stencil functional component for rendering the children element's markup in a <code> element along side the rendered jsx
import { h, ChildNode, FunctionalComponent, FunctionalUtilities } from "@stencil/core";
function vnodeToSource(elem: ChildNode, utils: FunctionalUtilities, output = "", level = 0): string {
if (elem.vchildren) {
let childOutput: string[] = [];
utils.forEach(elem.vchildren, (child) => {
childOutput.push(vnodeToSource(child, utils, output, level + 1));
});
@maxjustus
maxjustus / openssl_tls_1.2.patch
Last active March 15, 2017 20:58 — forked from kriansa/openssl_tls_1.2.patch
Source patch to add support to TLS 1.1 and 1.2 to Ruby 1.9.3
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -107,6 +107,18 @@
OSSL_SSL_METHOD_ENTRY(TLSv1),
OSSL_SSL_METHOD_ENTRY(TLSv1_server),
OSSL_SSL_METHOD_ENTRY(TLSv1_client),
+#if defined(HAVE_TLSV1_2_METHOD) && defined(HAVE_TLSV1_2_SERVER_METHOD) && \
+ defined(HAVE_TLSV1_2_CLIENT_METHOD)
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2),
@maxjustus
maxjustus / active_record_extensions.rb
Created January 6, 2016 20:08
Little active record extension to make zero downtime column removal a lil more convenient in Rails
# Put this in config/initializers
module ActiveRecord
class Base
def self.removed_columns(*names)
@@removed_columns = Set.new(names.map(&:to_s))
instance_eval do
def columns
cols = super
cols.reject { |col| @@removed_columns.include?(col.name) }