This file contains 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
test('getRandosFromArray returns an array of n random items from an array', () => { | |
let array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}, {id: 9}] | |
let n = 2 | |
let items = utils.getRandosFromArray(array, n) | |
expect(items.length).toBe(n) | |
expect(array).toContain(items[0]) | |
expect(array).toContain(items[1]) | |
}) |
This file contains 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
export const getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let randos = [] | |
for (let i = 0; i < numRandos; i++){ | |
let rand = Math.floor(Math.random() * arrClone.length) | |
randos.push(arrClone.splice(rand,1)) | |
} | |
return randos | |
} |
This file contains 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
export const getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let randos = [] | |
for (let i = 0; i < numRandos; i++){ | |
let rand = Math.floor(Math.random() * arrClone.length) | |
randos.push(arrClone.splice(rand,1)[0]) // splice returns a new array | |
} | |
return randos | |
} |
This file contains 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
export const getRandosFromArray = function(arr, numRandos){ | |
let arrClone = array.slice(0) | |
let shuffled = arrClone.sort(function() { return .5 - Math.random() }) | |
let randos = shuffled.slice(0, numRandos) | |
return randos | |
} |
This file contains 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
export const getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let shuffled = shuffle(arrClone) | |
let randos = shuffled.slice(0, numRandos) | |
return randos | |
} | |
// https://bost.ocks.org/mike/shuffle/ | |
const shuffle = function(array) { | |
var m = array.length, t, i; |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Instagram Gallery</title> | |
<script src="https://unpkg.com/vue@2.5.16/dist/vue.min.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<style type="text/css"> | |
:root{ | |
--color: #95e9ef; | |
--background: #1f1f1f; |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Instagram Gallery</title> | |
<script src="https://unpkg.com/vue@2.5.16/dist/vue.min.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<style type="text/css"> |
This file contains 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
<div id="app"> | |
<h1><a :href="instapage">@{{ username }} on instagram</a></h1> | |
<template v-if="grams.length > 0"> | |
<div v-for="(gram, index) in grams"> | |
<a :href="gram.link"> | |
<img :src="gram.images.standard_resolution.url" :alt="gram.text" /> | |
</a> | |
</div> | |
</template> | |
<div v-else class="loading"></div> |
This file contains 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 app = new Vue({ | |
el: '#app', | |
data: { | |
access_token: "your access token here", | |
url: "https://api.instagram.com/v1/users/self/media/recent/", | |
username: "", | |
grams: [], | |
next_url: "", | |
error: false | |
}, |
This file contains 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
:root{ | |
--color: #95e9ef; | |
--background: #1f1f1f; | |
--spacing: 1rem; | |
--speed: 1700ms; | |
--fontsize: 2rem; | |
} | |
body{ | |
margin: 0; | |
padding: var(--spacing); |
OlderNewer