Skip to content

Instantly share code, notes, and snippets.

View ghostwriter's full-sized avatar
🐘
while(!succeed=try())

Nathanael Esayeas ghostwriter

🐘
while(!succeed=try())
View GitHub Profile
@ghostwriter
ghostwriter / fabric.curvedText.js
Created April 29, 2016 22:26
Allows you to create curved text - extension to fabric.js
(function (global){
"use strict";
var fabric=global.fabric||(global.fabric={}),
extend=fabric.util.object.extend,
clone=fabric.util.object.clone;
if(fabric.CurvedText){
fabric.warn('fabric.CurvedText is already defined');
@ghostwriter
ghostwriter / BladeDirective.php
Created May 2, 2016 20:47
Declare view-specific variables on the fly with a blade directive. Use @var('variable', 'value') to use. Paste the code from this gist into a service provider.
<?php
\Blade::directive('var', function($expression) {
$segments = array_map(function($segment) {
return trim($segment);
}, explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression)));
return '<?php $' . $segments[0] . " = '" . $segments[1] . "' ?>";
});
@ghostwriter
ghostwriter / autoLink.php
Created May 2, 2016 20:53
Regex function for adding link tags in PHP.
@ghostwriter
ghostwriter / config.md
Created May 7, 2016 03:46
This throttle filter config should tag anything more than 30 events in a 60 second period with "chill-out" and we will skip sending them to pagerduty

filter { throttle { before_count => 30 period => 60 add_tag => "chill-out" } }

output { if "chill-out" not in [tags] {

Keybase proof

I hereby claim:

  • I am nathane on github.
  • I am nathane (https://keybase.io/nathane) on keybase.
  • I have a public key ASByU3CgpIKco5WnArzFLSe0IwXhG2U7edyc-Dhe5-bD9go

To claim this, I am signing this object:

@ghostwriter
ghostwriter / .htaccess
Created April 18, 2017 03:20
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@ghostwriter
ghostwriter / pre-push
Created May 11, 2017 02:47
Git pre-push hook for PHPUnit
#!/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 push changes untill all tests pass." . PHP_EOL;
exit(1);
}
@ghostwriter
ghostwriter / pre-commit
Created May 11, 2017 02:50
Git pre-commit hook for PHPUnit
#!/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);
}
@ghostwriter
ghostwriter / encryptTextForHuman.php
Created May 12, 2017 08:46
Human-Readable Encryption/Decryption
<?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){
@ghostwriter
ghostwriter / request-match.php
Created August 18, 2017 06:06
Request::match() for sending different responses based on Accept header.
<?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);