Skip to content

Instantly share code, notes, and snippets.

Avatar
💎

Kyle Keesling kylekeesling

💎
View GitHub Profile
@kylekeesling
kylekeesling / flatpickr_input.rb
Created Jan 2, 2021
A Simple Form custom input using stimulus-flatpickr and Bootstrap
View flatpickr_input.rb
# frozen_string_literal: true
class FlatpickrInput < SimpleForm::Inputs::StringInput
def input(wrapper_options)
template.content_tag(:div, class: "input-group",
data: {controller: "flatpickr", flatpickr_disable_mobile: true}) do
template.concat input_addon(calendar_button, data: {toggle: true})
template.concat @builder.text_field(attribute_name, input_html_options)
template.concat input_addon(close_button, data: {clear: true})
end
@kylekeesling
kylekeesling / organization.rb
Created Apr 26, 2018
Migrating from Paperclip to ActiveStorage
View organization.rb
class Organization < ApplicationRecord
has_one_attached :logo
# Old Paperclip config
# must be removed BEFORE to running the rake task
has_attached_file :logo,
path: "/companies/:id/:basename_:style.:extension",
default_url: "https://xxxxx.cloudfront.net/companies/missing_:style.jpg",
default_style: :normal,
styles: { thumb: "64x64#", normal: "400x400>" },
@kylekeesling
kylekeesling / cookie.rb
Created Mar 18, 2016
Cookie example from the GDI Ruby Class 2016-03-17
View cookie.rb
@kylekeesling
kylekeesling / birth_date.rb
Created Mar 17, 2016
Birthday Calculator
View birth_date.rb
puts "What year where you born? (Enter a 4 digit year, ie 1984)"
birth_year = gets.chomp
puts "What month where you born? (Enter the month number, ie June would be 6)"
birth_month = gets.chomp
puts "What day of the month where you born?"
birth_day = gets.chomp
@kylekeesling
kylekeesling / wedding_number.rb
Last active Nov 12, 2015
Outputs numbers as words with proper conjunctions - like you'd see on a wedding invite
View wedding_number.rb
def weddingNumber number
if number < 0 # No negative numbers.
return 'Please enter a number that isn\'t negative.'
end
if number == 0
return 'zero'
end
# No more special cases! No more returns!
@kylekeesling
kylekeesling / english_number.rb
Created Nov 12, 2015
Output numbers into english words
View english_number.rb
def englishNumber number
if number < 0 # No negative numbers.
return 'Please enter a number that isn\'t negative.'
end
if number == 0
return 'zero'
end
# No more special cases! No more returns!
@kylekeesling
kylekeesling / fancy_99_bottles.rb
Last active Nov 12, 2015
Output the 99 bottles of beer song with numbers in words rather than integers
View fancy_99_bottles.rb
require_relative 'english_number.rb' #https://gist.github.com/kylekeesling/4b73a984421f120312de
num_bottles = 999
while num_bottles > 0
puts "#{englishNumber(num_bottles)} bottles of beer on the wall,
#{englishNumber(num_bottles)} bottles of beer, take one down, pass it
around, #{englishNumber(num_bottles - 1)} bottles of beer on the wall!"
num_bottles = num_bottles - 1
end
@kylekeesling
kylekeesling / 99_bottles.rb
Created Nov 10, 2015
99 Bottles of Beer...
View 99_bottles.rb
num_bottles = 99
while num_bottles > 0
puts "#{num_bottles} bottles of beer on the wall,
#{num_bottles} bottles of beer, take one down, pass it
around, #{num_bottles - 1} bottles of beer on the wall!"
num_bottles = num_bottles - 1
end
@kylekeesling
kylekeesling / leap.rb
Created Nov 10, 2015
Leap Year Calculator
View leap.rb
puts "Enter a starting year in the format YYYY"
starting = gets.chomp!.to_i
puts "Enter an ending year in the format YYYY"
ending = gets.chomp!.to_i
puts "LEAP YEARS between #{starting} and #{ending}"
starting.upto(ending) do |year|
divisible_by_4 = (year % 4) == 0
not_divisible_by_100 = (year % 100) != 0
divisible_by_400 = (year % 400) == 0
View grandma.rb
chatting = true
byes = 0
while chatting
puts "Ask Grandma a question:"
said = gets.chomp!
if said == "BYE"
byes += 1
if byes > 2
chatting = false
else