This file contains hidden or 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 shuffle(self): | |
for _ in range(self.level * self.level): | |
if random.random() > 0.5: | |
self.flipcol(random.randint(0, self.level - 1)) | |
else: | |
self.fliprow(random.randint(0, self.level - 1)) |
This file contains hidden or 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
# method to flip a column | |
def flipcol(self, r): | |
for i in range(len(self.board[r])): | |
self.board[r][i] ^= 1 # 0 -> 1, 1 -> 0 | |
# method to flip a row | |
def fliprow(self, c): | |
for row in self.board: | |
row[c] ^= 1 |
This file contains hidden or 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
from pip._vendor import requests | |
from bs4 import BeautifulSoup | |
from urllib.parse import urlparse | |
import urllib | |
import xml.etree.ElementTree as ET | |
class SitemapGenerator: | |
def __init__(self, root, filename): |
This file contains hidden or 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 generatefile(self): | |
urlsbylevel = {} | |
maxlevel = 0 | |
for key, value in self.urls.items(): | |
if value > maxlevel : | |
maxlevel = value | |
listurls = None |
This file contains hidden or 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 crawl(self, url, level): | |
print("Level: " + str(level) + "/ Explore " + url) | |
page = requests.get(url) | |
if page.status_code == 200 : | |
url = urllib.parse.urldefrag(url)[0] # we don't add url with fragments | |
if url not in self.urls : | |
self.urls[url] = level |
This file contains hidden or 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
<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 = ""; |
This file contains hidden or 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
function sayBitcoinPrice() { | |
if (textToSpeech) { | |
const utterance = new SpeechSynthesisUtterance(textToSpeech); | |
utterance.lang = 'en-US'; | |
speechSynthesis.speak(utterance); | |
} | |
} |
This file contains hidden or 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
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) |
This file contains hidden or 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
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; | |
This file contains hidden or 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
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); | |
} | |
}; |