Skip to content

Instantly share code, notes, and snippets.

View bogardpd's full-sized avatar

Paul Bogard bogardpd

View GitHub Profile
<!-- #include file="incfiles/v09_pagedata.asp" -->
<!-- #include file="incfiles/adovbs.inc" -->
<% DisplayHeader "Paul Bogard's Non-Icthyophagous Website", "<b>home</b>" %>
<!-- BEGIN BODY -->
<%
' Banner Ad Randomizer Script
Dim listLen, tN1, tN2, tN3, tN4, tN5
require "net/http"
require "uri"
require "nokogiri"
def to_ascii(input_string)
input_string.gsub!(/\n/, "")
input_string.gsub!(/[”“]/, '"')
input_string.gsub!(/[‘’]/, "'")
input_string.gsub!(/[–—]/, "-")
input_string.encode(Encoding.find('ASCII'), {invalid: :replace, undef: :replace, universal_newline: true})
# app/helpers/application_helper.rb
def render_message(type, text)
render partial: "layouts/message", locals: {type: type, text: text}
end
<!-- app/views/layouts/_message.html.erb -->
<div class="message message-<%= type %>"><%= text.html_safe %></div>
# app/controllers/application_controller.rb
def add_message(type, text)
@messages ||= []
@messages.push({type: type, text: text})
end
# app/helpers/application_helper.rb
def render_messages
order = [:error, :warning, :success, :info]
@messages ||= []
@messages.concat(flash.map{|k,v| {type: k.to_sym, text: v}}) if flash
@messages.sort_by{|m| order.index(m[:type]) || order.length}
.map{|m| render_message(m[:type], m[:text]) }.join.html_safe
end
@bogardpd
bogardpd / application.html.erb
Last active April 23, 2017 04:08
app/views/layouts/application.html.erb
<!-- app/views/layouts/application.html.erb -->
<%= render_messages %>
$color-pax-aus: #FFAE00;
$color-pax-east: #D9272D;
$color-pax-south: #FF7600;
$color-pax-west: #007DBB;
@mixin pax($color-base) {
a {
background: $color-base;
background: linear-gradient($color-base, darken($color-base, 5%));
border: 1px solid lighten($color-base, 10%);
@bogardpd
bogardpd / airport.rb
Created September 8, 2017 01:48
Find all airports in a given set of regions
# app/models/airport.rb
...
# Take a collection of strings representing the starts of ICAO codes, and
# return an a hash of airports in the region, with airport ids as keys and
# IATA codes as values.
# Params:
# +icao_starts+:: An array of strings of the start of ICAO codes (i.e. EG, K)
def self.in_region_hash(icao_starts)
state_codes = %w(AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY)
state_codes.sort!
one_letter_changes = Hash.new()
state_codes.each do |sc|
one_letter_changes[sc] = state_codes.select{|s| sc != s && (sc[0] == s[0] || sc[1] == s[1])}
puts "#{sc}: #{one_letter_changes[sc].join(", ")}"
end