Skip to content

Instantly share code, notes, and snippets.

View jlainezs's full-sized avatar
💭
I may be slow to respond.

Pep Lainez jlainezs

💭
I may be slow to respond.
View GitHub Profile
@jlainezs
jlainezs / docker-compose.yml
Created May 2, 2024 09:00
Cloud SQL proxy in a docker compose file
# ---------------------------------------------------------------
# add the service in the docker-compose.yml file
# use .env file to define
# CLOUD_SQL_INSTANCE
# CLOUD_SQL_PORT
# GC_SQL_SERVICE_CREDENTIALS_FILE
#
# @link https://cloud.google.com/sql/docs/sqlserver/connect-docker
# ----------------------------------------------------------------
cloud_sql_service:
#! /usr/bin/env bash
# Add Ondrej's PPA - Follow screen indications
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# installs PHP 8.1, 8.2, 8.3 with some usual packages
sudo apt install php8.{1,2,3}-{cli,common,curl,mbstring,mysql,opcache,readline,xdebug,xml,zip,bz2,intl}
# Choose PHP version - Follow screen indications
@jlainezs
jlainezs / downloadandrestore.sh
Created January 12, 2024 07:31
Downloads last database dump from Google Cloud and restores it in a local database
#!/usr/bin/env bash
# ------------------------------------------------
# Downloads last backup from production
# and restores it into the local database
#
# requires:
# - gcloud with authenticated access
# - mysqlcredentials.cnf file
# ------------------------------------------------
@jlainezs
jlainezs / build.sh
Created October 4, 2023 09:46
Compile golang source for linux and windows
#!/usr/bin/env bash
# Build tool
# Writes the compiled executables in ./build
#
# see https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04
package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
@jlainezs
jlainezs / dumpmysql.sh
Last active April 24, 2023 07:11
Automated MySQL backup with tables filter.
#!/usr/bin/env bash
# Backup up database tables
# Requires a credentials files on
# ./mysqlcredentials.cnf
#
# CAUTION
# If you have running Google's sqlproxy you could end messing with the remote mysql!
CURRENT_TIME=$(date "+%Y%m%d-%H%M%S")
@jlainezs
jlainezs / git-things.md
Created December 16, 2022 19:23
Git things

Using several accounts on the same git service with ssh

We need to create an alternative certificate for the second account (pk stored in id_rsa.myotheridentity).

WARNING: when generating the new credentials take care not to overwrite any id_rsa and id_rsa.pub files you may have in ~/.ssh

Edit ssh config in ~/.ssh/config . Create it if not exists.

Host gitlabmyproject
@jlainezs
jlainezs / downloadFile.go
Created November 11, 2022 22:58
Download a file using net/http
# https://golangdocs.com/golang-download-files
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
@jlainezs
jlainezs / NestedSet.php
Last active November 10, 2022 10:07
Trait to manage a nested set in Joomla!3
<?php
namespace Traits;
use Joomla\CMS\Factory;
use Throwable;
use Exceptions\NestedSetNodeNotFoundException;
use Exceptions\ParentNotDefinedException;
use Exceptions\UnexpectedException;
use NestedSetPointer;
@jlainezs
jlainezs / zip-git-changed-files.txt
Last active November 2, 2022 11:27
Steps to create a zip file with the changed files of a branch.
# Zip changed files on a branch checked out from an initial branch.
# Open a terminal on the repository root.
# Tested with Git Bash. Requires 7z installed
# get the last commit on the updated branch
git merge-base initial_branch_name updated_branch_name
# get the changed files name (with full path)
git diff --name-only COMMIT_ID > diff-filelist.txt
@jlainezs
jlainezs / change_docker_desktop_image_storage.txt
Created December 12, 2020 17:29
Change images storage location for windows docker desktop running linux containers
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data <NEW_PATH>\docker-desktop-data.tar
eventually restarting docker desktop is required.