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 / 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 / xv6-setup-yosemite.sh
Last active September 28, 2020 12:10
Get xv6 running with QEMU on OSX Yosemite
#! /usr/bin/env bash
# Get xv6 working with OSX Yosemite
# Most things were here: https://doesnotscale.com/compiling-xv6-on-os-x-10-9/
# You need homebrew installed to make this thing work
brew tap homebrew/versions && brew install gcc48
brew deps qemu | xargs brew install
export PATH=/usr/local/bin:$PATH
export CC=/usr/local/bin/gcc-4.8
brew install wget
@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 / 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>
@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