Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
kylekeesling / english_number.rb
Created November 12, 2015 21:08
Output numbers into english words
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 / wedding_number.rb
Last active November 12, 2015 21:10
Outputs numbers as words with proper conjunctions - like you'd see on a wedding invite
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 / birth_date.rb
Created March 17, 2016 21:37
Birthday Calculator
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 / cookie.rb
Created March 18, 2016 00:07
Cookie example from the GDI Ruby Class 2016-03-17
@kylekeesling
kylekeesling / organization.rb
Created April 26, 2018 13:02
Migrating from Paperclip to ActiveStorage
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 / flatpickr_input.rb
Created January 2, 2021 14:48
A Simple Form custom input using stimulus-flatpickr and Bootstrap
# 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 / script.sh
Created November 18, 2024 20:30
server-protection-scripts
# disable SSH sessions using passwords
sudo nano /etc/ssh/sshd_config
```
PasswordAuthentication no
PubkeyAuthentication yes
```
sudo systemctl restart ssh
# Enable Uncomplicated Firewall (ufw) and only allow access via SSH and SSL/TLS
apt-get install ufw