Skip to content

Instantly share code, notes, and snippets.

View dchacke's full-sized avatar
😃
Learning Unity

Dennis Hackethal dchacke

😃
Learning Unity
View GitHub Profile
@dchacke
dchacke / robot_pain_response.js
Last active September 24, 2021 03:40
How could a robot respond to pain without being conscious?
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');
}
@dchacke
dchacke / dog.js
Created September 24, 2021 02:50
How can a dog change his mind about treats when he hears bath water without being conscious?
let wanting_treat = true;
while (wanting_treat) {
move_toward_treat();
if (hear_bathwater()) {
wanting_treat = false;
back_away();
}
}
<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>
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
@dchacke
dchacke / html_to_hiccup.rb
Created November 13, 2020 06:31
Turning an HTML string into hiccup in Ruby
# 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,