Open in app

Sign In

Write

Sign In

Extreme Programming
Extreme Programming

143 Followers

Home

About

Clay Shentrup

Clay Shentrup

·Pinned

simpler enums in typescript

i often see typescript enums used as constraints for redux actions and the like. for example: enum ActionTypes { GO = 'GO', STOP = 'STOP', } export const goAction = createAction(ActionTypes.GO, (resolve) => { return (payload?: any) => resolve(payload); }); function funcThatAcceptsAnAction(action: ActionTypes) { ... } it would be far…

1 min read

1 min read


Clay Shentrup

Clay Shentrup

·Mar 8

team structures

most companies scale teams and “territory” (namely, codebases) in an unstructured, evolutionary, ad hoc way. i once watched a talk about scaling while staying agile, and it inspired me to illustrate this with a specific hypothetical structure. let’s say we have an organization which can have one or more services…

2 min read

2 min read


Clay Shentrup

Clay Shentrup

·Jun 8, 2022

num-paths exercise

our challenge is to write a function to return the number of paths we can traverse from the upper-left corner of a grid to the lower-right corner. i’ve chosen ruby as my language. MAZE = [ [0, 0, 0], [0, 1, 0], [0, 0, 0], ] def num_paths(x, y…

1 min read

1 min read


Clay Shentrup

Clay Shentrup

·Apr 25, 2022

ordered dependencies problem

problem: given a graph of dependencies, write a function to return an array of ordered dependencies. that is, no dependency comes before one of its dependencies. cycles should be detected and cause failure. DEPS = { a: %i[b c], c: %i[b d], d: %i[e], } def get_deps(deps, ancestors) deps.flat_map do |child| raise('cycle') if ancestors.include?(child) get_deps(DEPS.fetch(child, []), ancestors + [child]) + [child] end.uniq end puts get_deps(DEPS.keys, []).inspect

Ruby

1 min read

Ruby

1 min read


Clay Shentrup

Clay Shentrup

·Jan 2, 2022

Better Rails Partial Rendering

Here was my problem. I wanted to render a polymorphic array like this. = render(@animals) E.g. templates named lions/lion or tigers/tiger as the case may be for each element in the array. As you probably guessed, my application didn’t actually use big cats, but a biological hierarchy is clear for…

Ruby On Rails

3 min read

Ruby On Rails

3 min read


Clay Shentrup

Clay Shentrup

·May 1, 2021

Building Arrays with Conditional Elements in Ruby

def users [ { name: 'bob', email: 'bob@example.com' }, *([name: 'alice', email: 'alice@abc.xyz'] if inspecting_users?), { name: 'eve', email: 'eve@nsa.gov' }, ] end If inspecting_users? returns false, the returned array will contain only the first and last elements.

Ruby

1 min read

Ruby

1 min read


Clay Shentrup

Clay Shentrup

·Mar 31, 2021

Stimulus.js Lifecycle Callbacks

One common mistake I see in Stimulus controllers is that people use the connect() callback to set up event handlers when they really should be using the initialize() callback. Let’s look at the descriptions of these callbacks. It’s useful to note here that connect() and disconnect() can be called an…

Ruby On Rails

1 min read

Stimulus.js Lifecycle Callbacks
Stimulus.js Lifecycle Callbacks
Ruby On Rails

1 min read


Clay Shentrup

Clay Shentrup

·Dec 7, 2020

My RuboCop config

require: rubocop-rails AllCops: # TODO EnabledByDefault: true NewCops: enable SuggestExtensions: rubocop-rspec: false # Disagree with 90% of it. Style/MethodCallWithArgsParentheses: AllowParenthesesInMultilineCall: true Enabled: true IgnoreMacros: false Style/Documentation: Exclude: - app/controllers/**/* - app/policies/**/* - db/**/* # Worry…

Ruby

1 min read

Ruby

1 min read


Clay Shentrup

Clay Shentrup

·Sep 6, 2020

Enumerable in Go Using Generics

The latest iteration of generics is amazing. Here’s a short proof of concept for a Ruby-like enumerable construct. package main import ( "fmt" "strings" ) func newSliceEnum[T comparable](s []T) enumerable[T] { return newEnum[T](sliceEnum[T](s)) } type sliceEnum[T comparable] []T func (se sliceEnum[T]) Each(f func(T)) { for _, v := range se { f(v) } } func newEnum[T comparable](e eacher[T]) enumerable[T] { return enumerable[T]{eacher: e} }

Golang

1 min read

Golang

1 min read


Clay Shentrup

Clay Shentrup

·Jul 28, 2020

Avoid []

It’s a Risky Tool with No Clear Benefit What Avoid calling hash[key]. Instead use hash.fetch(key) if the key is expected to always be present, or hash.fetch(key, nil) if it’s valid/expected for the key to be absent. Why The only benefit of using hash[key] is that it’s six characters shorter to type than…

Ruby

4 min read

Ruby

4 min read

Extreme Programming

About Extreme Programming

Editors

Clay Shentrup

Clay Shentrup

advocate of score voting and approval voting. software engineer.

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech