Skip to content

Instantly share code, notes, and snippets.

View ajardin's full-sized avatar
🏠
Working from home

Alexandre Jardin ajardin

🏠
Working from home
View GitHub Profile
@ajardin
ajardin / proximis.sh
Created June 28, 2016 12:23
A bash script that initializes/updates a Proximis project.
#!/bin/bash
BEHAVIOR="${1}"
if [[ "${BEHAVIOR}" != "bootstrap" && "${BEHAVIOR}" != "update" && "${BEHAVIOR}" != "reindex" ]]; then
echo "$(tput setaf 1)Please specify a valid behavior: $(tput bold && tput setaf 1)bootstrap$(tput sgr0 && tput setaf 1) or $(tput bold && tput setaf 1)update$(tput sgr0 && tput setaf 1) or $(tput bold && tput setaf 1)reindex$(tput sgr0 && tput setaf 1).$(tput sgr0)"
exit 1
fi
if [[ "${2}" =~ "/" ]]; then
GROUP_NAME=$(echo "${2}" | cut -f1 -d/)
@ajardin
ajardin / main.js
Created September 20, 2016 16:18
Update a JavaScript function body without overwriting the whole code.
/*
In the code below, "form_validation" is a JavaScript function provided by a third-party component. This function validates
and then sends the form values. Since these two behaviors are linked, it's impossible to only validate the form in this state.
But we can update the function without overwriting the whole code.
*/
if (typeof form_validation === 'function') {
var definition = form_validation.toString()
.replace(/myForm\.submit\(\);?/, 'return true;');
@ajardin
ajardin / magento1.conf
Created January 11, 2017 17:06
Nginx/PHP-FM configuration for a Magento1 application
server {
listen 80;
server_name magento1.dev;
root /var/www/html/magento1;
location / {
index index.php;
try_files $uri @rewriteapp;
}
@ajardin
ajardin / .blackfire.yml
Created December 30, 2017 22:54
Blackfire sample for Magento
tests:
Pages should be fast enough:
path: "/.*"
assertions:
- "main.wall_time < 3s"
- "main.io < 1s"
- "main.cpu_time < 2s"
Pages should not consume too much memory:
path: "/.*"
@ajardin
ajardin / project.local.json
Last active February 25, 2018 22:28
My Proximis configuration file.
{
"Change": {
"Application": {
"development-mode": true
},
"Cache": {
"block": false,
"page": false
},
"Db": {
@ajardin
ajardin / categories.sql
Last active April 6, 2018 20:47
How to clean up a Magento database
DELETE cce , cceda , ccede , ccei , ccet , ccev FROM catalog_category_entity cce
LEFT JOIN
catalog_category_entity_datetime AS cceda ON cce.entity_id = cceda.entity_id
LEFT JOIN
catalog_category_entity_decimal AS ccede ON cce.entity_id = ccede.entity_id
LEFT JOIN
catalog_category_entity_int AS ccei ON cce.entity_id = ccei.entity_id
LEFT JOIN
catalog_category_entity_text AS ccet ON cce.entity_id = ccet.entity_id
LEFT JOIN
@ajardin
ajardin / aws-connect.sh
Last active April 10, 2018 10:51
Make the SSH connection to EC2 instances easier by requiring only tag values instead of IP addresses.
#!/usr/bin/env bash
set -euo pipefail
# ======================================================================================================================
# Make the SSH connection to EC2 instances easier by requiring only tag values instead of IP addresses.
#
# Usage:
# bash aws-connect.sh <environment> <bastion|apache|nginx|...> <index>
#
# Examples:
@ajardin
ajardin / mysql-volume.txt
Last active April 17, 2018 15:50
Use MySQL data directly from a Docker volume.
# Extract MySQL data
docker run --rm --volumes-from XXXXX -v $(pwd):/backup busybox sh -c "tar cvf /backup/backup.tar /var/lib/mysql"
# Restore MySQL data
docker run --rm --volumes-from XXXXX -v $(pwd):/backup busybox sh -c "tar xvf /backup/backup.tar var/lib/mysql/"
@ajardin
ajardin / commit-msg.sh
Last active June 20, 2018 19:07
Git commit-msg hook to validate message format.
#!/usr/bin/env bash
set -euo pipefail
# ====================================================================================================
# The script below allows to check automatically a commit message before saving it.
# In order to use it, you have to copy this code in .git/hooks/commit-msg inside your project.
# Don't forget to add proper permissions if you create a new file (chmod +x). Bash 3+ is required.
# ====================================================================================================
COMMIT_MSG=$(cat $1)
@ajardin
ajardin / sync-tags.sh
Last active September 17, 2019 20:03
Adding tags to EBS volumes.
#!/usr/bin/env bash
set -euo pipefail
# Retrieve the current EC2 instance ID.
declare -r instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
# Retrieve the AWS region ID where the EC2 instance is located.
declare -r region_id=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | grep -Po "(us|ca|ap|eu|sa)-(north|south)?(east|west|central)-[0-9]+")
# Retrieve the volumes attached to the current EC2 instance.