Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions module1/01_fetch_image/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>Fetch Image</title>
<link rel="stylesheet" href="" />
</head>
<body>
<h1>Fetch a Rainbow</h1>
<img src="" id="rainbow" />
<script>
console.log('about to fetch a rainbow');
fetchRainbow()
.then(console.log)
.catch(console.error);
async function fetchRainbow() {
const response = await fetch('rainbow.jpg');
const blob = await response.blob();
let img = document.getElementById('rainbow');
img.src = URL.createObjectURL(blob);
return 'yay!';
}
</script>
</body>
</html>
Binary file added module1/01_fetch_image/rainbow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions module1/02_fetch_csv/ZonAnn.Ts+dSST.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
Year,Glob,NHem,SHem,24N-90N,24S-24N,90S-24S,64N-90N,44N-64N,24N-44N,EQU-24N,24S-EQU,44S-24S,64S-44S,90S-64S
1880,-.18,-.31,-.06,-.38,-.17,-.01,-.97,-.47,-.25,-.21,-.13,-.04,.05,.67
1881,-.10,-.19,-.01,-.32,.05,-.07,-.91,-.46,-.14,.03,.07,-.06,-.07,.60
1882,-.11,-.21,-.01,-.28,-.07,.02,-1.49,-.27,-.08,-.09,-.05,.02,.04,.63
1883,-.19,-.31,-.06,-.36,-.21,.01,-.35,-.59,-.22,-.24,-.17,-.01,.07,.50
1884,-.29,-.43,-.15,-.56,-.21,-.13,-1.32,-.59,-.40,-.23,-.19,-.19,-.02,.65
1885,-.31,-.40,-.24,-.58,-.15,-.25,-1.18,-.66,-.42,-.09,-.22,-.31,-.15,.82
1886,-.32,-.41,-.24,-.51,-.25,-.22,-1.25,-.49,-.39,-.24,-.26,-.22,-.20,.59
1887,-.35,-.41,-.30,-.46,-.32,-.28,-1.57,-.48,-.25,-.31,-.33,-.28,-.26,.32
1888,-.18,-.23,-.14,-.42,.07,-.29,-1.48,-.44,-.20,.07,.08,-.32,-.23,.16
1889,-.11,-.17,-.06,-.28,.05,-.16,-.86,-.21,-.21,.00,.10,-.16,-.15,.45
1890,-.37,-.42,-.33,-.47,-.42,-.22,-1.29,-.55,-.25,-.34,-.50,-.18,-.27,.15
1891,-.23,-.26,-.21,-.41,-.12,-.21,-1.28,-.29,-.31,-.03,-.21,-.18,-.24,-.15
1892,-.27,-.37,-.16,-.40,-.30,-.08,-1.32,-.59,-.10,-.33,-.28,.02,-.22,.09
1893,-.32,-.45,-.19,-.47,-.39,-.07,-.91,-.51,-.35,-.42,-.36,.03,-.21,-.04
1894,-.31,-.38,-.24,-.32,-.35,-.25,-1.37,-.26,-.11,-.48,-.23,-.16,-.35,-.37
1895,-.23,-.29,-.16,-.38,-.09,-.26,-.96,-.45,-.19,-.14,-.03,-.21,-.32,-.58
1896,-.11,-.20,-.03,-.36,.09,-.15,-1.25,-.35,-.15,.05,.13,-.15,-.13,.26
1897,-.12,-.17,-.07,-.34,.14,-.24,-.79,-.39,-.20,.10,.17,-.21,-.28,.41
1898,-.28,-.29,-.28,-.32,-.27,-.27,-1.25,-.16,-.20,-.24,-.29,-.29,-.21,.38
1899,-.19,-.21,-.16,-.21,-.16,-.20,-1.12,.00,-.13,-.20,-.12,-.18,-.22,.59
1900,-.09,-.09,-.09,-.19,.13,-.31,-.65,-.08,-.13,.07,.19,-.30,-.29,.27
1901,-.16,-.10,-.21,-.12,-.07,-.31,-.59,-.03,-.07,-.06,-.07,-.29,-.34,.26
1902,-.30,-.35,-.25,-.53,-.09,-.36,-1.64,-.42,-.32,-.07,-.12,-.30,-.43,-.04
1903,-.39,-.39,-.39,-.48,-.33,-.39,-.53,-.38,-.52,-.26,-.39,-.37,-.40,-.47
1904,-.49,-.50,-.49,-.51,-.52,-.44,-.31,-.56,-.53,-.48,-.56,-.39,-.49,-1.29
1905,-.29,-.31,-.26,-.39,-.15,-.36,-.20,-.18,-.59,-.17,-.13,-.34,-.37,-.31
1906,-.23,-.23,-.23,-.23,-.22,-.23,-.41,.00,-.34,-.23,-.21,-.21,-.23,-.69
1907,-.40,-.47,-.32,-.57,-.34,-.30,-.76,-.69,-.46,-.31,-.36,-.22,-.37,-1.17
1908,-.43,-.46,-.42,-.47,-.46,-.35,-.45,-.50,-.46,-.43,-.50,-.29,-.48,.70
1909,-.47,-.47,-.48,-.49,-.49,-.44,-.82,-.51,-.40,-.44,-.54,-.38,-.52,-.54
1910,-.43,-.44,-.43,-.39,-.51,-.37,-.72,-.16,-.46,-.51,-.51,-.32,-.45,.19
1911,-.43,-.40,-.47,-.38,-.44,-.47,-.36,-.36,-.41,-.41,-.46,-.43,-.52,.08
1912,-.36,-.45,-.25,-.57,-.19,-.35,-.64,-.71,-.47,-.27,-.12,-.35,-.29,-1.61
1913,-.35,-.43,-.27,-.41,-.32,-.34,-.66,-.25,-.46,-.46,-.18,-.27,-.40,-1.01
1914,-.16,-.19,-.12,-.23,-.08,-.18,-.59,-.07,-.25,-.13,-.04,-.16,-.18,-.34
1915,-.12,-.11,-.13,-.18,-.01,-.21,-.59,-.06,-.15,.01,-.03,-.14,-.23,-1.96
1916,-.33,-.36,-.31,-.29,-.44,-.21,-.32,-.43,-.20,-.46,-.42,-.21,-.17,-1.02
1917,-.44,-.54,-.35,-.41,-.65,-.18,-.65,-.37,-.39,-.72,-.58,-.22,-.09,.09
1918,-.28,-.37,-.20,-.38,-.33,-.13,-1.19,-.16,-.29,-.35,-.30,-.06,-.22,-.25
1919,-.27,-.33,-.20,-.40,-.20,-.22,-.85,-.44,-.27,-.22,-.18,-.15,-.32,.22
1920,-.25,-.25,-.25,-.19,-.26,-.31,.02,-.07,-.31,-.36,-.16,-.18,-.48,-1.12
1921,-.17,-.07,-.28,.06,-.25,-.31,-.03,.27,-.05,-.26,-.24,-.23,-.38,-.81
1922,-.27,-.24,-.30,-.20,-.32,-.27,-.39,-.30,-.09,-.30,-.33,-.25,-.28,-.25
1923,-.24,-.18,-.30,-.10,-.28,-.33,.13,-.03,-.22,-.29,-.27,-.26,-.41,-.52
1924,-.25,-.14,-.35,-.09,-.24,-.42,.28,-.15,-.17,-.22,-.26,-.39,-.46,-.51
1925,-.20,-.10,-.30,.00,-.23,-.37,-.16,.27,-.13,-.25,-.21,-.24,-.54,-.84
1926,-.08,.05,-.20,.06,.04,-.40,.49,.26,-.19,.03,.06,-.35,-.45,-.61
1927,-.20,-.10,-.29,-.10,-.13,-.38,-.04,-.12,-.11,-.09,-.17,-.31,-.45,-1.36
1928,-.19,-.07,-.30,-.04,-.15,-.39,.60,-.07,-.20,-.11,-.18,-.29,-.48,-2.10
1929,-.34,-.30,-.38,-.34,-.27,-.45,.02,-.51,-.34,-.24,-.30,-.42,-.44,-1.05
1930,-.14,.02,-.29,.09,-.09,-.43,.44,.16,-.07,-.07,-.12,-.34,-.47,-2.57
1931,-.10,.05,-.23,.03,.05,-.43,.41,.09,-.12,.08,.01,-.42,-.40,-.39
1932,-.16,-.05,-.27,.05,-.19,-.34,.23,.31,-.17,-.19,-.18,-.21,-.53,-.96
1933,-.30,-.26,-.33,-.24,-.31,-.34,-.43,-.38,-.10,-.29,-.32,-.22,-.49,-1.12
1934,-.14,-.01,-.27,.18,-.28,-.26,.65,.41,-.10,-.28,-.28,-.16,-.38,-.54
1935,-.20,-.09,-.32,-.02,-.21,-.38,.19,.06,-.13,-.18,-.24,-.31,-.42,-1.69
1936,-.16,-.04,-.28,-.03,-.15,-.30,.14,.19,-.22,-.05,-.25,-.27,-.33,-.01
1937,-.04,.12,-.20,.18,-.07,-.22,.97,.10,.01,.03,-.16,-.20,-.25,.39
1938,-.03,.12,-.21,.34,-.26,-.10,1.09,.45,.05,-.19,-.34,-.06,-.11,-.84
1939,-.03,.08,-.15,.23,-.16,-.13,.45,.35,.10,-.13,-.18,-.05,-.19,-1.58
1940,.11,.17,.07,.11,.25,-.07,.86,.06,-.07,.25,.25,.03,-.20,-.03
1941,.18,.24,.15,.02,.47,-.05,-.23,-.04,.12,.55,.40,.03,-.15,-.44
1942,.05,.11,.00,.09,.07,-.01,.25,-.01,.10,.13,.02,.06,-.05,-.87
1943,.07,.15,-.02,.32,-.10,.04,1.08,.29,.13,-.10,-.09,.07,.00,1.16
1944,.21,.27,.15,.37,.19,.07,.94,.51,.12,.13,.26,.19,-.09,-.21
1945,.09,.09,.09,.08,.18,-.02,.36,-.02,.06,.12,.23,.04,.00,-1.85
1946,-.07,.04,-.17,.06,-.05,-.24,-.22,-.01,.19,-.01,-.09,-.22,-.24,.02
1947,-.04,.06,-.14,.12,-.07,-.15,.85,-.12,.05,-.02,-.11,-.19,-.08,.03
1948,-.10,-.01,-.20,.13,-.20,-.21,.07,.34,.02,-.22,-.17,-.19,-.19,-1.01
1949,-.10,-.03,-.18,.11,-.20,-.19,.13,.17,.06,-.23,-.17,-.17,-.14,-1.28
1950,-.18,-.17,-.20,-.09,-.29,-.12,-.01,-.32,.03,-.30,-.29,-.06,-.16,-.72
1951,-.06,.05,-.17,.08,-.06,-.20,-.02,.03,.14,.00,-.13,-.22,-.16,-.18
1952,.01,.06,-.03,.09,.01,-.08,.11,-.07,.19,.00,.03,-.09,-.02,-.38
1953,.07,.23,-.08,.33,.07,-.19,.81,.36,.17,.08,.05,-.08,-.24,-1.34
1954,-.15,-.04,-.25,.02,-.22,-.21,.51,-.21,.01,-.14,-.30,-.17,-.20,-.77
1955,-.14,-.10,-.20,.02,-.33,-.05,-.45,-.08,.23,-.29,-.38,-.16,-.08,1.27
1956,-.20,-.26,-.16,-.25,-.33,.00,-.29,-.47,-.09,-.28,-.37,-.13,.02,.67
1957,.04,.04,.04,.03,.07,.01,.03,.23,-.09,.06,.09,-.09,-.01,.45
1958,.07,.17,-.03,.11,.20,-.15,-.11,.18,.13,.27,.14,-.09,-.08,-.55
1959,.03,.11,-.06,.15,.07,-.16,.42,.17,.04,.07,.08,-.03,-.26,-.37
1960,-.02,.08,-.12,.09,.03,-.20,.32,-.06,.11,.07,-.01,-.10,-.07,-.79
1961,.05,.08,.02,.18,-.03,.04,-.16,.37,.17,-.06,.01,.14,-.18,.14
1962,.04,.15,-.08,.29,-.05,-.10,.64,.33,.15,-.04,-.05,.09,-.07,-.81
1963,.07,.16,-.02,.17,.12,-.10,-.01,.33,.13,.14,.10,-.11,-.17,.08
1964,-.20,-.19,-.20,-.24,-.13,-.24,-.66,-.22,-.11,-.13,-.14,-.30,-.07,-.38
1965,-.10,-.13,-.08,-.16,-.03,-.14,-.18,-.23,-.11,-.07,.01,-.23,-.03,-.08
1966,-.05,.00,-.09,-.12,.08,-.15,-.69,-.16,.07,.17,.00,-.23,-.14,.13
1967,-.02,.03,-.08,.13,-.14,-.01,.46,.26,-.07,-.11,-.17,-.09,-.02,.28
1968,-.08,-.06,-.09,-.09,-.05,-.09,-.22,-.02,-.09,-.01,-.09,-.14,.00,-.11
1969,.07,-.01,.15,-.26,.33,.04,.05,-.59,-.16,.35,.31,.00,.13,.01
1970,.03,-.03,.09,-.10,.07,.12,-.17,-.13,-.06,.07,.06,.10,.03,.36
1971,-.09,-.16,-.03,-.06,-.26,.11,-.07,.00,-.11,-.30,-.22,.02,.16,.33
1972,.01,-.18,.22,-.35,.17,.17,-.40,-.50,-.23,.05,.28,.16,-.02,.60
1973,.16,.10,.22,.12,.18,.17,.21,.26,.01,.06,.29,.22,.07,.28
1974,-.08,-.20,.03,-.17,-.20,.17,-.26,-.10,-.19,-.24,-.17,.22,-.09,.55
1975,-.02,-.06,.02,.12,-.24,.15,.20,.36,-.06,-.31,-.16,.14,.14,.22
1976,-.11,-.21,.00,-.26,-.12,.07,-.05,-.33,-.29,-.14,-.10,.11,.22,-.37
1977,.17,.11,.23,.13,.15,.23,.21,.22,.05,.08,.23,.21,.31,.15
1978,.07,.02,.11,-.03,.08,.14,-.03,.00,-.04,.10,.07,.21,.13,-.11
1979,.16,.08,.24,-.03,.26,.22,-.56,.06,.08,.24,.27,.29,.33,-.24
1980,.27,.16,.38,.07,.29,.45,.35,.01,.01,.31,.28,.35,.37,.96
1981,.33,.39,.27,.51,.18,.35,1.34,.78,.08,.21,.16,.28,.38,.52
1982,.14,.05,.22,-.07,.27,.16,-.30,.07,-.08,.24,.30,.18,.32,-.23
1983,.31,.26,.38,.24,.43,.23,.34,.67,-.06,.29,.58,.21,.41,-.03
1984,.16,.04,.29,.03,.18,.28,.39,.08,-.11,.06,.30,.16,.32,.59
1985,.12,-.01,.25,-.03,.09,.31,.37,-.27,.00,.03,.16,.30,.45,.09
1986,.18,.13,.24,.11,.22,.21,.10,.25,.04,.16,.29,.25,.25,-.05
1987,.34,.27,.41,.08,.58,.26,-.22,.14,.13,.55,.62,.32,.25,.10
1988,.41,.38,.44,.42,.38,.44,.82,.51,.23,.32,.45,.38,.20,1.14
1989,.29,.29,.29,.43,.15,.34,.45,.67,.27,.09,.22,.36,.30,.36
1990,.44,.51,.37,.62,.36,.37,.67,.83,.47,.35,.38,.37,.37,.33
1991,.41,.41,.41,.47,.37,.41,.83,.61,.27,.32,.42,.32,.29,1.01
1992,.22,.12,.32,.08,.29,.28,-.11,.36,-.04,.20,.38,.21,.33,.41
1993,.24,.19,.29,.14,.31,.25,.69,.24,-.10,.27,.35,.27,.39,-.14
1994,.31,.36,.26,.44,.30,.20,.43,.46,.43,.25,.34,.27,.23,-.10
1995,.45,.58,.31,.71,.43,.21,1.41,.96,.33,.40,.46,.29,.15,.06
1996,.34,.28,.39,.27,.32,.43,.88,.20,.12,.30,.33,.34,.29,1.07
1997,.47,.53,.41,.55,.51,.33,.82,.89,.26,.50,.52,.42,.37,-.06
1998,.62,.73,.52,.82,.70,.34,1.04,.93,.67,.60,.79,.39,.31,.20
1999,.40,.50,.30,.73,.21,.32,.51,.83,.75,.15,.27,.47,.19,.05
2000,.40,.50,.30,.71,.24,.30,1.16,.76,.55,.19,.29,.42,.10,.32
2001,.53,.63,.43,.80,.41,.43,1.10,.81,.70,.39,.43,.57,.24,.39
2002,.62,.71,.54,.83,.58,.47,1.39,.97,.57,.54,.63,.47,.32,.81
2003,.61,.73,.49,.82,.61,.38,1.56,.95,.51,.58,.64,.44,.24,.47
2004,.53,.67,.40,.75,.54,.31,.68,.93,.67,.55,.53,.48,.23,-.11
2005,.67,.83,.51,.99,.61,.43,2.00,1.17,.55,.59,.62,.49,.19,.75
2006,.61,.78,.45,.94,.54,.38,1.62,1.05,.66,.54,.55,.51,.20,.32
2007,.64,.81,.46,1.07,.45,.45,1.90,1.30,.67,.42,.47,.49,.07,1.11
2008,.51,.64,.39,.86,.36,.37,1.37,1.02,.60,.31,.41,.53,.09,.42
2009,.63,.69,.57,.73,.67,.48,1.23,.58,.66,.64,.70,.60,.15,.79
2010,.70,.86,.53,.97,.67,.46,1.98,.85,.73,.70,.63,.63,.20,.41
2011,.58,.70,.46,.92,.35,.55,2.09,.89,.56,.37,.34,.65,.18,.97
2012,.61,.76,.47,.96,.50,.41,1.88,.88,.72,.45,.55,.56,.19,.34
2013,.64,.74,.54,.86,.56,.53,1.17,1.02,.67,.56,.55,.63,.23,.79
2014,.73,.89,.56,1.04,.65,.52,1.78,1.12,.75,.67,.62,.71,.18,.58
2015,.86,1.12,.61,1.24,.91,.40,1.66,1.44,.99,.93,.89,.73,.18,-.27
2016,.98,1.26,.71,1.50,.97,.49,3.05,1.41,1.06,.92,1.02,.66,.25,.42
2017,.90,1.11,.68,1.32,.79,.61,2.21,1.35,1.02,.81,.77,.75,.35,.68
2018,.82,.99,.66,1.19,.64,.70,1.87,1.09,1.03,.69,.59,.78,.37,1.07
59 changes: 59 additions & 0 deletions module1/02_fetch_csv/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Coding Train: Data and APIs Project 1</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
</head>
<body>
<h1>Global Average Temperatures 1880-2018</h1>
<canvas id="myChart" width="400" height="200"></canvas>

