This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class encapsulates a unit of work done for a particular tenant, connected to that tenant's database. | |
# ActiveRecord makes it _very_ hard to do in a simple manner and clever stuff is required, but it is knowable. | |
# | |
# What this class provides is a "misuse" of the database "roles" of ActiveRecord to have a role per tenant. | |
# If all the tenants are predefined, it can be done roughly so: | |
# | |
# ActiveRecord::Base.legacy_connection_handling = false if ActiveRecord::Base.respond_to?(:legacy_connection_handling) | |
# $databases.each_pair do |n, db_path| | |
# config_hash = { | |
# "adapter" => 'sqlite3', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <%= style_for_this_template do %> | |
# width: 128px; | |
# .caption { | |
# font-size: 12px; | |
# text-align: center; | |
# } | |
# <% end %> | |
# <div class="<%= css_class_for_this_template %>"> | |
# <div class="title">Hello!</div> | |
# </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
require "logger" | |
gemfile do | |
source 'https://rubygems.org' | |
gem "activerecord", "~> 6", require: "active_record" | |
gem "sqlite3", "~> 1.1" # This has to be of a version activerecord supports, so can't be 2.x | |
end | |
16.times do |n| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'premailer' | |
gem 'nokogiri' | |
gem 'base64' | |
gem 'mail' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
.outlinerounded { | |
width: 1px; height: 1px; overflow: hidden; border: 1px solid gray; | |
} | |
</style> | |
</head> | |
<body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "openssl" | |
require "stringio" | |
class PassthruScheme | |
READ_OR_WRITE_CHUNK_SIZE = 1 << 16 | |
def streaming_encrypt(from_plaintext_io, into_ciphertext_io) | |
while (chunk = from_plaintext_io.read(READ_OR_WRITE_CHUNK_SIZE)) | |
into_ciphertext_io.write(chunk) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "test_helper" | |
class BlockwiseEncryptionTest < ActiveSupport::TestCase | |
class NonRandomAccessible | |
def initialize(encryption_key) | |
@algo = "aes-256-cfb" | |
@iv_and_key_length = 16 + 32 | |
@key_derivation_salt = "my desire" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# This script will build a Docker image from the current state of the working tree. | |
# It will tag it with the short Git sha, and then push it to Quay.io under our company | |
# account. Afterwards the image can be picked up from other hosts to deploy. | |
export DEPLOY_HOST=<someapp>.<my-domain> | |
export REV=`git log -1 --pretty=%h` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StreamingController < ApplicationController | |
class Writer | |
def initialize(&blk) | |
@blk = blk | |
end | |
def write(stuff) | |
@blk.call(stuff) | |
stuff.bytesize | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Pecobox is a Circuitbox-like class which uses Pecorino for | |
# measurement error rates. It is less resilient than Circuitbox | |
# because your error stats are stored in the database, but guess what: | |
# if your database is down your product is already down, so there is | |
# nothing to circuit-protect. And having a shared data store for | |
# the circuits allows us to track across machines and processes, so | |
# we do not have to have every worker hammer at an already failing | |
# resource right after start |
NewerOlder