$ rails g scaffold_controller foo
class FoosController < ApplicationController
before_action :set_foo, only: [:show, :update, :destroy]
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] |
class Rx | |
class Subject | |
def initialize | |
@pipes = [] | |
end | |
def next(object) | |
threads = @pipes.map { |pipe| Thread.new { pipe.push object } } | |
threads.each(&:join) | |
end |
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.
module AppCallbacks
extend ActiveSupport::Concern
included do
include ActiveSupport::Callbacks
end
class_methods do
def define_app_callbacks(*callback_names)
Taken from this answer on StackOverflow
name = "Person"
attributes = [:name, :age]
class MyBaseClass; end
klass = Class.new(MyBaseClass) do
ATTRIBUTES = attributes
#!/usr/bin/env bash
this_dir="${BASH_SOURCE%/*}"
# Recursively iterates over directories looking for .sh files sourcing them if they exist
for executable in $(find "$this_dir" -regex ".*\.sh"); do
[ -f "$executable" ] && source "$executable"
done
# frozen_string_literal: true | |
module Middleware | |
class Entry | |
attr_reader :klass, :args, :kwargs, :block | |
def initialize(klass, *args, **kwargs, &block) | |
@klass = klass | |
@args = args | |
@kwargs = kwargs |
# https://www.ascii-code.com/ | |
# https://fontstruct.com/fontstructions/show/847768/5x7_dot_matrix | |
' | |
1 2 3 4 5 6 7 8 9 0 | |
a b c d e f g h i j k l m n o p q r s t u v w x y z | |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | |
' | |
# 00 01 02 03 04 | |
# 05 06 07 08 09 |