Skip to content

Instantly share code, notes, and snippets.

View ConAntonakos's full-sized avatar
🏠
Working from home

Constantine Antonakos ConAntonakos

🏠
Working from home
View GitHub Profile
@javilobo8
javilobo8 / download-file.js
Last active April 9, 2024 12:01
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@elliette
elliette / ManyToManyRelationships.md
Last active October 31, 2023 16:03
Describing `belongsToMany` and `hasMany` methods in Sequelize

Defining Many-to-Many Associations in Sequelize

Reference: Sequelize docs on association

Let’s say we have two models: Films and Festivals

We know that a film can be shown at many film festivals and that, conversely, a festival can show many films. This is what is known as a many-to-many relationship.

Knowing this, we can set up our associations:

import hoistStatics from 'hoist-non-react-statics';
import React from 'react';
/**
* Allows two animation frames to complete to allow other components to update
* and re-render before mounting and rendering an expensive `WrappedComponent`.
*/
export default function deferComponentRender(WrappedComponent) {
class DeferredRenderWrapper extends React.Component {
constructor(props, context) {
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}

Motivation

  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small

Examples

Write in an expression-oriented style, scoping variables as locally as possible:

@lencioni
lencioni / AsyncComponent.jsx
Created January 8, 2017 17:09
<AsyncComponent> at Airbnb used for Webpack code splitting
// Usage:
//
// function loader() {
// return new Promise((resolve) => {
// if (process.env.LAZY_LOAD) {
// require.ensure([], (require) => {
// resolve(require('./SomeComponent').default);
// });
// }
// });
@tkh44
tkh44 / async-component.js
Last active May 30, 2017 15:43
modified versions of @acdlite's async component. Uses async/await.
import { Component, createElement } from 'react'
export default function asyncComponent (getComponent) {
return class AsyncComponent extends Component {
static NextComponent = null;
state = { NextComponent: AsyncComponent.NextComponent }
componentWillMount = async () => {
if (this.state.NextComponent) {
return
@tkh44
tkh44 / FileDrop.js
Last active September 13, 2022 01:20
wrapper wround react-dropzone so that you can pass some utilties to the children via function args
import { Component, createElement, DOM } from 'react'
import compose from 'recompose/compose'
import defaultProps from 'recompose/defaultProps'
import withHandlers from 'recompose/withHandlers'
import withReducer from 'recompose/withReducer'
import DropZone from 'react-dropzone'
import { TransitionMotion, spring } from 'react-motion'
import { StyleSheet, css } from 'aphrodite/no-important'
import { animation, colors, commonStyles, font } from 'style'
import Icon from 'art/Icon'
@alexdiliberto
alexdiliberto / date_and_number_formatting.js
Created October 6, 2016 01:35
Vanilla JS date and number formatting
// "October 5, 2016"
(new Date()).toLocaleString('en-us', {month: 'long', day: 'numeric', year: 'numeric'});
new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' }).format(new Date())
// "$123.45"
Number(123.45).toLocaleString('en-us', { style: 'currency', currency: 'USD' });
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(123.45);

Thanks everyone for participating in the quiz!
Many of you have posted correct answers.

What we know:

A top-level App component returns <Button /> from its render() method.

Question:

>What is the relationship between `` and this in that `Button`’s `render()`?