Skip to content

Instantly share code, notes, and snippets.

View RomanTurner's full-sized avatar
🤫

Roman RomanTurner

🤫
View GitHub Profile
@RomanTurner
RomanTurner / railsconf_2022.md
Created May 7, 2022 21:55
RailsConf 2022 Schedule

Rails Conference Schedule

TUESDAY

Leveling up. From Planning to Production

By: Tomas Countz Room: Portland BR 254

  • 10:40am-11:10am Leveling up. From Planning to Production BR 254

Rails C With Me: The Interactive Console as a Superpower

@RomanTurner
RomanTurner / clean_code.md
Created July 6, 2022 16:43 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@RomanTurner
RomanTurner / error_serializer.rb
Last active July 13, 2022 04:37
Error Serializer
class ErrorSerializer
attr_accessor :request, :params, :errors
def initialize(request, params, errors = [], exception = nil)
@request = request
@params = params
@errors = errors
@exception = exception
end
@RomanTurner
RomanTurner / vite_rephlex.rb
Last active October 1, 2024 22:15
Tag helpers for ViteRuby using the Phlex component gem.
module ViteRephlex
module PhlexHelpers
class OohBabyILikeItRaw < Phlex::HTML
def initialize(tag:)
@tag = tag
end
def template
@tag.is_a?(Array) ? @tag.each { |t| unsafe_raw(t) } : unsafe_raw(@tag)
end
end
@RomanTurner
RomanTurner / roda_phlex.rb
Last active July 16, 2023 16:21
A plugin for Roda for using Phlex as the rendering library of choice.
class Roda
module RodaPlugins
module Phlex
def self.configure(app, opts)
app.opts[:class_name] = app.name
app.opts[:phlex] = opts
end
module InstanceMethods
# Render a component with the default layout.
@RomanTurner
RomanTurner / tailwind_phlex.rb
Last active July 16, 2023 23:17
POC Tailwind + Phlex component.
class StyledComponent < Phlex::HTML
STYLES = {
container: {
xs: "mx-auto max-w-7xl px-6 py-24",
sm: "sm:py-32",
lg: "lg:px-8"
},
get_started: {
@RomanTurner
RomanTurner / accessor.js
Created April 27, 2023 15:45
Testing speed of lookups
// // Generate a large sorted array of random integers
const arraySize = 1500;
const amountOfRecipes = 1000;
const sortedArray = Array.from({ length: arraySize }, (_, i) => i).sort(
(a, b) => a - b
);
const jsonArray = JSON.stringify(sortedArray);
function binarySearch(arr, val) {
@RomanTurner
RomanTurner / vite_rephlex.rb
Created November 9, 2023 01:36
Phlex + ViteRuby
# frozen_string_literal: true
require 'phlex'
require 'vite_ruby'
module ViteRephlex
module PhlexHelpers
class OohBabyILikeItRaw < Phlex::HTML
def initialize(tag:)
@tag = tag
@RomanTurner
RomanTurner / haml_components.rb
Created November 18, 2023 05:04
View Components- With Haml 😅
require "haml"
module Hamlet
def self.included(base)
base.extend ClassMethods
end
def render
engine = Haml::Template.new { self.class.get_element }
engine.render(self)
@RomanTurner
RomanTurner / pattern_matching.rb
Last active February 1, 2024 16:14
Ruby Pattern Matching
class Response
attr_reader :status, :data
def initialize(status, data)
@status = status
@data = data
end
def deconstruct
by_status