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 = { |
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 |
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()); |
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 post(url, data) { | |
return new Promise((resolve, reject) => { | |
let xhr = new XMLHttpRequest(); | |
xhr.open('POST', url); | |
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); | |
xhr.addEventListener('load', () => { | |
let { response, status } = xhr; | |
let res = JSON.parse(response); | |
if(status >= 200 && status < 400){ |
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; |
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); |
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); |
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
// Initialize cargo using the development network. This will | |
// tell Cargo to use it's contracts on the Rinkeby network. | |
const cargo = new Cargo({ | |
network: 'development', | |
}); | |
const run = async () => { | |
// This will fetch Cargo contract information | |
// so we can begin interacting with those contracts when we are ready. | |
await cargo.init(); |
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)) | |
); |
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
// Update this with your crate ID | |
const CRATE_ID = '98'; | |
// Initialize cargo using the development network. This will | |
// tell Cargo to use it's contracts on the Rinkeby network. | |
const cargo = new Cargo({ | |
network: 'development', | |
}); | |
const run = async () => { |
OlderNewer