Skip to content

Instantly share code, notes, and snippets.

Corey McMahon coreymcmahon

View GitHub Profile
View reset-postgres-sequences.sql
-- Get all relations from database
SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
@coreymcmahon
coreymcmahon / logging.php
Created Apr 23, 2019
Example logging configuration for Laravel, going to stdout.
View logging.php
<?php
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
],
@coreymcmahon
coreymcmahon / docker-compose.yml
Created Apr 23, 2019
Example Docker Compose file for a Laravel application.
View docker-compose.yml
version: '3.7'
services:
# foodkit php api
app:
container_name: foodkit.app
build:
context: ./docker/app
dockerfile: Dockerfile
image: foodkitapp.io/app
init: true
@coreymcmahon
coreymcmahon / CleanTempCommand.php
Last active Apr 28, 2019
Demonstration of a Laravel console command.
View CleanTempCommand.php
<?php
namespace App;
use Illuminate\Console\Command;
class CleanTempCommand extends Command
{
protected $signature = "app:clean-temp";
@coreymcmahon
coreymcmahon / CleanTempCommand.php
Created Apr 18, 2019
Demonstration of a Symfony console command.
View CleanTempCommand.php
<?php
namespace App;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CleanTempCommand extends Command
{
@coreymcmahon
coreymcmahon / product.json
Created Aug 18, 2018
Frontend interviewee technical task - Test data
View product.json
{
"id": 14557,
"name": "Flat White",
"price": 125,
"before_sale_price": null,
"description": "Freshly-ground beans and steamed milk",
"full_description": "Freshly-ground beans and steamed milk",
"order": 1,
"category": {
"id": 1727,
@coreymcmahon
coreymcmahon / log.sh
Created Oct 31, 2017
Colorize Nginx access log
View log.sh
#!/usr/bin/env bash
tail -f /var/log/nginx/access.log | awk '
/" 2/ {print "\033[32m" $0 "\033[39m"; next;}
/" 3/ {print "\033[37m" $0 "\033[39m"; next;}
/" 4/ {print "\033[33m" $0 "\033[39m"; next;}
/" 5/ {print "\033[31m" $0 "\033[39m"}
'
@coreymcmahon
coreymcmahon / LaravelMeetupLottery.php
Created Sep 21, 2016
Script to randomly select an attendee from the Laravel Bangkok meet up event.
View LaravelMeetupLottery.php
<?php
$attendees = [
// insert attendee list here
];
$winnerIndex = random_int(0, count($attendees)-1);
$winner = $attendees[$winnerIndex];
echo "\n\n";
View debounce.js
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@coreymcmahon
coreymcmahon / explode_resource.php
Last active Sep 1, 2016
Explode a resource identifier into its component parts
View explode_resource.php
<?php
/**
* Parses resource identifiers of the format:
* RESOURCE=s3://username:password@domain/resource
*/
if ($resource = getenv('RESOURCE')) {
// strip off the namespace, assume it's not needed (e.g 's3', 'mysql')
$identifier = explode('://', $resource)[1];
You can’t perform that action at this time.