Skip to content

Instantly share code, notes, and snippets.

@andyg1
andyg1 / DatabaseSeeder.php
Created November 20, 2015 11:05
Truncating Laravel tables before seeding them
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
protected $toTruncate = ['users'];
public function run()
@andyg1
andyg1 / gist:1b95e4e5590e49394624
Created January 25, 2016 12:45
Cross-browser, mouse leaving the window event
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
addEvent(document, "mouseout", function(e) {
git commit --allow-empty -m 'push to execute post-receive'
@andyg1
andyg1 / public_key_copy
Created February 15, 2016 15:52
copy public key to clipboard
cat ~/.ssh/id_rsa.pub | pbcopy
@andyg1
andyg1 / Laravel Directive: include if logged in
Created March 7, 2016 13:43
Include a Blade view template only if there is a logged in user. Useful for including/excluding views and/or partials for things like menus, logout buttons, etc
/*
* Laravel includeIfAuth() function.
*
* Usage: @includeIfAuth($templateName)
*/
\Blade::directive('includeIfAuth', function ($expression) {
if(\Auth::check()) {
return \Blade::compileString("@include({$expression})");
}
});
// https://gist.github.com/philfreo/1040968
/**
* Add the querystring variable $key with a value $value to $url.
* If $key is already specified within $url, it will replace it.
*
* Based upon http://www.addedbytes.com/code/querystring-functions/
*
* @param string $url
@andyg1
andyg1 / Laravel variables in view template
Created March 22, 2016 13:00
Lists all the variables available to the current view
@dd(get_defined_vars()['__data'])
@andyg1
andyg1 / gist:259b378b6db8fb757949777bff878d93
Created October 28, 2016 07:11
Show files that have been deleted in the currently working git directory
git ls-files --deleted
alias gb='git branch'
alias gg='git status'
alias gitfiles='git diff-tree --no-commit-id --name-only -r '
alias gitlog='git log --graph --abbrev-commit --decorate --format=format:'\''%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'\'''\'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'\'' --all'
#!/bin/bash
# checks any .php files that are edited in the current branch for syntax errors
# reports a list of files, putting errors in red and reporting the error and line number
FILES=$(git status -s | grep '\.php$')
for f in $FILES
do
if [[ $f =~ ^.*\.php$ ]]; then
RESULT=$(php -l $f 2>&1)