Skip to content

Instantly share code, notes, and snippets.

View lucaswinningham's full-sized avatar

Lucas Winningham lucaswinningham

View GitHub Profile
@lucaswinningham
lucaswinningham / how_to_create_a_class_dynamically_in_ruby.md
Last active December 2, 2020 13:40
How to create a class dynamically in Ruby
@lucaswinningham
lucaswinningham / callbacks.md
Last active November 14, 2020 16:44
Rails Notes
module AppCallbacks
  extend ActiveSupport::Concern

  included do
    include ActiveSupport::Callbacks
  end

  class_methods do
    def define_app_callbacks(*callback_names)

poodr quotes

[Regarding refactoring and good design practices:] They are needed, not because the design is clear, but because it isn't. You don't have to know where you're going to use good design practices to get there. Good practices reveal design.

The code is not perfect, but in some ways it achieves a higher standard: it is good enough.

class Rx
class Subject
def initialize
@pipes = []
end
def next(object)
threads = @pipes.map { |pipe| Thread.new { pipe.push object } }
threads.each(&:join)
end
$ rails g scaffold_controller foo
app/controllers/foos_controller.rb
class FoosController < ApplicationController
  before_action :set_foo, only: [:show, :update, :destroy]
@lucaswinningham
lucaswinningham / bot_trust.rb
Last active August 17, 2017 12:54
Bot Trust Code Jam
def process_sequence(sequence, last_robot_letter="B", robots={"B" => {position: 1, time: 0}, "O" => {position: 1, time: 0}})
robot_letter = sequence.shift
current_robot_position = robots[robot_letter][:position]
current_robot_time = robots[robot_letter][:time]
next_robot_position = sequence.shift.to_i
next_robot_time = (current_robot_position - next_robot_position).abs + current_robot_time
last_robot_time = robots[last_robot_letter][:time]