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
@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;
@carltondickson
carltondickson / gist:ad979cc684027b64c0ff95383ae1c18c
Last active Aug 3, 2020
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);
View gist:0bff7a425c4b1d0fa6d64c1abf04c91a
# /usr/bin/xdebug
#!/bin/bash
XDEBUG_CONFIG="idekey=xdebug" php -dxdebug.remote_host=`echo $SSH_CLIENT | cut -d "=" -f 2 | awk '{print $1}'` "$@"
@carltondickson
carltondickson / cache.md
Created Feb 28, 2017
Laravel 5.2 cache notes
View cache.md

Cache file name

  • Just an md5 of the cache key
  • Therefore not possible to identify key name from file name - md5 is one way

Cache directory name

  • Level 1 - First 2 characters of filename
  • Level 2 - Next 2 characters of filename
@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