Skip to content

Instantly share code, notes, and snippets.

View rbishop's full-sized avatar

Richard Bishop rbishop

View GitHub Profile
@rbishop
rbishop / carl_hewitt_actor_model.md
Last active April 3, 2024 06:58
Notes from Carl Hewitt on the Actor Model

Carl Hewitt on Actors

Actor - Fundamental unit of computation, a computation model - not just a form of concurrency

An Actor has three essential elements:

  • 1 - Processing - you have to get something done
  • 2 - Storage - you have to be able to remember things
  • 3 - Communication
@rbishop
rbishop / README.md
Last active April 26, 2022 15:38
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
    [
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
    ]
  end
@rbishop
rbishop / decorator_perf.rb
Created November 20, 2013 00:40
Disclaimer: Yes, this is performance testing and Ruby. Obviously we choose Ruby for it's other greater qualities. Playing around with performance regarding the various ways you can implement Decorators in Ruby.
require 'benchmark'
require 'delegate'
require 'forwardable'
class Person
def initialize(name)
@name = name
end
def name
@rbishop
rbishop / egpu.md
Last active July 25, 2020 16:41
2013 MacBook Pro eGPU build

Context

I bought a new Dell U2720Q monitor but the onboard graphics on my 13 inch 2013 MacBook Pro (Catalina) was not powerful enough to drive it at 3840x2160@60Hz. I had been using the Apple Thunderbolt Display prior to this and I really liked how through a single Thunderbolt cable it connected the display, ethernet, and USB devices. I didn't want to buy a new laptop as this one is still powerful enough for my needs of programming and not gaming.

As such, my parameters for an enclosure were that:

  • Small form factor. A lot of enclosures such as the Sonnet Breakaway Box and Razer Core X are very large.
  • This isn't for gaming so I didn't need a beefy video card or an enclosure with a really high wattage power supply.
  • Thunderbolt 3. While my current laptop is Thunderbolt 2 I recognize I won't have it for more than 2-3 more years and will eventually have a Thunderbolt 3 computer.
  • Ethernet and USB ports on the enclosure were a plus but not a hard requirement. The idea of having as many of my peripherals
@rbishop
rbishop / object_send.js
Created January 24, 2013 04:59
So, everything is an object eh, JavaScript? Then every object should have a send method! This is just for fun of course and I pray to not be punished by the gods for extending native prototypes. How fun is it to have a ton of dynamic method dispatching at your hands though?
Object.prototype.send = function(methodName) {
args = [].slice.call(arguments);
args.shift()
if (this.hasOwnProperty(methodName)) return this[methodName];
if (args.length > 1) {
return this[methodName].apply(this, args);
} else {
return this[methodName]();
@rbishop
rbishop / repl.rb
Last active March 23, 2016 11:32
Minimal implementation of a REPL in Ruby. WAT?!
while true
line_num ||= 1
("%03d" % line_num + ' > ').display
code = gets
puts eval(code)
line_num += 1
end
@rbishop
rbishop / quicksort.ex
Created September 26, 2014 17:49
Quicksort in Elixir
# Not tail recursive and uses ++ :(
defmodule Quicksort do
def sort([]), do: []
def sort([head | rest]) do
{before, after} = Enum.partition(rest, &(&1 < head))
sort(before) ++ [head] ++ sort(after)
end
end
@rbishop
rbishop / concern.rb
Created October 3, 2013 23:54
I imagine this is due to how ActiveSupport::Concern handles dependency resolution? It's pretty surprising though because you can use most other Rails class methods (before_filter, helper_method, belongs_to, etc. etc.) in the included method's block.
module Surprisable
extend ActiveSupport::Concern
included do
attr_accessor :this_aint_gonna_work
end
end
module Wtfable
extend ActiveSupport::Concern
@rbishop
rbishop / gist:4974678
Created February 18, 2013 01:56
Fixes the issue where the fixed navigation menu in Twitter Bootstrap sits on top of your main div container.
// Add #main to the second div.container
@media (min-width: 720px) {
#main {
margin-top: 50px;
}
}
Rails.cache.fetch :group_id => group.id, :goal_id => self.id do
Post.find_by_sql(
"#{Post.where(:attachment_type => 'UserGoalLog').where(Post.arel_table[:attachment_id].in(user_goal_logs.collect(&:id))).to_sql}
UNION
#{Post.where(:attachment_type => 'UserGoal').where(Post.arel_table[:attachment_id].in(user_goals.collect(&:id))).to_sql}"
)
end