TLDR: Use for...of instead of forEach() in asynchronous code.
For legacy browsers, use for(...;...;...) or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
| #! /bin/bash | |
| ###################################################################### | |
| # | |
| # This script generates an SSL certficate for local development. To | |
| # execute the script, run `bash create-dev-ssl-cert.sh`. Sudo is | |
| # needed to save the certificate to your Mac KeyChain. After the cert | |
| # is generated, you can use `HTTPS=true yarn start` to run the web | |
| # server. | |
| # |
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Mithril Rollup.js</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <link href="bundle.css" rel="stylesheet" /> | |
| </head> | |
| <body> | |
| <div id="app"></div> |
| // jquery required | |
| // maxWidth and maxHeight can be parameters for more flexibility | |
| function (img_ref) { | |
| var img = $(img_ref); | |
| img.on('load', function () { | |
| img.css("width", "auto"); | |
| img.css("height", "auto"); | |
| const atimport = require("postcss-import"); | |
| const { dest, src, task } = require("gulp"); | |
| const postcss = require("gulp-postcss"); | |
| const purgecss = require("@fullhuman/postcss-purgecss"); | |
| const tailwindcss = require("tailwindcss"); | |
| const TAILWIND_CONFIG = "./tailwind.config.js"; | |
| const SOURCE_STYLESHEET = "./src/style.css"; | |
| const DESTINATION_STYLESHEET = "./build/style.css"; |
| const waitFor = (ms) => new Promise(r => setTimeout(r, ms)) | |
| const asyncForEach = async (array, callback) => { | |
| for (let index = 0; index < array.length; index++) { | |
| await callback(array[index], index, array) | |
| } | |
| } | |
| const start = async () => { | |
| await asyncForEach([1, 2, 3], async (num) => { | |
| await waitFor(50) |
| import {Action, ActionCreator, Dispatch} from 'redux'; | |
| import {ThunkAction} from 'redux-thunk'; | |
| // Redux action | |
| const reduxAction: ActionCreator<Action> = (text: string) => { | |
| return { | |
| type: SET_TEXT, | |
| text | |
| }; | |
| }; |
| String.prototype.turkishtoEnglish = function () { | |
| return this.replace('Ğ','g') | |
| .replace('Ü','u') | |
| .replace('Ş','s') | |
| .replace('I','i') | |
| .replace('İ','i') | |
| .replace('Ö','o') | |
| .replace('Ç','c') | |
| .replace('ğ','g') | |
| .replace('ü','u') |
| 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); |