Skip to content

Instantly share code, notes, and snippets.

View murtuzaalisurti's full-sized avatar
:octocat:
breaking and fixing code

Murtuzaali Surti murtuzaalisurti

:octocat:
breaking and fixing code
View GitHub Profile
const markdownIt = require("markdown-it")();
module.exports = (...data) => {
const images = data.flatMap((arg, index) => {
if (index === data.length - 1) {
return [];
}
return [
{

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:

@murtuzaalisurti
murtuzaalisurti / dock.sh
Created July 30, 2023 18:15
An example shell script to execute docker commands using flags!
#!/usr/bin/env bash
usage() {
echo "Usage:
$0 [-b] [-r containerName imageName] [-c (up | down)] [-s (containerName | id)] [-x (containerName | id)] [-d (containerName | id)] [-h]
example: $0 -b --- [to build the image]
$0 -c up --- [to create and start a container using docker compose]
-h: help
@murtuzaalisurti
murtuzaalisurti / findStyles.js
Created December 4, 2022 13:02 — forked from macbookandrew/findStyles.js
List unique CSS properties for all DOM elements
/**
* List unique CSS properties for all DOM elements
* Initially created to list unique font stacks on a page
* @see {@link http://stackoverflow.com/a/35022690/ Inspired by this StackOverflow answer}
*
* @see {@link https://gist.github.com/macbookandrew/f33dbbc0aa582d0515919dc5fb95c00a/ URL for this file}
*
* @author AndrewRMinion Design (https://andrewrminion.com)
* @version 1.1
*
@murtuzaalisurti
murtuzaalisurti / after-prefixing.css
Last active June 23, 2022 11:07
How to vendor-prefix and minify your CSS?
*{
margin: 0;
box-sizing: border-box;
-webkit-text-size-adjust: auto;
-moz-text-size-adjust: auto;
text-size-adjust: auto;
}
eleventyConfig.addLiquidShortcode("codepen", function (url) {
const url_array = url.split("/");
const profile_url_array = url_array.filter((string, index) => {
return (index < (url_array.length - 2)) ? true : false
})
const username = profile_url_array[profile_url_array.length - 1];
const user_profile = profile_url_array.join("/");