Skip to content

Instantly share code, notes, and snippets.

View thinkstylestudio's full-sized avatar

Theron Smith thinkstylestudio

View GitHub Profile
@thinkstylestudio
thinkstylestudio / macro.md
Created May 8, 2018 20:47 — forked from brunogaspar/macro.md
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@thinkstylestudio
thinkstylestudio / eloquent-cheatsheet.php
Created May 7, 2018 22:30 — forked from hassansin/eloquent-cheatsheet.php
Laravel 5 Eloquent CheatSheet #laravel #eloquent
Model::
/*Select*/
select('col1','col2')
->select(array('col1','col2'))
->select(DB::raw('businesses.*, COUNT(reviews.id) as no_of_ratings, IFNULL(sum(reviews.score),0) as rating'))
->addSelect('col3','col4')
->distinct() // distinct select
/*From*/
<?php
$macro = var_export($wpTermsArray, true);
$macro = str_replace("stdClass::__set_state", "(object)", $macro);
$wpTermsArray = '$data = ' . $macro . ';';
echo $wpTermsArray;
composer global remove laravel/valet
rm -rf ~/.valet
brew unlink nginx && brew remove nginx && brew uninstall --force nginx
brew unlink php@7.1 && brew remove php@7.1
brew unlink dnsmasq && brew remove dnsmasq
composer global require laravel/valet &&
valet install &&
ping foobar.test
@thinkstylestudio
thinkstylestudio / gist:5b99ca3a5168de48eb59a72cb4994e87
Created March 1, 2018 21:25
How to Efficiently Clean Hidden Link Injections in Your Hacked WordPress Sites - https://managewp.com/blog/clean-link-injections-hacked-websites
<?php
// By default only preview infected posts. Change to 0 to clean posts
$preview_only = 1;
// This is the pattern to search and replace with blank
$pattern = '|
posts where post_content LIKE '%display: none%'";
@thinkstylestudio
thinkstylestudio / HigherOrderOptionalProxy.php
Created August 28, 2017 05:54 — forked from derekmd/Optional.php
Laravel global helper function `optional()`
<?php
namespace App\Support;
class HigherOrderOptionalProxy
{
/**
* The target being transformed.
* Use _ prefix to avoid namespace conflict on __get()
*
@thinkstylestudio
thinkstylestudio / null_pattern.php
Created June 13, 2017 01:03 — forked from eric1234/null_pattern.php
A null object pattern implemented in PHP
<?php
# Implements a recursive null object pattern.
#
# Implemented as a trait so any object can make it's properties use
# the null pattern without resorting to inheritance.
#
# The goal is so you can pull data off a partially populated object
# without excessive existance checks.
trait NullPattern {
@thinkstylestudio
thinkstylestudio / launcher.sh
Created June 1, 2017 18:11 — forked from robertoestivill/launcher.sh
Bash alternative to Franz
#!/bin/bash
open -a "Google Chrome" --new --args --new-window \
'https://tweetdeck.twitter.com' \
'https://web.whatsapp.com' \
'https://blastersystems.slack.com/' \
'https://www.messenger.com/' \
'https://web.telegram.org/' \
'https://web.skype.com' \
'https://hangouts.google.com/' \
@thinkstylestudio
thinkstylestudio / maxBy.php
Created May 25, 2017 18:16 — forked from adamwathan/maxBy.php
maxBy/minBy macros
<?php
Collection::macro('maxBy', function ($callback) {
$callback = $this->valueRetriever($callback);
return $this->reduce(function ($result, $item) use ($callback) {
if ($result === null) {
return $item;
}
return $callback($item) > $callback($result) ? $item : $result;
var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 1280, height: 1024 };