Skip to content

Instantly share code, notes, and snippets.

Josh Thompson josh-works

Block or report user

Report or block josh-works

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@josh-works
josh-works / exceptional_values.rb
Last active Oct 13, 2018
test, and the code that makes the test pass, to understand whole values and exceptional values, from Avdi Grim's https://avdi.codes/courses/moom/
View exceptional_values.rb
class Object
def exceptional?
false
end
end
Course = Struct.new(:name, :duration) do
def duration=(new_duration)
self[:duration] = Duration(new_duration)
end
@josh-works
josh-works / benchmark_double_inject.md
Last active Apr 13, 2018
ruby, benchmarking, double_inject
View benchmark_double_inject.md

Double inject. What does it mean?

i want to know how long it takes to do some stuff. I've got some code like this:

def count_stuff(list)
  list.inject([]) do |results, item|
    results << get_results_from_something_else(values)
  end.flatten.uniq
View url_validator.md

I needed a URL validator - it needed to check that URL's had HTTP or HTTPS at the beginning. I initially wrote a "before save" action, but didn't like it cluttering up my model. I found a reference to basically "monkey patching" Rail's default Validator class, so that's what I did!

# concerns/url_validator.rb
require 'uri'

class UrlValidator < ActiveModel::Validator

  def validate(record)
    if record.url?
View on_learning.md

On Learning

topics: {
      DEEP WORK:
        protect and cultivate (limited) attention,
        ear plugs,
        skeptical of music,
        examine your own process,
        downtime,
View better_questions.md

Better workflow (leads to) better questions (leads to) better jobs

We'll cover two things:

  1. Have a great workflow
  2. Ask great questions

Workflow

From Regis, who will cover the "workflow" portion of the spike

View on_cleaner_controllers.md

On cleaner controllers

A few days ago, I worked on a project that was mostly about serving up basic store data (modeled after Etsy) to an API.

We had a few dozen end-points, and all responses were in JSON.

Most of the action happened inside of our controllers, and as you might imagine, our routes.rb file was bananas.

One of the instructors made an exceptionally simple suggestion, I was embarrassed to not have seen it.

View psqlrc_config.md

in .psqlrc, I've got:

\set PROMPT1 '\n%[%033[1;31;40m%] ➤ %[%033[32m%]psql%033[36m%]%/ %[%033[K%]%[%033[0m%]\n\n%[%033[1;33m%]%#%[%033[0m%] '
\set PROMPT2 '%[%033[1;33m%]%##%[%033[0m%] '
\timing
\set HISTSIZE 2000


\set alldata 'SELECT * FROM '
View zsh_setup.md
View learning_how_to_learn.md

Learning is cool.

Learning how to learn is a super power.

Lets look at the lense of learning a new language:

At the most tactical level, we would be studying the language itself. Reading a children's book in the target language, or making and studying flashcards.

At a higher level, we would be considering how we can best study the language. Flash cards? Reading children's books in the foreign language? Passive or active learning? etc.

View tour_of_d3_for_clueless_folks_like_me.md
You can’t perform that action at this time.