Skip to content

Instantly share code, notes, and snippets.

@andybeak
andybeak / EventServiceProvider.php
Created August 19, 2016 12:25
Laravel 5.2 model events
<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
@andybeak
andybeak / 403.blade.php
Last active July 20, 2016 14:13
Laravel custom errors
@extends('layouts.error')
@section('code')
403
@endsection
@section('shortmessage')
Forbidden&hellip;
@endsection
@section('longmessage')
If authentication credentials were provided in the request, the server <br>
@andybeak
andybeak / TestCase.php
Last active July 12, 2016 15:02
Laravel 5.2 controlling database seeds and migrations
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* Tracks whether we must (re)seed
* @var bool
*/
protected static $needsSeed = true;
@andybeak
andybeak / app-bootstrap.php
Created July 8, 2016 14:45
Laravel 5.2 custom Monolog bootstrap
$app->configureMonologUsing(function($monolog) use ($app) {
// log more severe messages to loggly
$config = $app->make('config');
$logglyToken = $config->get('app.loggly_token');
$tag = $config->get('app.base_domain');
@andybeak
andybeak / checkbox.js
Created July 6, 2016 13:26
jQuery to implement an "All of the above" checkbox
$(".checkbox-all > input").change(function() {
$(':checkbox').prop('checked', this.checked);
});
$("form > input").change(function() {
if (this.checked == false) {
$(".checkbox-all > input").prop("checked", false);
}
})
@andybeak
andybeak / nginx.conf
Last active May 27, 2016 11:57
For blog post - Nginx redirection
# redirects http traffic to https
server {
listen 80;
listen [::]:80;
server_name mysite.co.uk www.mysite.co.uk;
return 301 https://$server_name$request_uri;
}
# redirect non-www to www
@andybeak
andybeak / nginx.conf
Last active September 24, 2018 16:59
Nginx configuration with redirects #nginx #config
# Read
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart#
# http://tautt.com/best-nginx-configuration-for-security/
#
# Generate your key with: openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# Generate certificate: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
## redirects http traffic to https ##
server {
@andybeak
andybeak / Kernel.php
Created May 11, 2016 08:35
Laravel 5.2 Fingers Crossed logging setup
// laravel 5.1 kernel (http and console) to bootstrap using the custom ConfigureLogging class
public function __construct(Application $app, Router $router)
{
parent::__construct($app, $router);
array_walk($this->bootstrappers, function(&$bootstrapper)
{
if($bootstrapper === 'Illuminate\Foundation\Bootstrap\ConfigureLogging')
{
@andybeak
andybeak / fizzbuzz.exs
Created April 11, 2016 09:05
Fizzbuzz with no conditional logic
fizz = fn
  {0, 0, _} -> "FizzBuzz"
  {0, _, _} -> "Fizz"
  {_, 0, _} -> "Buzz"
  {_, _, a} -> "#{a}"
end
foo = fn (n) -> "#{IO.puts(fizz.({rem(n,3), rem(n,5), n}))}" end
for i <- 1..100 do
@andybeak
andybeak / nginx-badbots.conf
Created January 28, 2016 09:03
Fail2Ban badbots filter - edited from Debian apache badbots
# Fail2Ban configuration file
#
# Regexp to catch known spambots and software alike. Please verify
# that it is your intent to block IPs which were driven by
# above mentioned bots.
[Definition]
badbotscustom = EmailCollector|WebEMailExtrac|TrackBack/1\.02|sogou music spider|Baiduspider