Skip to content

Instantly share code, notes, and snippets.

View lucaswinningham's full-sized avatar

Lucas Winningham lucaswinningham

View GitHub Profile
@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]
$ rails g scaffold_controller foo
app/controllers/foos_controller.rb
class FoosController < ApplicationController
  before_action :set_foo, only: [:show, :update, :destroy]
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.

@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)
@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 / how_to.md
Created December 8, 2020 19:49
Semi-monthly iCalendar Recurring Event (Pay Day)

Create an ics file

$ touch pay_day.ics

pay_day.ics

BEGIN:VCALENDAR
@lucaswinningham
lucaswinningham / how_to.md
Created May 19, 2021 18:20
Recursively source bash files
#!/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
@lucaswinningham
lucaswinningham / entry.rb
Last active September 29, 2023 13:35
Simple Ruby Middleware Chain
# 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
@lucaswinningham
lucaswinningham / character_displays.rb
Created August 7, 2023 12:35
5x7 matrix display of essential ascii characters.
# 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