Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / cookie.rb
Created March 18, 2016 00:07
Cookie example from the GDI Ruby Class 2016-03-17
@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 / 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 / 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 / fancy_99_bottles.rb
Last active November 12, 2015 21:08
Output the 99 bottles of beer song with numbers in words rather than integers
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 November 10, 2015 20:06
99 Bottles of Beer...
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 November 10, 2015 19:59
Leap Year Calculator
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