Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Bogard bogardpd

View GitHub Profile
View 99-bottles.graphml
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph edgedefault="directed">
<node id="99"/>
<node id="bottles"/>
<node id="of"/>
View 99-bottles.py
output = ""
bottles = 99
def bottle_str(bottles):
if bottles == 0:
return "No bottles"
elif bottles == 1:
return "1 bottle"
else:
return f"{bottles} bottles"
@bogardpd
bogardpd / routes.rb
Created Sep 30, 2019
/config/routes.rb Routing
View routes.rb
#/config/routes.rb
get "/flights/flights.gpx" => "flights#show_flight_gpx", as: :show_flight_gpx
get "/flights/flights.kml" => "flights#show_flight_kml", as: :show_flight_kml
@bogardpd
bogardpd / flights_controller.rb
Created Sep 30, 2019
/app/flights_controller.rb Controller Actions
View flights_controller.rb
#/app/flights_controller.rb
def show_flight_gpx
flights = flyer.flights(current_user)
render xml: FlightsMap.new(flights).gpx
end
def show_flight_kml
flights = flyer.flights(current_user)
render xml: FlightsMap.new(flights).kml
@bogardpd
bogardpd / map.rb
Created Sep 30, 2019
/app/classes/map.rb Completing the kml method
View map.rb
#/app/classes/map.rb
def kml
@airport_details ||= airport_details
used_airports = @airport_details.keys
output = %Q(<?xml version="1.0" encoding="UTF-8" ?>).html_safe
output += content_tag(:kml, xmlns: "http://www.opengis.net/kml/2.2") do
content_tag(:Document) do
concat content_tag(:name, map_name)
concat content_tag(:description, map_description)
@bogardpd
bogardpd / map.rb
Created Sep 30, 2019
/app/classes/map.rb KML LineStrings (Routes)
View map.rb
#/app/classes/map.rb
def kml_routes(routes, name)
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 content_tag(:Folder) do
concat content_tag(:name, name)
concat safe_join(routes.map{|r| kml_route(r)})
end
end
@bogardpd
bogardpd / map.rb
Created Sep 30, 2019
/app/classes/map.rb KML Points (Airports)
View map.rb
#/app/classes/map.rb
def kml_airports(airports)
airports = airports.sort_by{|a| @airport_details[a][:iata]}
return content_tag(:Folder) do
concat content_tag(:name, "Airports")
concat safe_join(airports.map{|a| kml_airport(a)})
end
end
@bogardpd
bogardpd / map.rb
Created Sep 30, 2019
/app/classes/map.rb KML Metadata and Style
View map.rb
#/app/classes/map.rb
def kml_styles
output = content_tag(:Style, id: "airportMarker") do
content_tag(:Icon) do
content_tag(:href, "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png")
end
end
output += content_tag(:Style, id: "flightPath") do
content_tag(:LineStyle) do
@bogardpd
bogardpd / flights.kml
Created Sep 30, 2019
flights.kml example
View flights.kml
<?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 Sep 30, 2019
/app/classes/map.rb Completing the gpx method
View 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")
You can’t perform that action at this time.