Skip to content

Instantly share code, notes, and snippets.

View stratigos's full-sized avatar
🧑‍🔬
Building the Internet

Todd stratigos

🧑‍🔬
Building the Internet
View GitHub Profile
@stratigos
stratigos / .rspec
Created January 9, 2017 21:39
RSpec Configuration
--color
--require spec_helper
@stratigos
stratigos / ruby_memory_profile_example.rb
Last active January 9, 2017 21:40
Example Tool for Profiling Memory Use in Ruby Scripts and Applications
#################################
# GEMFILE: gem 'get_process_mem'
#################################
require 'get_process_mem'
def profile_mem(description=nil)
mb = GetProcessMem.new.mb
puts "\n\n---- #{ description } - MEMORY USAGE(MB): #{ mb.round } ----\n\n"
end
@stratigos
stratigos / rspec_shared_example_with_shoulda_matchers_for_booleans.rb
Created April 19, 2018 16:46
RSpec Boolean Matcher Shared Example with Shoulda Matchers
# Shared specs for models with the `:validates_inclusion_of` validators, where
# Boolean values are specified. This is for use cases where Booleans are used
# in non-null DB columns, and validation errors need to be returned to actors
# attempting to store a NULL value (e.g., a IoT unit's firmware uploading a
# NULL value for an On/Off sensor reading).
# Additionally, `shoulda` will complain if `validate_inclusion_of` is used
# with the Booleans, and instead of turning off warnings, its best to just
# approach these specs differently. See
# [this github comment](https://github.com/thoughtbot/shoulda-matchers/issues/922#issuecomment-225752673)
# for more info.
@stratigos
stratigos / rspec_validates_numericality_with_shoulda_matchers.rb
Created April 19, 2018 16:54
RSpec Validates Numericality of Active Record Model with Shoulda Matchers
# Shared specs for models with the `:validates_numericality_of` validators.
# Usage: pass a hash of each of the symbolized names of each options for the
# numericality validator. If the option has a value with which to evaluate
# against, add it as the value of that option hash name.
# E.g.:
# `it_behaves_like :validates_numericality_model, :numeric_attr, { greater_than_or_equal_to: 0, only_integer: true }`
RSpec.shared_examples :validates_numericality_model do |attribute_name, options|
it { is_expected.to validate_numericality_of(attribute_name) }
@stratigos
stratigos / rspec_shared_example_defined_constants.rb
Created April 19, 2018 16:56
RSpec Shared Example Matcher for Class Constant Definition
# Shared specs for models with frozen CONST values. Expects two String values
# as parameters.
RSpec.shared_examples :has_const_model do |const_name, const_value|
it { expect(described_class).to be_const_defined(const_name.to_sym) }
it { expect("#{described_class}::#{const_name}".constantize).to be_frozen }
it { expect("#{described_class}::#{const_name}".constantize).to eq(const_value) }
end
@stratigos
stratigos / respec_helper_bearer_token_session_headers.rb
Last active April 19, 2018 17:19
RSpec Helper for Validating Token-based Auth Headers Returned with Request
module RequestSpecHelper::SessionsHelper
# Set single expectation that checks auth headers were returned.
def expect_auth_headers(response)
expect(response.headers.keys).to include('access-token', 'client', 'expiry', 'uid')
end
end
########################################################################
@stratigos
stratigos / number_weekdays_in_year_to_today.rb
Created July 8, 2016 15:53
Ruby: get the number of weekdays in the last year up to today.
( (1.year.ago.to_date)..(Date.today) ).select{ |d| (1..5).include? d.wday }.size.to_f
@stratigos
stratigos / clear_swap.sh
Created November 11, 2018 22:34
Clear Swap Space on Ubuntu Linux (14.04)
function clearswap { sudo swapoff -a && sudo swapon -a; }
@stratigos
stratigos / 2019-04-19_functional-structures-scala.md
Last active July 12, 2019 23:29
Notes on "FSiS Part 1 - Type Constructors, Functors, and Kind Projector"

Functional Structures in Scala

  • 📆 2019-04-19
  • this spans many weeks / investment times
  • 📹 Screencast: Functional Structures
  • 👨‍💻📝️ an experienced OOP programmer learning FP and Scala
    • and maybe category theory? 🤔

On Kindedness

@stratigos
stratigos / 2019-07-19_elm-language-guide.md
Last active September 14, 2019 00:37
Elm Lang Guide

Elm Language Guide

  • 📆 2019-07-19
  • this spans many weeks / investment times
  • 📖 🌳️🕵‍♀️️ The Elm Language Guide
  • 👨‍💻📝️ an experienced OOP programmer learning FP and Elm

Installing Elm

Compared to my experiences using JavaScript over many years, I found installing