<script>
// Data from: https://data.giss.nasa.gov/gistemp/
// Mean from: https://earthobservatory.nasa.gov/world-of-change/DecadalTemp

window.addEventListener('load', setup);

function setup() {
var ctx = document.getElementById('myChart').getContext('2d');
getData().then(globalTemps => {
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: globalTemps.years,
datasets: [
{
label: 'Temperature in °C',
data: globalTemps.temps,
fill: false,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.5)',
borderWidth: 1
}
]
},
options: {}
});
});
}

async function getData() {
// const response = await fetch('testdata.csv');
const response = await fetch('ZonAnn.Ts+dSST.csv');
const years = [];
const temps = [];
const data = await response.text();
const rows = data.split('\n').slice(1);
rows.forEach(row => {
const cols = row.split(',');
years.push(cols[0]);
temps.push(14 + parseFloat(cols[1]));
});
return { years, temps };
}
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions module1/02_fetch_csv/testdata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Year,Glob,NHem,SHem,24N-90N,24S-24N,90S-24S,64N-90N,44N-64N,24N-44N,EQU-24N,24S-EQU,44S-24S,64S-44S,90S-64S
1880,-.18,-.31,-.06,-.38,-.17,-.01,-.97,-.47,-.25,-.21,-.13,-.04,.05,.67
1881,-.10,-.19,-.01,-.32,.05,-.07,-.91,-.46,-.14,.03,.07,-.06,-.07,.60
77 changes: 77 additions & 0 deletions module1/03_fetch_json/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Coding Train: Data and APIs Project 1</title>
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""
/>
<script
src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
crossorigin=""
></script>

