Skip to content

Instantly share code, notes, and snippets.

@DavidColby
DavidColby / slider.html
Created May 6, 2021
Implementation of a horizontal slider component with Stimulus and Tailwind CSS
View slider.html
<!--
This code is meant to accompany the guide originally published at https://colby.so/posts/building-a-horizontal-slider-with-stimulus-and-tailwind
It intentionally pulls in Tailwind CSS and Stimulus without a build system to simplify the guide. You shouldn't do this with a real application,
you should use a build system like webpack!
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
@DavidColby
DavidColby / Gemfile
Created May 14, 2014
Testing basic Sinatra app with rspec and capybara
View Gemfile
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rspec', '~> 2.14.0'
gem 'capybara'
gem 'pry-debugger', '~> 0.2.2'
gem 'sinatra'
gem 'sinatra-contrib' # Not required
gem 'thin' # Not required
gem 'rack-test'
@DavidColby
DavidColby / triples.rb
Last active Aug 29, 2015
Method for finding pythagorean triples in a given range. Returns the triple with the largest sum that is less than the given perimeter
View triples.rb
def find_biggest_triple(perimeter)
all_triples = [] # Empty array to hold all of the triplets
max_side_length = perimeter/2 # This isn't necessary because we filter but the method runs a lot faster if we cut down how many times the all_triples loops need to run. a + b should always be greater than c so no need to build triples that won't be selected
# Run outer loop perimeter/2 times - This is our hypotenuse
max_side_length.times do |a|
a.times do |b|
b.times do |c|
# Pythagorean triplet is found if the square of the two shorter sides (the two interior loops) equals the square of the hypotenuse
if c**2 + b**2 == a**2