Skip to content

Instantly share code, notes, and snippets.

View tristanbailey's full-sized avatar
🏭
Talking to manufacturers

Tristan Bailey tristanbailey

🏭
Talking to manufacturers
View GitHub Profile
<?php
namespace App\Nova\Filters;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Container\Container;
use Laravel\Nova\Filters\DateFilter as NovaDateFilter;
class DateFilter extends NovaDateFilter
@tristanbailey
tristanbailey / GDPR.md
Created October 11, 2018 12:23
(Data) Protection Racket
@tristanbailey
tristanbailey / Contract Killer 3.md
Created October 11, 2018 12:22 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@tristanbailey
tristanbailey / phplint-folder.sh
Created October 11, 2018 09:00 — forked from james2doyle/phplint-folder.sh
Use PHP lint on a folder of PHP files
#!/usr/bin/env bash
# found on http://kamisama.me/2012/07/02/faster-php-lint/
find my/folder/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l
@tristanbailey
tristanbailey / cspheader.php
Created January 11, 2018 16:04 — forked from phpdave/cspheader.php
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
<?
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *.example.com;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri https://example.com/violationReportForCSP.php;". //A URL that will get raw json data in post that lets you know what was violated and blocked
@tristanbailey
tristanbailey / get-latest-tag-on-git.sh
Last active December 22, 2017 10:20 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@tristanbailey
tristanbailey / docker-xenial-copy-paste.sh
Created October 13, 2016 19:17 — forked from BretFisher/docker-xenial-copy-paste.sh
Install Docker PPA on Ubuntu 16.04
# NOT FOR SHELL SCRIPT, but rather just for quick copy paste
# this is a copy-paste version with defaults of full shell script docker-xenial.sh
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
mkdir -p /etc/apt/sources.list.d && \
echo deb https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list && \
service lxcfs stop && apt-get remove -y -q lxc-common lxcfs lxd lxd-client && \
apt-get update -q && apt-get upgrade -y -q && \
apt-get install -y -q linux-image-extra-$(uname -r) linux-image-extra-virtual && \
apt-get install -y -q docker-engine && \
@tristanbailey
tristanbailey / git-branch-status
Created September 18, 2016 09:22 — forked from jehiah/git-branch-status
show git ahead/behind info for branches
moved to github --> https://github.com/bill-auger/git-branch-status/

ServiceWorker for github pages

This is a ServiceWorker template to turn small github pages into offline ready app.

Why ?

Whenever I make small tools & toys, I create github repo and make a demo page using github pages (like this one).
Often these "apps" are just an index.html file with all the nessesary CSS and JavaScript in it. I wanted to cache this html file so that I can access my tools offline as well.

Notes

Make sure your github pages have HTTPS enforced, you can check Settings > GitHub Pages > Enforce HTTPS of your repository.

UsedByTeams Model Trait For Laravel Spark

Automatically limit your models to the current team

So you're using spark, and you have teams enabled. You start creating models and want to have them be team specific. Instead of writing, Model::where('team_id', auth()->user()->currentTeam->id)->get(); use this trait to add that behind the scenes so that every time you call on your model, it's assumed that you mean for the current team.

This assumes that the model has a team_id, while it adds a scope of where team_id = currentTeam->id.