-
Never use float for performing arithmetic calculations relating to money.
Floating numbers can sometimes show funky behaviour. It is not Ruby’s fault but the very implementation of floating numbers raises precision issues.
Examples of odd behaviour:
| import { Controller } from "@hotwired/stimulus" | |
| import SignaturePad from 'signature_pad' | |
| export default class extends Controller { | |
| static targets = ["canvas", "input"] | |
| connect() { | |
| this.signaturePad = new SignaturePad(this.canvasTarget) | |
| this.signaturePad.addEventListener("endStroke", this.endStroke) | |
| this.resizeCanvas() | |
| if (this.inputTarget.value) { |
| # frozen_string_literal: true | |
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'pry' | |
| gem "sqlite3" | |
| gem 'activerecord' | |
| end |
| # Take a Markdown email from the clipboard or a file and turn it into HTML | |
| function mkemail() { | |
| # Either read from clipboard (default) or read from a file | |
| if [[ -z $1 ]]; then | |
| content=`pbpaste` | |
| echo "Reading from clipboard" | |
| else | |
| content=`cat $1` | |
| echo "Reading from file '$1'" | |
| fi |
| This tool is used to compare microbenchmarks across two versions of code. It's | |
| paranoid about nulling out timing error, so the numbers should be meaningful. | |
| It runs the benchmarks many times, scaling the iterations up if the benchmark | |
| is extremely short, and it nulls out its own timing overhead while doing so. It | |
| reports results graphically with a text interface in the terminal. | |
| You first run it with --record, which generates a JSON dotfile with runtimes | |
| for each of your benchmarks. Then you change the code and run again with | |
| --compare, which re-runs and generates comparison plots between your recorded | |
| and current times. In the example output, I did a --record on the master |
| # MODEL | |
| class Case < ActiveRecord::Base | |
| include Eventable | |
| has_many :tasks | |
| concerning :Assignment do | |
| def assign_to(new_owner:, details:) | |
| transaction do |
| class AssignCaseCommand < Command | |
| attribute :case, Case | |
| attribute :owner, User | |
| attribute :created_by, User | |
| attribute :comments, String | |
| attribute :distribute_at, DateTime | |
| attribute :distribute_rule_name, String | |
| attribute :require_initial, Boolean |
| require 'spec/support/grep_matcher' | |
| describe do | |
| disallow_presence_of pattern: "send(.*#", | |
| location: "app/", | |
| description: "Do not use dynamic method invocations", | |
| failure: "Please change dynamic method call to something more sane." | |
| end |
| #!/bin/bash | |
| set -exo pipefail | |
| BUILD_ENV=$1 | |
| if [ `uname` == 'Darwin' ]; then | |
| OSX=1 | |
| JSCOMPRESSOR="yuicompressor --type js" | |
| else | |
| OSX= |