Skip to content

Instantly share code, notes, and snippets.

Avatar

Sylvain Saurel ssaurel

View GitHub Profile
View bitcoinpriceinwords.html
<html>
<head>
<title>Bitcoin Price in Words - Sylvain Saurel</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Sriracha&display=swap" rel="stylesheet">
<script type="text/javascript">
var textToSpeech = "";
@ssaurel
ssaurel / sayBitcoinPrice.js
Created Mar 26, 2021
sayBitcoinPrice for Bitcoin Price in Words
View sayBitcoinPrice.js
function sayBitcoinPrice() {
if (textToSpeech) {
const utterance = new SpeechSynthesisUtterance(textToSpeech);
utterance.lang = 'en-US';
speechSynthesis.speak(utterance);
}
}
@ssaurel
ssaurel / numberToWords.js
Created Mar 26, 2021
Number to Words for Bitcoin Price in Words
View numberToWords.js
var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
function numberToWords (num) {
if ((num = num.toString()).length > 9)
return 'MOON';
n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
if (!n)
@ssaurel
ssaurel / parseJson.js
Created Mar 26, 2021
Parse JSON for Bitcoin Price in Words
View parseJson.js
function parseJson(json) {
var time = "on " + json["time"]["updated"];
var usdValue = json["bpi"]["USD"]["rate"];
var gbpValue = json["bpi"]["GBP"]["rate"]; // ToDo later
var euroValue = json["bpi"]["EUR"]["rate"]; // ToDo later
var usdValueInWords = (numberToWords(usdValue.split(".")[0].replace(",","")) + " dollars").toUpperCase();
document.getElementById("content").innerHTML = usdValueInWords;
@ssaurel
ssaurel / bpi_call.js
Created Mar 26, 2021
BPI Call For Bitcoin Price in Words
View bpi_call.js
function bitcoinPrice() {
var xmlhttp = new XMLHttpRequest();
var url = "https://api.coindesk.com/v1/bpi/currentprice.json";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var json = JSON.parse(this.responseText);
parseJson(json);
}
};
@ssaurel
ssaurel / index.html
Created Mar 26, 2021
Bitcoin Price In Words HTML5 Page
View index.html
<html>
<head>
<title>Bitcoin Price in Words - Sylvain Saurel</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Sriracha&display=swap" rel="stylesheet">
<style>
#top {
@ssaurel
ssaurel / hexadecimalcolorclock.html
Created Jan 5, 2020
Hexadecimal Color Clock on the SSaurel's Blog
View hexadecimalcolorclock.html
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed&display=swap" rel="stylesheet">
<style>
#hexatime {
width: 300px;
text-align: center;
margin: 0 auto;
margin-top: 500px;
@ssaurel
ssaurel / hexislight.js
Created Jan 5, 2020
hexislight function for the Hexadecimal Color Clock on the SSaurel's Blog
View hexislight.js
function hexislight(color) {
var hex = color.replace('#', '');
var red = parseInt(hex.substr(0, 2), 16);
var green = parseInt(hex.substr(2, 2), 16);
var blue = parseInt(hex.substr(4, 2), 16);
// it is a known formula, nothing magical here
var brightness = ((red * 299) + (green * 587) + (blue * 114)) / 1000;
return brightness > 155;
}
@ssaurel
ssaurel / hexaTime.js
Created Jan 5, 2020
hexaTime function for Hexadecimal Color Clock on the SSaurel's Blog
View hexaTime.js
function hexaTime() {
var date = new Date();
// we convert in the 0 .. 255 range
var seconds = parseInt(date.getSeconds() * 255 / 59);
var minutes = parseInt(date.getMinutes() * 255 / 59);
var hours = parseInt(date.getHours() * 255 / 23);
return "#" + toHex(hours) + toHex(minutes) + toHex(seconds);
}
@ssaurel
ssaurel / ToHex.js
Created Jan 5, 2020
toHex function for Hexadecimal Color Clock on the SSaurel's Blog
View ToHex.js
function toHex(d) {
var hex = ("0" + (Number(d).toString(16))).slice(-2).toUpperCase();
return hex;
}