Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / FooTest.php
Last active March 23, 2023 10:06
PHPUnit 10 - Replacement for deprecated withConsecutive() method
View FooTest.php
<?php
// @see: https://github.com/sebastianbergmann/phpunit/issues/4026
// Use `$this->with(...$this->consecutiveParams($args1, $args2))` instead of `$this->withConsecutive($args1, $args2)`.
use PHPUnit\Framework\TestCase;
class FooTest extends TestCase
{
use ConsecutiveParams;
@ziadoz
ziadoz / test.sh
Created March 22, 2023 13:52
Laravel - Install Composer dependencies via Docker for testsuite
View test.sh
# Put this inside /bin/test.sh to install Laravel's dependencies before running testsuite in Docker.
docker run \
-it \
--rm \
-w /data \
-v ${PWD}:/data:delegated \
--entrypoint /bin/sh \
registry.gitlab.com/grahamcampbell/php:8.1-base -c 'curl -o /tmp/composer-setup.php https://getcomposer.org/installer && php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && composer install'
@ziadoz
ziadoz / docker-compose.yml
Created March 21, 2023 23:23
Miniflux Docker Compose
View docker-compose.yml
version: '3.4'
services:
miniflux:
image: miniflux/miniflux:latest
ports:
- "80:8080"
depends_on:
- db
environment:
- DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
@ziadoz
ziadoz / fix-osx-wifi-battery-drain.md
Last active March 21, 2023 22:15
Fix OSX battery draining on sleep due to wifi activity
View fix-osx-wifi-battery-drain.md

Fix OSX battery draining on sleep due to wifi activity

Install SleepWatcher using Homebrew:

sudo chown -R $(whoami) /usr/local
brew update
brew install sleepwatcher

Start the SleepWatcher service:

@ziadoz
ziadoz / meta-programming.php
Created July 17, 2012 03:35
Basic Meta Programming with PHP 5.4
View meta-programming.php
<?php
trait MetaClass
{
protected $__classMethods = array();
static protected $__staticMethods = array();
public function __call($name, $args)
{
@ziadoz
ziadoz / Laravel-Container.md
Last active March 16, 2023 15:21 — forked from zhilinskiy/Laravel-Container.md
Laravel's Dependency Injection Container in Depth
View Laravel-Container.md

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@ziadoz
ziadoz / install.sh
Last active March 16, 2023 14:53
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
View install.sh
#!/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`
@ziadoz
ziadoz / highlighting.js
Last active March 16, 2023 13:21 — forked from jlong/uri.js
URI Parsing with Javascript/jQuery
View highlighting.js
(function($) {
$(document).ready(function() {
// Highlight Navigation
var url = $.parseUrl(document.location);
$('a').each(function() {
var link = $.parseUrl(this.href);
if (link.pathname !== '' && link.pathname === url.pathname) {
$(this).siblings().removeClass('active');
$(this).addClass('active');
}
@ziadoz
ziadoz / index.php
Last active March 11, 2023 11:07
Simple PHP / jQuery CSRF Protection
View index.php
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
@ziadoz
ziadoz / awesome-php.md
Last active February 21, 2023 11:21
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.
View awesome-php.md