Skip to content

Instantly share code, notes, and snippets.

View brandondrew's full-sized avatar

Brandon Zylstra brandondrew

  • UC Berkeley
  • the tubes
View GitHub Profile
@brandondrew
brandondrew / float_approximation.rb
Created June 15, 2024 23:08
Safely compare floats
## you presumably already know that this returns false, because of the way floats are stored:
0.1 + 0.2 == 0.3
# => false
# we can create a more useful way of comparing floats that matches what humans would expect:
class Float
def =~(number, tolerance = 0.0001)
(self - number).abs < tolerance
end
@brandondrew
brandondrew / ruby-the-future-of-frozen-string-literals.md
Last active May 24, 2024 17:39 — forked from fxn/ruby-the-future-of-frozen-string-literals.md
Xavier's helpful post, with grammar fixes (in progress).

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@brandondrew
brandondrew / button_progress_controller.js
Created February 22, 2024 03:20 — forked from dbreunig/button_progress_controller.js
Poor man's form button progress indicator, in Stimulus, for those long processing requests.
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
addEventListener("turbo:submit-end", ({ target }) => {
clearInterval(this.interval);
this.element.innerHTML = this.originalLabel;
})
this.originalLabel = this.element.innerHTML;
}
@brandondrew
brandondrew / upgrading_ruby_for_rails
Last active January 3, 2023 04:46
How To Upgrade Ruby for your Rails App, Locally & on a Server with Passenger
Overview
--------
Consider the commands given to be examples, not to necessarily be precisely
what you will use. They were based on my circumstances, in which
* my local platform is macOS,
* where Homebrew is the de facto package manager;
* my laptop (and the server) are managing Ruby with rbenv;
* vim is my remote editor of choice, and an acceptable local editor; and
Goals
Editable by Supervisor
Employee Data Safe
Supervisor Edits Goals -> Editable by Supervisor
Supervisor Assigns Rights to Employee -> Editable by Employee
Employee Data Lost
No Simple Solution -> Employee Data Lost
Editable by Employee
Employee Data Still Safe
Employee Begins Editing Goals -> Employee Data at Risk
# https://wikihub.berkeley.edu/display/robots/CC+-+20181213+More+Changes+to+Pilot+Specs
Proposed Performance Pilot Workflow - Newest
No Review Exists*
Create New Form -> Supervisor Starts Form
Review In Process
Supervisor Starts Form
Save -> Draft
Save & Share with Employee -> Participants Comment and Sign
New*
Draft
@brandondrew
brandondrew / SketchSystems.spec
Created October 4, 2018 02:57
Proposed Performance Pilot Workflow - Steps
Proposed Performance Pilot Workflow - Steps
No Review Exists*
Create New Form -> Supervisor Starts Conversation
Review In Process
Supervisor Starts Conversation
Save as Draft -> Supervisor Starts Conversation
Share with Employee -> Participants Comment
Participants Comment
Employee Comments -> Participants Comment
Supervisor Edits and Comments -> Participants Comment
@brandondrew
brandondrew / SketchSystems.spec
Last active October 4, 2018 02:53
Proposed Performance Pilot Workflow - States
Proposed Performance Pilot Workflow - States
No Review Exists*
Create New Form -> New
Review In Process
Save as Draft -> Draft
Share with Employee -> Awaiting Comments
Delete -> No Review Exists
New
Draft
Awaiting Comments
@brandondrew
brandondrew / SketchSystems.spec
Last active October 4, 2018 02:54
Proposed Performance Pilot Workflow - Complete
Proposed Performance Pilot Workflow - Complete
No Review Exists*
Create New Form -> Supervisor Starts Conversation
Review In Process
Supervisor Starts Conversation
Save as Draft -> Draft
Share with Employee -> Participants Comment
New*
Draft
Participants Comment
@brandondrew
brandondrew / SketchSystems.spec
Last active October 3, 2018 17:04
Current Performance Pilot Workflow x
Current Performance Pilot Workflow x
Supervisor Starts Form
Share with Employee -> Supervisor & Employee Comment
Supervisor & Employee Comment
Supervisor Signs
Employee Signs