Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
@coreymcmahon
coreymcmahon / log.sh
Created October 31, 2017 04:38
Colorize Nginx access log
#!/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 September 21, 2016 07:13
Script to randomly select an attendee from the Laravel Bangkok meet up event.
<?php
$attendees = [
// insert attendee list here
];
$winnerIndex = random_int(0, count($attendees)-1);
$winner = $attendees[$winnerIndex];
echo "\n\n";
// 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 September 1, 2016 08:04
Explode a resource identifier into its component parts
<?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];
@coreymcmahon
coreymcmahon / index.html
Created May 29, 2015 07:00
Typical HTML component of a Single Page App (SPA) - http://slashnode.com
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>My Web App</title>
</head>
<body>
<div id="react-app"></div>
<script src="/js/bundle.js"></script>
<?php namespace Acme\Models;
/**
* In Laravel 4.2: app/src/Models/User.php
*
* In Laravel 5.x: app/Models/User.php
*/
class User
{
<?php namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
<?php namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/** ... etc */
public function map(Router $router)
{
<?php
/** in app/Http/Middleware/GuestMiddleware.php */
class GuestMiddleware implements Middleware
{
public function handle($request, Closure $next)
{
if (\Auth::check()) {
return new RedirectResponse(url('/'));
@coreymcmahon
coreymcmahon / Article.php
Created February 15, 2015 12:47
Laravel 5: camel-case to snake-case mapping for eloquent relations has been dropped - http://slashnode.com/definitive-laravel-4-to-laravel-5-migration-guide/
<?php namespace App\Models;
class Article extends Model
{
/** etc... */
public function associatedUsers()
{
return $this->belongsToMany('...');
}
/** etc... */