Skip to content

Instantly share code, notes, and snippets.

@oldgitdaddy
oldgitdaddy / gist:a65eacd0205b1f9ef1f20548da71fdcf
Last active May 22, 2021 10:00
Sensor informing you if there is a DWD warning NOW!
{% set dwd_warning = namespace(found=false)%}
{% if state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_count') > 0 %}
{% for i in range(1, state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_count')+1) %}
{% set start = as_timestamp(state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_'~i~'_start'))%}
{% set end = as_timestamp(state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_'~i~'_end'))%}
{% if start < as_timestamp(now()) < as_timestamp(now()) < end %}
{% set dwd_warning.found = true %}
{%endif%}
{%endfor%}
{%endif%}
function proof_of_work(difficulty, prev_hash, timestamp, merkle_root) {
var hash = “1111111111111111111111111111111111111111111111111111111111111111”;
var nonce = 0;
//check if hash meets difficulty criteria (by counting number of zeros)
while (hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
//incrementing the nonce value every time the loop runs.
nonce++;
//recalculating the hash value
hash = this.calculateHash(nonce, prev_hash, timestamp, merkle_root);
}