Skip to content

Instantly share code, notes, and snippets.

View bryanp's full-sized avatar

Bryan Powell bryanp

View GitHub Profile
@bryanp
bryanp / about.md
Last active December 29, 2021 16:51
Ruby Routines
  • Performs routines concurrently in one or more reactors, each reactor runnning in its own thread.

  • Does not back routines with fibers or threads because of their overhead. Instead routines are defined as a block that is called on each tick of the reactor until the routine says it's finished. The block is given the underlying routine that can hold state, etc. It's a different way of coding as the routine cannot be paused or resumed like fibers can.

  • Reactors are as equitable as possible when allocating compute time. Developers define a compute "unit" in terms of one call of their routine's block. Reactors call one tick of every routine in sequence. This is kind of similar to reductions in Erlang, but differs in that it gives each routine one tick instead of counting.

@bryanp
bryanp / analytics.js
Created April 19, 2021 23:25
Proc Analytics
pw.define("analytics", {
authorization: null,
constructor() {
window.fetch(this.config.authorization + `?authenticity=${this.config.authenticity}`).then(async (response) => {
if (response.status === 200) {
let payload = await response.json();
this.authorization = payload.authorization;
const Proc = await import("https://cdn.skypack.dev/pin/@proc.dev/client@v0.7.1-nFcLiK6mvVvvyFLjxzU1/mode=imports,min/optimized/@proc.dev/client.js");
@bryanp
bryanp / input.rb
Created January 25, 2020 20:38
Ruby Monads
require "dry/monads"
include Dry::Monads[:maybe]
class Presenter
class << self
def presents(name, &block)
presentations[name] = block
end
def perform(**presentables)
@bryanp
bryanp / inflection.rb
Created December 3, 2019 23:20
Global Instance Pattern
require "forwardable"
module Inflection
class Inflector
def pluralize(string)
string + "s"
end
end
class << self
@bryanp
bryanp / allocations.rb
Created October 17, 2019 00:56
Ruby allocation calling mixin
module Foo
def foo
bar
end
def bar
end
end
class Whatever
@bryanp
bryanp / error.txt
Created October 15, 2019 16:04
sassc docker error
/usr/app/vendor/bundle/ruby/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:112: [BUG] Illegal instruction at 0x00007f6b11b55285
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0052 p:---- s:0269 e:000268 CFUNC :open
c:0051 p:0022 s:0263 e:000262 BLOCK /usr/app/vendor/bundle/ruby/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:112 [FINISH]
c:0050 p:---- s:0254 e:000253 CFUNC :each
c:0049 p:0113 s:0250 e:000249 BLOCK /usr/app/vendor/bundle/ruby/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:109 [FINISH]
c:0048 p:---- s:0243 e:000242 CFUNC :map
c:0047 p:0069 s:0239 e:000238 METHOD /usr/app/vendor/bundle/ruby/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:99
c:0046 p:0079 s:0232 e:000231 CLASS /usr/app/vendor/bundle/ruby/2.6.0/gems/sassc-2.2.1/lib/sassc/native.rb:11
@bryanp
bryanp / human.rb
Last active March 15, 2019 04:27
Log4r Formatters
# frozen_string_literal: true
require "log4r"
require "pakyow/connection"
require "pakyow/error"
require "pakyow/logger/colorizer"
require "pakyow/logger/timekeeper"
@bryanp
bryanp / proxy.rb
Created February 20, 2019 01:00
Ruby Async Proxy
class Proxy
def initialize(port:, host:)
@port, @host = port, host
@destination = "#{@host}:#{@port}"
@client = Async::HTTP::Client.new(
Async::HTTP::URLEndpoint.parse(
"http://#{@destination}"
)
)
end
@bryanp
bryanp / detect.rb
Created September 21, 2018 14:54
Detect Platform Health Checks
# Platform health check ip addresses.
#
HEALTH_CHECK_ADDRS = [
IPAddr.new("209.85.152.0/22"),
IPAddr.new("209.85.204.0/22"),
IPAddr.new("35.191.0.0/16"),
IPAddr.new("130.211.0.0/22"),
IPAddr.new("35.191.0.0/16")
]
@bryanp
bryanp / detect.rb
Last active January 24, 2018 12:54
Detect Optional Keyword Arguments in Ruby
NOT_PASSED = Object.new
def foo(bar: NOT_PASSED)
if bar.equal?(NOT_PASSED)
...
end
end