Skip to content

Instantly share code, notes, and snippets.

Shannon Skipper havenwood

Block or report user

Report or block havenwood

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
@havenwood
havenwood / ascii_art_png.rb
Created Jul 4, 2019
A quick spike to turn ascii art into a png
View ascii_art_png.rb
# frozen_string_literal: true
require 'chunky_png'
ascii = <<~ASCII
@@@@@@ @@@@@@
@@@@@@@@@@ @@@@@@@@@@
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@havenwood
havenwood / base58.rb
Created Jun 28, 2019
Example Base58 Implementation (showing haxx0r> on #ruby irc)
View base58.rb
module Base58
CHARACTERS = [*?1..?9, *?a..?k, *?m..?z, *?A..?H, *?J..?N, *?P..?Z].freeze
module_function
def encode(n)
chars = []
while n >= 58
chars.unshift BASE58_CHARACTERS[n % 58]
@havenwood
havenwood / install.sh
Created Jun 21, 2019
Debian 9 Installation Instructions for system wide Ruby 2.6.3 in /usr/local
View install.sh
sudo apt-get update
sudo apt-get install -y bison build-essential libffi-dev libgdbm-dev libreadline-dev libssl-dev libyaml-dev zlib1g-dev
cd /usr/local/src
wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.bz2
tar -xjvf ruby-2.6.3.tar.bz2
cd ruby-2.6.3
./configure --prefix="/usr/local"
make -j"$(getconf _NPROCESSORS_ONLN)"
sudo make install
@havenwood
havenwood / config.ru
Last active Jun 29, 2019
Run ./config.ru then browse to localhost:3000.
View config.ru
#!/usr/bin/env -S falcon serve --bind http://localhost:3000 --count 1 --config
# frozen_string_literal: true
require 'roda'
class App < Roda
BODY = <<~HTML
<!DOCTYPE html>
<html lang="en">
<head>
@havenwood
havenwood / user.rb
Created Jun 11, 2019
suggestion for GeorgesLeYeti on #rubyonrails irc
View user.rb
class User < ApplicationRecord
validates :email, uniqueness: true, unless: :gmail?
validates :email, :unique_gmail, if: :gmail?
def unique_gmail
username, symbol, domain = email.partition '@'
email_without_periods = "#{username.delete('.')}#{symbol}#{domain}"
duplicate = self.class.find_by email: email_without_periods
errors.add :email, "#{duplicate} has already been taken" if duplicate
end
@havenwood
havenwood / censor.rb
Last active Jun 7, 2019
A solution to comet23's problem from #ruby irc
View censor.rb
def censor(sentence, words, redact: 'aeiou', filler: '*')
sentence.gsub /#{Regexp.union(words).source}/i do |word|
word.tr redact, filler
end
end
censor 'Gosh darned it', %w[gosh darn shoot]
#=> "G*sh d*rned it"
@havenwood
havenwood / time_of_day.rb
Created May 31, 2019
A TimeOfDay class for leftylink on IRC
View time_of_day.rb
# frozen_string_literal: true
class TimeOfDay
include Comparable
SEPARATOR = ':'
HOURS_MATCH = /\A\d+/.freeze
MINUTES_MATCH = /(?<=#{SEPARATOR})\d+/o.freeze
attr_reader :hour
View application_helper.rb
module ApplicationHelper
def bell_notification_with_conditional_counter
keyword_arguments = {class: 'notification-bell'}
keyword_arguments[:data] = {count: '...'} if Notification.unread_count(current_user).nonzero?
icon("fas", "bell", **keyword_arguments)
end
end
View x.rb
class Hangman
DICTIONARY = ["cat", "dog", "bootcamp", "pizza"]
def initialize()
@secret_word = Hangman.random_word
@guess_word = Array.new(@guess_word.length, "-")
@attempted_chars = Array.new
@remaining_incorrect_guesses = 5
end
@havenwood
havenwood / foo.rb
Created Mar 9, 2019
example for #ruby irc
View foo.rb
class Foo
end
def Foo
yield
end
Foo { puts 'hi' }
You can’t perform that action at this time.