Skip to content

Instantly share code, notes, and snippets.

View ricardoaugusto's full-sized avatar
🥽
Focusing

Ricardo Augusto ricardoaugusto

🥽
Focusing
View GitHub Profile
@ricardoaugusto
ricardoaugusto / mysqlworkbench.sh
Last active December 10, 2019 19:38
Link mysqldump on macOS Catalina (requires MySQL Workbench)
ln -s /Applications/MySQLWorkbench.app/Contents/MacOS/mysql /usr/local/bin/mysql
ln -s /Applications/MySQLWorkbench.app/Contents/MacOS/mysqldump /usr/local/bin/mysqldump
@ricardoaugusto
ricardoaugusto / html_scrapper.py
Created March 20, 2020 14:21
Python 3 HTML scrapper
from urllib.request import urlopen
link = 'https://example.net'
f = urlopen(link)
output = f.read()
print(output)
@ricardoaugusto
ricardoaugusto / belongsToMany.php
Created April 16, 2020 22:26
Laravel belongsToMany explanation
class Current extends Model
{
public function final()
{
$this->belongsToMany(
'pivot_model',
'pivot_table',
'current_id',
'final_ID'
);
@ricardoaugusto
ricardoaugusto / restore_migration.php
Created April 22, 2020 20:27
Laravel Restore Table
public function down()
{
(new AnotherMigration)->up();
}
@ricardoaugusto
ricardoaugusto / docker-mysqldump.sh
Last active June 2, 2024 21:02
Export/Import a gzip SQL file from/into a MySQL Docker Container using mysqldump
# To run the MySQL container:
docker-compose exec [container] bash
# Export
# Inside the container:
mysqldump -u [username] -p [database] | gzip -c > [filename].sql.gz
exit
# Local Terminal:
docker cp [container]:/[filename].sql.gz [filename].sql.gz
@ricardoaugusto
ricardoaugusto / mysqldump-10rows.sql
Created May 19, 2020 15:08
Export the schema and 10 rows of data from all tables of a DB
mysqldump --opt --where="1 limit 10" [DATABASE] > dump.sql
@ricardoaugusto
ricardoaugusto / gist:74c3f841a3c263593cecc5c063a89ebb
Created July 28, 2020 02:20 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@ricardoaugusto
ricardoaugusto / trait-with-anonymous-class.php
Created September 20, 2020 11:46
Trait Method Collision Workaround
<?php
trait TraitA {
public function show() {
return 123;
}
}
trait TraitB {
public function show() {
@ricardoaugusto
ricardoaugusto / table-sizes.sql
Created November 3, 2021 09:03
Size of tables in a SQL DB. Source: https://stackoverflow.com/a/46143816
SELECT
TABLE_NAME AS `Table`,
ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024),2) AS `Size (MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "database_name"
#AND
# TABLE_NAME = "table_name"
ORDER BY
@ricardoaugusto
ricardoaugusto / row-count.sql
Created November 3, 2021 09:16
Estimate row count for all tables in a SQL DB. Source: https://stackoverflow.com/a/11778602
SELECT TABLE_NAME,SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'database_name'
GROUP BY TABLE_NAME;