Skip to content

Instantly share code, notes, and snippets.

View MTheProgrammer's full-sized avatar

Matt Chad MTheProgrammer

View GitHub Profile
@MTheProgrammer
MTheProgrammer / jq_replace_env_vars.sh
Created November 4, 2022 08:21
jq tricks (JSON parser)
#!/bin/bash
# This script replaces `${ENVIRONMENT_VAR}` with the value of `ENVIRONMENT_VAR` environment variable.
# Output is compacted with `-c` param of `jq` program. This means that no pretty printed JSON is returned as it is more suitable for machine processing.
set -e
jq -c 'with_entries( .value |= sub("(?<tmpl_var>\\$\\{.*?\\})"; "\(env[.tmpl_var[2:-1]])") )' "$1"
<script>
const isActive = ref(true)
const error = ref(null)
const classObject = computed(() => ({
active: isActive.value && !error.value,
'text-danger': error.value && error.value.type === 'fatal'
}))
</script>
@MTheProgrammer
MTheProgrammer / symfony-6-tailwind.md
Created December 22, 2022 14:23
Chat gpt programming questions

Using Symfony 6 and Tailwind, refactor this into modern looking login form: Here place code snippet

@MTheProgrammer
MTheProgrammer / Mac OS
Last active July 4, 2024 09:46
Instal php with asdf and postgres pdo
brew install libpq
PHP_CONFIGURE_OPTIONS="--with-pgsql --with-openssl --with-sodium --with-xsl --with-iconv=$(brew --prefix libiconv)" asdf install php 8.1.25
Generate PHP8.1 data model class with constructor promoted properties named ${DTO_NAME} with fields extracted from this array keys:
[
"externalid" => $quoteItem->getItemId(),
"name" => $quoteItem->getName(),
"price" => $this->coreHelper->priceToCents($quoteItem->getPrice()),
"quantity" => $quoteItem->getQty(),
"sku" => $quoteItem->getSku(),
"description" => $quoteItem->getDescription(),
"imageUrl" => $imageUrl,
"productUrl" => $product->getProductUrl()

Introduction

Because Varnish doesn't support SSL, most people choose a setup where Nginx SSL will forward all traffic to Varnish and Varnish will forward will forward the traffic it cannot handle back to nginx. Or worse, bind Varnish on port 80 and direct all traffic into Varnish. This will already degrade performance, because Varnish will purge more because static files are also taking up room in the cache.

Default configuration

Next up, the Nginx configuration of Magento will handle static files.

@MTheProgrammer
MTheProgrammer / elixir-best-practices.md
Last active April 10, 2023 16:05
Elixir Best Practices

Favor pattern matching over guards

Guards are powerful construct, but they increase complexity:

def pasta_recipe(eggs) when is_list(eggs), do: scramble(eggs)

With pattern matching the function definitions is shorter:

def pasta_recipe([_ | _] = eggs), do: scramble(eggs)
@MTheProgrammer
MTheProgrammer / schema_diff_check.php
Created December 4, 2023 06:24
Magento 2 schema upgrade differences check
<?php
// Forked from https://github.com/magento/magento2/issues/19597#issuecomment-671880440
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get(Magento\Framework\App\State::class);
$state->setAreaCode('adminhtml');
@MTheProgrammer
MTheProgrammer / aws-docker.pkr.hcl
Last active August 14, 2024 19:18
Setup Docker on AWS EC2 with HashiCorp Packer
packer {
required_plugins {
amazon = {
version = ">= 1.0.0"
source = "github.com/hashicorp/amazon"
}
}
}
variable "aws_region" {