This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let incoming_electric_signal = get_electric_signal(); | |
// The electric signal could represent the temperature of whatever the robot just touched, say. | |
// The higher the temperature, the greater the number returned by `get_electric_signal`. | |
// If some threshold is passed: | |
if (incoming_electric_signal > 1000) { | |
// Detected pain! | |
say('OUCH'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let wanting_treat = true; | |
while (wanting_treat) { | |
move_toward_treat(); | |
if (hear_bathwater()) { | |
wanting_treat = false; | |
back_away(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="col-8 offset-2 d-flex"> | |
<canvas id="canvas" width="500" height="300" style="margin: 0 auto; border: 1px solid #bd6816;"></canvas> | |
</div> | |
<div class="col-12 text-center"> | |
<h4 class="mt-4">Score: <span id="score">0</span></h4> | |
<h5>Post your high score in the comments below!</h5> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_html structure | |
if structure.is_a? Hash | |
structure.reduce([]) do |acc, (key, val)| | |
acc + [[key.to_s, '="', val.to_s, '"'].join] | |
end.join(' ') | |
elsif structure.is_a? Array | |
if structure[1].is_a? Hash | |
tag, attrs, *children = structure.map { |s| to_html s} | |
tag_and_attrs = structure[1].any? ? [tag, ' ', attrs].join : tag | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is gross: use Clojure unless you absolutely have | |
# to use Ruby. | |
# Required dependency: Nokogiri | |
# Use at your own risk. | |
def generate_hiccup parsed_html | |
if parsed_html.is_a?(Nokogiri::HTML::DocumentFragment) | |
parsed_html.children.map { |child| generate_hiccup child } | |
elsif parsed_html.is_a?(Nokogiri::XML::Element) | |
[ | |
parsed_html.name, |