Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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

Carlton carltondickson

🏠
Working from home
  • Carlton Dickson Development Ltd.
  • London
View GitHub Profile
@carltondickson
carltondickson / postgres-queries.md
Last active February 8, 2021 09:34
Useful Postgres queries

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 December 21, 2020 17:22
Access Homestead Redis server from host

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 September 16, 2020 08:30
Access Homestead Postgres DB from host machine

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 August 18, 2020 07:42
Postgres - Enable/Disable query logging

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();

@carltondickson
carltondickson / TestSession.php
Created June 6, 2018 16:37
Laravel - Jobs - Sessions
<?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 May 30, 2022 03:13
Laravel Queue mailable via tinker
// 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);
# /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 February 28, 2017 11:35
Laravel 5.2 cache notes

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 22:01
Install and Configure Redis on Ubuntu 16.04
# 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