Skip to content

Instantly share code, notes, and snippets.

View rdegges's full-sized avatar

Randall Degges rdegges

View GitHub Profile
@rdegges
rdegges / index.html
Created July 21, 2017 01:34
Crypto Compare styling.
<tbody>
<tr v-for="coin in coins">
<td>{{ coin.rank }}</td>
<td><img v-bind:src="getCoinImage(coin.symbol)"> {{ coin.name }}</td>
<td>{{ coin.symbol }}</td>
<td>{{ coin.price_usd | currency }}</td>
<td v-bind:style="getColor(coin.percent_change_1h)">
<span v-if="coin.percent_change_1h > 0">+</span>{{ coin.percent_change_1h }}%
</td>
<td v-bind:style="getColor(coin.percent_change_24h)">
@rdegges
rdegges / app.js
Created July 21, 2017 01:32
Crypt Compare getColor
/**
* Return a CSS color (either red or green) depending on whether or
* not the value passed in is negative or positive.
*/
getColor: (num) => {
return num > 0 ? "color:green;" : "color:red;";
}
@rdegges
rdegges / index.html
Created July 21, 2017 01:27
Crypto Compare table.
<table class="table table-hover">
<thead>
<tr>
<td>Rank</td>
<td>Name</td>
<td>Symbol</td>
<td>Price (USD)</td>
<td>1H</td>
<td>1D</td>
<td>1W</td>
@rdegges
rdegges / app.js
Created July 21, 2017 01:21
Crypto Compare setInterval
/**
* Once the page has been loaded and all of our app stuff is working, we'll
* start polling for new cryptocurrency data every minute.
*
*/
setInterval(() => {
app.getCoins();
}, UPDATE_INTERVAL);
@rdegges
rdegges / app.js
Created July 21, 2017 01:16
Crypto Compare created hook.
let app = new Vue({
// ...
created: function() {
this.getCoinData();
}
});
@rdegges
rdegges / app.js
Created July 21, 2017 01:12
Crypto Compare getCoinImage
getCoinImage: function(symbol) {
return CRYPTOCOMPARE_API_URI + this.coinData[symbol].ImageUrl;
}
@rdegges
rdegges / app.js
Created July 21, 2017 01:07
Crypto Compare getCoinData
getCoinData: function() {
let self = this;
axios.get(CRYPTOCOMPARE_API_URI + "/api/data/coinlist")
.then((resp) => {
this.coinData = resp.data.Data;
this.getCoins();
})
.catch((err) => {
this.getCoins();
@rdegges
rdegges / app.js
Last active July 21, 2017 01:07
Crypto Compare getCoins
getCoins: function() {
let self = this;
axios.get(COINMARKETCAP_API_URI + "/v1/ticker/?limit=10")
.then((resp) => {
this.coins = resp.data;
})
.catch((err) => {
console.error(err);
});
@rdegges
rdegges / app.js
Created July 21, 2017 00:50
Crypto Compare Vue app.
/**
* Our Vue.js application.
*
* This manages the entire front-end website.
*/
// The API we're using for grabbing metadata about each cryptocurrency
// (including logo images). The service can be found at:
// https://www.cryptocompare.com/api/
let CRYPTOCOMPARE_API_URI = "https://www.cryptocompare.com";
@rdegges
rdegges / cryptocompare-api-example.sh
Created July 21, 2017 00:39
Crypto Compare API example.
$ curl https://www.cryptocompare.com/api/data/coinlist
{
...
"Data": {
"AVT": {
"Id": "138642",
"Url": "/coins/avt/overview",
"ImageUrl": "/media/1383599/avt.png",
"Name": "AVT",
"CoinName": "AventCoin",