Skip to content

Instantly share code, notes, and snippets.

View ddotx's full-sized avatar
:octocat:
Developing all the time

Dome J ddotx

:octocat:
Developing all the time
  • < G-TECH >
  • Bangkok
  • 16:25 (UTC +07:00)
  • X @doloto
View GitHub Profile
@ddotx
ddotx / server gen ssl
Last active May 24, 2024 09:59
Getapp
https://griponline.net/extensions/themes/gae_gripautobiz301/staticfiles/templates/tpl/blog-detail/%7B%7Bitem.post_id%7D%7D-%7B%7Bhome.buildTitleUrl(item.post_title)%7D%7D
@ddotx
ddotx / angular.json
Last active March 4, 2021 14:23 — forked from gsans/angular.json
Remove CommonJS or AMD dependencies optimization bailouts warnings for AWS Amplify using Angular v10
"build": {
"builder": "@angular-devkit/build-angular:browser",
...
"options": {
"allowedCommonJsDependencies": ["crypto-js", "@aws-sdk/eventstream-marshaller", "buffer", "js-cookie",
"@aws-crypto", "zen-observable", "@aws-sdk/util-utf8-node", "@aws-crypto/sha256-js", "@aws-sdk/util-buffer-from",
"@aws-sdk/smithy-client", "@aws-sdk/middleware-serde", "@aws-sdk/middleware-user-agent",
"@aws-sdk/middleware-retry", "@aws-sdk/middleware-signing", "@aws-sdk/middleware-content-length",
"@aws-sdk/middleware-host-header", "@aws-sdk/config-resolver", "@aws-sdk/s3-request-presigner",
"@aws-sdk/util-format-url", "@aws-sdk/util-create-request", "@aws-sdk/property-provider",

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@ddotx
ddotx / pil_s3.py
Created April 5, 2022 15:17 — forked from ghandic/pil_s3.py
Load image from S3 directly into memory as PIL image and write to S3 directly from memory from PIL image
import boto3
from PIL import Image
from io import BytesIO
import os
class S3ImagesInvalidExtension(Exception):
pass
class S3ImagesUploadFailed(Exception):
pass
const http = require('axios')
module.exports.handler = async (urls) => {
let sum = 0
for (let i = 0; i < urls.length; i++) {
const url = urls[i]
const body = (await http.get(url)).data
sum += body.length
}
const http = require('axios')
module.exports.handler = async (urls) => {
const promises = urls.map(async url => {
return (await http.get(url)).data.length
})
const counts = await Promise.all(promises)
return counts.reduce((x, acc) => x + acc, 0)
}
@ddotx
ddotx / web.config
Created May 18, 2024 14:00 — forked from iknowkungfoo/web.config
IIS SQL Injection Request Filtering
<filteringRules>
<filteringRule name="SQLInjection" scanQueryString="true">
<appliesTo>
<clear />
<add fileExtension=".asp" />
<add fileExtension=".aspx" />
</appliesTo>
<denyStrings>
<clear />
<add string="@@version" />