View queuing.rb
class Node | |
attr_accessor :edges, :jobs, :id | |
def initialize(id, arrivals_per_tick) | |
@id = id | |
@jobs = 0.0 | |
@tick = 0 | |
@edges = [] | |
@arrivals_per_tick = arrivals_per_tick | |
end |
View zettelkasten-search.rb
require "sqlite3" | |
require 'set' | |
require 'byebug' | |
# Will be rebuilt at any time. Nice and incremental. | |
db = SQLite3::Database.new "index.db" | |
# Keep prefix indexes for "mos*" searches. | |
# | |
# TODO: It doesn't seem like SQLITE FTS5 supports synonyms well. That's ok, but | |
# we're going to want that. We can download this database from Princeton, write |
View black_box.rs
use std::io::{Read, Seek, SeekFrom, Write}; | |
use std::slice; | |
use std::time::Instant; | |
use std::{fs::OpenOptions, io::Result}; | |
use std::ptr; | |
use std::mem::forget; | |
const BUF_SIZE: usize = 1024 * 32; | |
const FILE_SIZE: usize = 1024 * 1024 * 512; | |
const QUEUE_DEPTH: usize = 32; |
View sequantial_io.rs
use std::{fs::OpenOptions, io::Result}; | |
use std::io::{Read, Write, Seek, SeekFrom}; | |
use std::slice; | |
use std::time::Instant; | |
const BUF_SIZE: usize = 1024 * 32; | |
const FILE_SIZE: usize = 1024 * 1024 * 512; | |
const QUEUE_DEPTH: usize = 32; | |
fn main() -> Result<()> { |
View ping_less.rb
# frozen_string_literal: true | |
# By default, ActiveRecord will issue a PING command to the database to check | |
# if it is active at various points. This overhead is unnecessary; we instead | |
# attempt to issue queries without checking the connection, then if the query | |
# returns an error and the connection was closed, try to reconnect. | |
# This also allows for reconnection during a single UoW, improving resiliency | |
# under transient connection failure (e.g. ProxySQL restarts). | |
# | |
# To avoid amplifying load when a database is intermittently down, the attempt |
View book.rb
class Book < Airrecord::Table | |
class Endorser < Airrecord::Table | |
self.base_key = "" | |
self.table_name = "Endorser" | |
end | |
self.base_key = "" | |
self.table_name = "Books" | |
has_many :endorsements, class: 'Book::Endorser', column: 'Endorsements' |
View setup.sh
WORKDIR="/home/vagrant/src" | |
clone_repo() { | |
local name=$1; shift | |
local repo=$1; shift | |
if [[ ! -d "$WORKDIR/$name" ]]; then |
View gist:f3111d7f12f9d736d68a
def load_customer | |
if customer_id = session[:customer_id] | |
@customer = Customer.find_by_id(session[:customer_id]) | |
end | |
# in reality e.g. a redis exception thrown from the driver | |
# could be raised from circuit breaker or semian as well (see later) | |
rescue Sessions::DataStoreUnavailable | |
flash[:notice] = 'Customer sign in is currently unavailable' | |
@customer = nil | |
end |
View gist:44f6c7293f25cf69382d
def test_storefront_resilient_to_sessions_down | |
Toxiproxy[:sessions_data_store].down do | |
get '/' | |
assert_equal 'Customer sign in is currently unavailable', flash[:notice] | |
assert_response :success | |
end | |
end |
View gist:3b3762c74355f42ac7bc
def load_customer | |
if customer_id = session[:customer_id] | |
@customer = Customer.find_by_id(customer_id) | |
end | |
end |
NewerOlder