View s3-client.js
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
const dataURItoBlob = (dataURI, type) => { | |
const byteString = atob(dataURI.split(',')[1]); | |
const ab = new ArrayBuffer(byteString.length); | |
const ia = new Uint8Array(ab); | |
for (let i = 0; i < byteString.length; i++) { | |
ia[i] = byteString.charCodeAt(i); | |
} | |
return new Blob([ab], { | |
type |
View Mongoose_Pagination_Plugin.js
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
function paginate(query = {}, options = {}, callback) { | |
const limit = options.limit || 10; | |
let page = options.page || 1; | |
const countQuery = this.find(query).count(); | |
return new Promise(resolve => { | |
countQuery.exec().then(count => { | |
const pages = Math.ceil(count / limit) || 1; |
View Product of consecutive Fibonacci numbers.js
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
// Given a number, say prod (for product), we search two Fibonacci numbers F(n) and F(n+1) verifying F(n) * F(n+1) = prod | |
// My solution to the code wars challenge https://www.codewars.com/kata/5541f58a944b85ce6d00006a/train/javascript | |
// Not used for this, but here's some code to test if a number is in the Fibonacci sequence. | |
// const isPerfectSquare = num => { | |
// const sq = Math.sqrt(num); | |
// return sq * sq === num; | |
// } | |
// const isFib = num => { | |
// return isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4); |
View deepEqual.js
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
const deepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b); |
View 01_DropZone.jsx
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
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import classNames from 'classnames'; | |
const ANIMATION_DURATION = 1000; | |
class BatchDropZone extends React.Component { | |
static propTypes = { |
View MongooseSingletonModel.js
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
schema.statics = { | |
getSingleton: function (cb) { | |
this.findOne() | |
.sort({ updated: -1 }) | |
.limit(1) | |
.exec((err, model) => { | |
if (err) { | |
cb(err, null); | |
} else if (!model) { | |
cb(err, new this()); |
View starter_02.js
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
if (isEnabled) { | |
// Get all the vendors in your crate. The creator of the crate (you) is | |
// added as a default vendor. | |
const { data: vendors } = await cargo.api.getCrateVendors(CRATE_ID); | |
// Map through each vendor and get the token contracts they created. | |
const contractResponses = await Promise.all( | |
vendors.map(({ vendorId }) => cargo.api.getVendorTokenContracts(vendorId)) | |
); |
View starter_04.js
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
// Get the resale items for our contracts. This method | |
// takes a list of token contract IDs, not addresses. | |
// The IDs are assigned by Cargo and used internally | |
const { data: resaleItems} = await cargo.api.getContractResaleItems( | |
contracts.map(contract => contract.tokenContractId) | |
); | |
// Pass our contract data and resale items to a function that will create some markup | |
// and add it to the page. | |
displayContractContent(contracts, resaleItems); |
View starter_05.js
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
function displayContractContent(contracts, resaleItems) { | |
let template = ''; | |
contracts.forEach(contract => { | |
const { name, symbol, tokenAddress, tokenContractId } = contract; | |
const currentResaleItems = resaleItems[tokenContractId]; | |
let tokenMarkup = ''; | |
currentResaleItems.forEach(token => { | |
const { metadata, price } = token; |
View starter_07.js
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
const tokenRows = document.querySelector('[data-id="token-rows"]'); | |
const txConfirmation = document.querySelector('[data-id="tx-confirmation"]'); | |
// This listener checks to see if we clicked the buy now button | |
tokenRows.addEventListener('click', async evt => { | |
// If the target is the buy now button | |
if (evt.target.dataset.id === 'buy-now') { | |
// We want to get the resale ID and price we set on the button via | |
// data attributes. |
OlderNewer