This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Don't forget to change the namespace! | |
namespace App\Traits; | |
use Cron\CronExpression; | |
use Illuminate\Support\Carbon; | |
use Illuminate\Console\Scheduling\ManagesFrequencies; | |
trait Schedulable{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am nathane on github. | |
* I am nathane (https://keybase.io/nathane) on keybase. | |
* I have a public key ASDWlm4Hih2sLVgfGKC8TfF-1yh0CI9b2ebzN2rAtrK30Ao | |
To claim this, I am signing this object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this to the "boot()" method of your "AppServiceProvider" | |
<?php | |
\Illuminate\Database\Eloquent\Builder::macro('search', function ($name, $search) { | |
return $this->where($name, 'LIKE', $search ? '%'.$search.'%' : ''); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Helper usage: | |
// timeTravel(Carbon::parse('one year ago'), function () {...}); | |
function timeTravel($target, $callback) { | |
Illuminate\Support\Carbon::setTestNow($target); | |
return tap($callback(), function () { | |
Illuminate\Support\Carbon::setTestNow(); | |
}); | |
} | |
// Macro usage: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function preg_quote(str, delimiter) { | |
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&') | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background: url(/assets/img/glitter.gif);background-color: #252830;border-color: #1997c6;border-radius: 0.25rem;color: white;font-weight: bold;letter-spacing: 1px;padding: 0.15rem 0.5rem;text-align: center;text-shadow: 1px 1px 8px #4183D7, -1px -1px 8px #4183D7 , 1px -1px 8px #4183D7 , -1px 1px 8px #4183D7 ;text-transform: capitalize; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Using CURL to download partial content from a URL | |
* | |
* @url file URL to download | |
* @range_start Start range in bytes | |
* @range_end End range in bytes | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Request::macro('match', function ($candidates, $default = null) { | |
$candidates = collect($candidates); | |
$type = collect(request()->getAcceptableContentTypes())->map(function ($type) { | |
return $this->getFormat($type); | |
})->first(function ($type) use ($candidates) { | |
return $candidates->keys()->contains($type); | |
}); | |
$match = $candidates->get($type, $default ?? $candidates->first()); | |
return value($match); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# | |
# github.com/nathane | |
# @natedrug | |
# | |
function encryptTextForHuman($text=null){ | |
try { | |
if(is_null($text) || empty($text)) throw new Exception("Error: expected 'text' argument is missing, empty or null."); | |
return implode(' ', array_map(function($word){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
echo "Running tests... "; | |
exec('vendor/bin/phpunit', $output, $returnCode); | |
if ($returnCode !== 0) { | |
// Show full output | |
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL; | |
echo "Cannot commit changes untill all tests pass." . PHP_EOL; | |
exit(1); | |
} |