Skip to content

Instantly share code, notes, and snippets.

View film42's full-sized avatar
✔️
Verified

Garrett Thornburg film42

✔️
Verified
View GitHub Profile
@film42
film42 / a_usage.py
Created October 24, 2024 22:08
Write a dataframe to BigQuery using the Storage Write API with Flexible Columns with dynamic protos
# NOTE: The BigQueryTable class is something we wrote to wrap a bunch of operations and migrate tables,
# but you can catch the gist of what we're doing. Converting types is not the hard part.
#
# NOTE: The protobuf descritpor comes from: https://github.com/googleapis/googleapis/blob/master/google/cloud/bigquery/storage/v1/annotations.proto
import big_query_storage_write_api as s
s.to_gbq(
df=df,
table=internal.BigQueryTable("some_table"),
@film42
film42 / tokio_diesel.rs
Created August 3, 2021 20:09
Forked tokio diesel
use async_trait::async_trait;
use diesel::{
connection::SimpleConnection,
dsl::Limit,
query_dsl::{
methods::{ExecuteDsl, LimitDsl, LoadQuery},
RunQueryDsl,
},
r2d2::{ConnectionManager, Pool, R2D2Connection},
result::QueryResult,
@film42
film42 / Counting.actor.cpp
Last active January 17, 2019 03:23
Simple example using foundationdb's Flow
#include <iostream>
#include <vector>
#include "flow/flow.h"
#include "flow/DeterministicRandom.h"
#include "flow/actorcompiler.h"
// Simple counting actor that:
// 1. Logs a tag on start and finish.
// 2. Waits for some time.
// 3. Returns the new number.
@film42
film42 / sketching_a_disk_backed_queue.rb
Last active August 27, 2017 20:37
Exploring different back pressure mechanism for active publisher
require "pstore"
require "thread"
require "securerandom"
module ActivePublisher
module Async
module DiskBackedQueue
class Page
attr_reader :file_path
@film42
film42 / redirect.go
Created August 24, 2017 00:32
If you need to go from io.Reader to io.Reader but need to do a streaming io.Writer -> io.Reader before hand, this redirects the output
type NoOpWriteCloser struct {
writer io.Writer
}
func (c *NoOpWriteCloser) Write(p []byte) (int, error) {
return c.writer.Write(p)
}
func (c *NoOpWriteCloser) Close() error {
return nil
}
@film42
film42 / tls_cert_key_and_ca_jruby.rb
Created April 9, 2017 22:49
Load a x509 cert + rsa key and x509 ca and create an sslcontext in java using jruby. This took me a few hours to figure out since I wasn't super familiar with java, but here you go! Btw, you'll notice I'm using bouncycastle which is fine because it's a dependency of jruby-openssl. So as long as you require "openssl" this should work out of the box.
require "openssl"
def create_ssl_context(options)
# Create our certs and key converters to go from bouncycastle to java.
cert_converter = org.bouncycastle.cert.jcajce.JcaX509CertificateConverter.new
key_converter = org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter.new
# Load the certs and keys.
tls_ca_cert = cert_converter.getCertificate(read_pem_object_from_file(options[:tls_ca_cert]))
tls_client_cert = cert_converter.getCertificate(read_pem_object_from_file(options[:tls_client_cert]))
@film42
film42 / pg.rb
Last active April 3, 2017 03:09
require "socket"
class Client
def initialize(addr, port, user, db)
@user = user
@db = db
@socket = TCPSocket.new(addr, port)
end
def login_packet
module Protobuf
module Nats
class ThreadPool
def initialize(size, opts = {})
@queue = ::Queue.new
@active_work = 0
# Callbacks
@error_cb = lambda {|_error|}
# frozen_string_literal: true
module Arel
module Visitors
class Visitor
def initialize
@dispatch = get_dispatch_cache
@random = [0.1, 0.5, 1, 2, 4]
end
def accept object
@film42
film42 / disable-capslock-delay.c
Created December 8, 2016 02:30
Apple Aluminum Keyboard Caps Lock Delay Remover
// CREDITS HERE
// FROM: http://apple.stackexchange.com/questions/81234/how-to-remove-caps-lock-delay-on-apple-macbook-pro-aluminum-keyboard
// FROM: https://bugs.launchpad.net/mactel-support/+bug/585244
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>