Skip to content

Instantly share code, notes, and snippets.

View bran921007's full-sized avatar
🏠
Working from home

Fran Perez bran921007

🏠
Working from home
View GitHub Profile
@bran921007
bran921007 / Phpunit-assert_exception.php
Created December 20, 2020 06:15 — forked from VladaHejda/Phpunit-assert_exception.php
Phpunit Exception assertion. For easy multiple testing if Exception is thrown in one test method. For PHP >= 5.5 you can use package with trait: https://packagist.org/packages/vladahejda/phpunit-assert-exception
<?php
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function assertException(callable $callback, $expectedException = 'Exception', $expectedCode = null, $expectedMessage = null)
{
$expectedException = ltrim((string) $expectedException, '\\');
if (!class_exists($expectedException) && !interface_exists($expectedException)) {
$this->fail(sprintf('An exception of type "%s" does not exist.', $expectedException));
}
@bran921007
bran921007 / console-example.php
Created December 20, 2020 06:04 — forked from sallar/console-example.php
PHP Colored CLI Output Script.
<?php
// Output screenshot:
// http://cl.ly/NsqF
// -------------------------------------------------------
include_once 'console.php';
// ::log method usage
// -------------------------------------------------------
Console::log('Im Red!', 'red');
@bran921007
bran921007 / install.sh
Created December 14, 2020 18:07 — forked from ziadoz/install.sh
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# https://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# https://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# https://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# https://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
@bran921007
bran921007 / transpose.php
Created October 15, 2020 11:51 — forked from sword-jin/transpose.php
Laravel collection transpose
// key will be 0,1,2,...
Collection::macro('transpose', function() {
$items = array_map(function(...$items) {
return $items;
}, ...$this->values());
return new self($items);
});
// transpose(['name', 'email'])
@bran921007
bran921007 / base64ToFile.php
Created October 9, 2020 06:28 — forked from leonardopinho/base64ToFile.php
Laravel: Convert base64 to file and resize the final size.
/**
* base64ToFile
* @param $base64
* @param $path
* @param int $width
* @param int $height
* @return string
* @info usage 'Image' => Intervention\Image\Facades\Image::class
*/
public static function base64ToFile($base64, $path, $width = 400, $height = 400)
@bran921007
bran921007 / combine-rgba-colors.js
Created October 7, 2020 08:52 — forked from JordanDelcros/combine-rgba-colors.js
Combine two RGBA colors with JavaScript
// Fast and easy way to combine (additive mode) two RGBA colors with JavaScript.
// [red, green, blue, alpha] based on these maximul values [255, 255, 255, 1].
var base = [69, 109, 160, 1];
var added = [61, 47, 82, 0.8];
var mix = [];
mix[3] = 1 - (1 - added[3]) * (1 - base[3]); // alpha
mix[0] = Math.round((added[0] * added[3] / mix[3]) + (base[0] * base[3] * (1 - added[3]) / mix[3])); // red
mix[1] = Math.round((added[1] * added[3] / mix[3]) + (base[1] * base[3] * (1 - added[3]) / mix[3])); // green
mix[2] = Math.round((added[2] * added[3] / mix[3]) + (base[2] * base[3] * (1 - added[3]) / mix[3])); // blue
// SET THE input old value with following values Input::old('key');
Session::set('_old_input.key', Input::get('value'));
@bran921007
bran921007 / imgur-example.html
Created August 31, 2020 16:41 — forked from homam/imgur-example.html
html2canvas example
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<form method="POST" enctype="multipart/form-data" action="https://www.google.com/save" id="myForm">
<input type="hidden" name="img_val" id="img_val" value="" />
</form>
<div id="more">
<h1 style='color: red'> hello </h1>
<iframe src="https://tags.mli.me/12751">
</iframe>
@bran921007
bran921007 / share-urls.md
Created August 26, 2020 21:31 — forked from apisandipas/share-urls.md
Share url's for Facebook, Twitter, Pinterest and Linkedin with just get variables

Creating share buttons with just URL's

Twitter

http://twitter.com/share?text=<TITLE>&url=<URL>

E.g. http://twitter.com/share?text=This+is+google+a+search+engine&url=https%3A%2F%2Fwww.google.com

Facebook

http://www.facebook.com/sharer.php?u=&amp;p[title]=

@bran921007
bran921007 / youtube_id_regex.php
Created July 23, 2020 23:31 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