Skip to content

Instantly share code, notes, and snippets.

View bogardpd's full-sized avatar

Paul Bogard bogardpd

View GitHub Profile
@bogardpd
bogardpd / flights.kml
Created September 30, 2019 01:04
flights.kml example
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Flights</name>
<description>Map of flight routes, created by Paul Bogard’s Flight Historian</description>
<Style id="airportMarker">
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>
</Icon>
</Style>
@bogardpd
bogardpd / map.rb
Created September 30, 2019 01:03
/app/classes/map.rb Completing the gpx method
#/app/classes/map.rb
def gpx
output = %Q(<?xml version="1.0" encoding="UTF-8" ?>).html_safe
output += content_tag(:gpx, xmlns: "http://www.topografix.com/GPX/1/1", version: "1.1") do
concat (content_tag(:metadata) do
concat content_tag(:name, map_name)
concat content_tag(:desc, map_description)
concat (content_tag(:author) do
concat content_tag(:name, "Paul Bogard’s Flight Historian")
@bogardpd
bogardpd / map.rb
Created September 30, 2019 01:02
/app/classes/map.rb Routes
#/app/classes/map.rb
def gpx_routes(routes)
return nil unless routes.any?
routes = routes.map{|r| r.sort_by{|x| @airport_details[x][:iata]}}.uniq.sort_by{|y| [@airport_details[y[0]][:iata], @airport_details[y[1]][:iata]]}
return safe_join(routes.map{|r| gpx_route(r)})
end
def gpx_route(airport_pair)
detail = airport_pair.map{|a| @airport_details[a]}
@bogardpd
bogardpd / map.rb
Created September 30, 2019 01:01
/app/classes/map.rb Waypoints (Airports)
#/app/classes/map.rb
def gpx_airports(airports)
airports = airports.sort_by{|a| @airport_details[a][:iata]}
return safe_join(airports.map{|a| gpx_airport(a, :wpt)})
end
def gpx_airport(airport_id, wpt_type)
detail = @airport_details[airport_id]
return content_tag(wpt_type, lat: detail[:latitude], lon: detail[:longitude]) do
@bogardpd
bogardpd / map.rb
Created September 30, 2019 00:58
/app/classes/map.rb
#/app/classes/map.rb
def gpx
output = %Q(<?xml version="1.0" encoding="UTF-8" ?>).html_safe
output += content_tag(:gpx, xmlns: "http://www.topografix.com/GPX/1/1", version: "1.1") do
concat (content_tag(:metadata) do
concat content_tag(:name, map_name)
concat content_tag(:desc, map_description)
concat (content_tag(:author) do
concat content_tag(:name, "Paul Bogard’s Flight Historian")
@bogardpd
bogardpd / map.rb
Created September 30, 2019 00:57
/app/classes/map.rb
#/app/classes/map.rb
class Map
include ActionView::Helpers
include ActionView::Context
<?xml version="1.0" encoding="UTF-8" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1">
<metadata>
<name>Flights</name>
<desc>Map of flight routes, created by Paul Bogard’s Flight Historian</desc>
<author>
<name>Paul Bogard’s Flight Historian</name>
<link href="https://www.flighthistorian.com">
<text>Paul Bogard’s Flight Historian</text>
@bogardpd
bogardpd / Switch MAC Address.command
Last active July 28, 2018 03:56
Script to toggle between Switch and laptop MAC for logging into hotel wifi (xx:xx:xx:xx:xx:xx is the Switch's MAC address, and yy:yy:yy:yy:yy:yy is the laptop's MAC address)
sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx
networksetup -setairportpower en0 off
networksetup -setairportpower en0 on
echo
echo -e "Now using $(tput bold)$(tput setaf 6)Nintendo $(tput setaf 1)Switch$(tput sgr0) MAC address (xx:xx:xx:xx:xx:xx)"
read -p "Press ENTER to change back to native MAC address"
sudo ifconfig en0 ether yy:yy:yy:yy:yy:yy
networksetup -setairportpower en0 off
networksetup -setairportpower en0 on
echo
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])}
end
def path_distance(graph, source)
vertexes = graph.keys
return nil unless vertexes.include?(source)
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