Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Carlton carltondickson

🏠
Working from home
  • Carlton Dickson Development Ltd.
  • London
View GitHub Profile
View gist:b14d72d9d3631f870c48
# Exporting entire database:
mysqldump -u user -p database --opt | gzip > database.sql.gz
# Export table
mysqldump -uroot --opt --databases DB_NAME --tables TABLE_NAME | gzip > /tmp/TABLE_NAME.export.sql.gz
# Importing:
gunzip < database.sql.gz | mysql -u user -p database
# Credit http://failshell.io/mysql/using-gzip-and-gunzip-with-mysql-to-importexport-backups/
@carltondickson
carltondickson / gist:ad979cc684027b64c0ff95383ae1c18c
Last active May 30, 2022
Laravel Queue mailable via tinker
View gist:ad979cc684027b64c0ff95383ae1c18c
// Create mailable, e.g. MailableTest
php artisan make:mail MailableTest --markdown=emails.mailable-test
// Run horizon or queue worker
// Open tinker
$mailable = (new \App\Mail\MailableTest())->onQueue('queue-name');
Mail::to('somemail@example.com')->send($mailable);
@carltondickson
carltondickson / gist:28a90ccfed2f6b697aba
Created Mar 12, 2015
Undo commit and push to the wrong branch
View gist:28a90ccfed2f6b697aba
# Credit to http://www.iarp.ca/hobby/computing/36-git-committed-and-pushed-to-the-incorrect-branch
# Ensure you're in the branch that you commited to by accident.
git checkout master
# Reset the branch back one commit.
git reset --soft HEAD^
# Stash the changes
git stash
@carltondickson
carltondickson / gist:62977cee8ea32c6ce594eaa60524292b
Created May 17, 2016
Install and Configure Redis on Ubuntu 16.04
View gist:62977cee8ea32c6ce594eaa60524292b
# From https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04
# Use at your own risk
sudo apt-get update
sudo apt-get install build-essential tcl
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
@carltondickson
carltondickson / postgres-queries.md
Last active Feb 8, 2021
Useful Postgres queries
View postgres-queries.md

Source: Hans-Jürgen Schönig - PostgreSQL performance in 5 minutes https://youtu.be/5M2FFbVeLSs?t=757

SELECT substring(query, 1, 5000) AS short_query,
       round(total_time::numeric, 2) AS total_time,
       calls, round(mean_time::numeric, 2) AS mean,
       round((100*total_time/sum(total_time::numeric) OVER ())::numeric, 2) AS percentage_overall
FROM pg_stat_statements ORDER BY total_time DESC LIMIT 20;
@carltondickson
carltondickson / access-homestead-redis.md
Last active Dec 21, 2020
Access Homestead Redis server from host
View access-homestead-redis.md

For local development only

  • Comment out bind 127.0.0.1 ::1 in nano /etc/redis/redis.conf
  • Set protected-mode no
  • sudo service redis-server restart
  • Access Redis using Redis client, e.q. Redis Deskktop Manager
    • Only need to set address as per Homestead.yaml file, e.g. 192.168.10.10
    • Port is probably default 6379

Better to enable protected mode and set specific bind addresses if for any sensitive environment

@carltondickson
carltondickson / access-homestead-postgres.md
Last active Sep 16, 2020
Access Homestead Postgres DB from host machine
View access-homestead-postgres.md

Check version

SELECT version();

PostgreSQL 12.4 (Ubuntu 12.4-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit

sudo nano /etc/postgresql/12/main/pg_hba.conf

Add the following lines

@carltondickson
carltondickson / instructions.md
Last active Aug 18, 2020
Postgres - Enable/Disable query logging
View instructions.md

Enable query logging

  • Check version, determine which config file to edit

  • SELECT version();

  • PostgreSQL 12.3 (Ubuntu 12.3-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit

  • sudo nano /etc/postgresql/12/main/postgresql.conf

  • Find REPORTING AND LOGGING section and change following settings

  • log_statement = 'all'

  • Reload configuration from command line SELECT pg_reload_conf();

View gist:1616ad52717ad93790e1550a845d30ad
@carltondickson
carltondickson / TestSession.php
Created Jun 6, 2018
Laravel - Jobs - Sessions
View TestSession.php
<?php
# Dispatch the following job from multiple tinker instances will see session never gets updated.
# Using sessions in jobs is bad idea.
# $job = new \App\Jobs\TestSession(1, false);Bus::dispatch($job);
# $job = new \App\Jobs\TestSession(2, false);Bus::dispatch($job);
# @see https://github.com/laravel/framework/issues/20908
namespace App\Jobs;