<style>
#issMap {
height: 480px;
}
</style>
</head>
<body>
<h1>ISS</h1>
<p>
ISS Latitude: <span id="latitude">loading...</span>&deg;.<br />
ISS Longitude: <span id="longitude">loading...</span>&deg;.<br />
</p>
<div id="issMap"></div>
<script>
window.addEventListener('load', setup);

function setup() {
// Image from: https://commons.wikimedia.org/wiki/File:International_Space_Station.svg
const issIcon = L.icon({
iconUrl: 'iss.png'
});

const map = L.map('issMap');
map.setView([0, 0], 1);
const attribution =
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';

const tiles = L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{ attribution }
);
tiles.addTo(map);
const marker = L.marker([0, 0], { icon: issIcon }).addTo(map);

function update() {
getData().then(data => {
const { latitude, longitude } = data;
const lonSpan = document.getElementById('longitude');
const latSpan = document.getElementById('latitude');
lonSpan.textContent = longitude.toFixed(2);
latSpan.textContent = latitude.toFixed(2);
marker.setLatLng([latitude, longitude]);
});
}

async function getData() {
const url = 'https://api.wheretheiss.at/v1/satellites/25544';
const response = await fetch(url);
const json = await response.json();
return json;
}

update();
setInterval(update, 1000);
}
</script>
</body>
</html>
Binary file added module1/03_fetch_json/iss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.