Skip to content

Instantly share code, notes, and snippets.

@pizzarob
pizzarob / 01_DropZone.jsx
Last active November 14, 2017 08:28
HTML5 Drag and Drop File Upload React Component
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
const ANIMATION_DURATION = 1000;
class BatchDropZone extends React.Component {
static propTypes = {
const deepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
@pizzarob
pizzarob / Product of consecutive Fibonacci numbers.js
Last active October 15, 2016 00:54
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.
// 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);
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;
@pizzarob
pizzarob / s3-client.js
Created August 16, 2016 20:21
Client Side Image Upload to AWS
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