Skip to content

Instantly share code, notes, and snippets.

@stomg7969
stomg7969 / manualUpload.txt
Last active July 25, 2019 20:55
manual sync command
// IMPORTANT! The order must be the same as following.
// 1.
npm run build
// When running 'npm run build', GatsbyJS will run: 'npm run clean' && 'gatsby build'
// 2.
aws s3 sync ./public/ s3://thedevelopark.com --delete
@stomg7969
stomg7969 / buildspec2.yml
Created July 25, 2019 20:11
buildsepc example 2
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
pre_build:
commands:
- echo Removing objects in the S3 bucket...
- aws s3 rm s3://thedevelopark.com --recursive
@stomg7969
stomg7969 / buildspec1.yml
Last active July 25, 2019 20:10
buildspec example 1
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- echo Installing Gatsby and Gatsby-CLI...
- npm install -g gatsby
- npm install -g gatsby-cli
@stomg7969
stomg7969 / s3Sync.txt
Last active July 25, 2019 18:07
S3 synchronization
aws s3 sync ./public/ s3://thedevelopark.com --delete
// "thedevelopark.com" must to changed to your bucket name.
@stomg7969
stomg7969 / deleteRequest.js
Created May 22, 2019 01:15
BLOG - fetch vs axios - 'DELETE'
// DELETE request with fetch => 4 lines
fetch(`${process.env.REACT_APP_HOST}/api/v1/users/${decoded.user_id}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${ token }` }
})
.catch(() => alert('Error Message'));
// DELETE request with axios => 3 lines
axios.delete(`${process.env.REACT_APP_HOST}/api/v1/users/${decoded.user_id}`, {
headers: { Authorization: `Bearer ${token}` }
@stomg7969
stomg7969 / postRequest.js
Created May 22, 2019 00:50
BLOG - fetch vs axios - 'GET'
// POST request with fetch => 13 lines
fetch(`${process.env.REACT_APP_HOST}/api/v1/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify({
user: {
username: username,
@stomg7969
stomg7969 / getRequest.js
Created May 22, 2019 00:47
BLOG - fetch vs axios - 'GET'
// GET request with fetch => 4 lines
fetch(`${process.env.REACT_APP_HOST}/api/v1/profile`, {
method: "GET",
headers: { Authorization: `Bearer ${ token }` }
})
// Regular fetch request doesn't automatically turn 'response' to json format.
// Thus, .json() is required.
.then(r => r.json())
// GET request with axios => 3 lines
@stomg7969
stomg7969 / patchRequest.js
Last active May 22, 2019 00:42
BLOG - fetch vs axios - 'PATCH'
// PATCH request with Fetch => 11 lines
fetch(`${process.env.REACT_APP_HOST}/api/v1/users/${decoded.user_id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
user: { password: newPW }
@stomg7969
stomg7969 / passingDown.js
Created May 14, 2019 18:22
FILTER BLOG - passing down props
// Pass down .searchProducts() only if products are fetched from the backend.
{this.props.products.length ? (
<ProductContainer products={this.searchProducts()} />
) : null}
@stomg7969
stomg7969 / finalFilter.js
Created May 14, 2019 18:20
FILTER BLOG - final filter
// **************** SEARCH Filter ****************
searchProducts = () => {
const filteredProducts = this.multiPropsFilter(
this.props.products,
this.filteredCollected()
);
return filteredProducts.filter(product => {
return product.name
.toLowerCase()
.includes(this.state.passingTags.search.inputTerm);