Skip to content

Instantly share code, notes, and snippets.

View itsjavi's full-sized avatar
🤖

Javi Aguilar itsjavi

🤖
View GitHub Profile
@itsjavi
itsjavi / AbstractDto.php
Created April 3, 2018 12:51
basic DTO concept in PHP
<?php
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
class AbstractDto extends ArrayableJsonableObject implements \ArrayAccess
{
public function __construct(array $properties = [])
{
@itsjavi
itsjavi / service_proxy_pattern.php
Last active May 29, 2017 01:02
PHP Service Proxy + Lazy Proxy patterns
<?php
namespace Foo;
use BadMethodCallException;
use Closure;
use DomainException;
/*
* This example encapsulates before/after method call callbacks inside a the service itself, using a proxy,
@itsjavi
itsjavi / composer-box.php
Created June 6, 2016 17:29
Generate a PHAR using composer and box
#! /usr/bin/env php
<?php
// Usage: composer-box <package-name>:<version> [<config>] [<output>]
ini_set('phar.readonly', false);
$WORKING_DIR = realpath(dirname(__FILE__));
$ROOT_DIR = realpath($WORKING_DIR . '/../');
$TMP_DIR = "${ROOT_DIR}/tmp";
$BUILD_DIR = "${ROOT_DIR}/build";
@itsjavi
itsjavi / scriptloader.js
Last active January 25, 2023 13:07
JS ScriptLoader using ES6 Promises
/*!
* ES6 ScriptLoader snippet
* (c) Javier Aguilar mjolnic.com
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Source: https://gist.github.com/mjolnic/93cc837dd2213ec0636a
*/
window.ScriptLoader = function () {
/**
*
* @param {string} url
@itsjavi
itsjavi / AnnotationParser_with_BaseAnnotation.php
Last active August 29, 2015 14:20
PHP Annotation Parser based on Nette AnnotationParser.php
<?php
/**
* Annotations support for PHP.
* Class based on the Nette Framework annotation parser.
*/
class AnnotationParser
{
/** @internal single & double quoted PHP string */
const RE_STRING = '\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"';
@itsjavi
itsjavi / StopWatch.php
Created February 17, 2015 15:34
A simple "StopWatch" class to measure PHP execution time. The class can handle multiple separate timers at the same time.
<?php
/**
* A simple "StopWatch" class to measure PHP execution time.
* The class can handle multiple separate timers at the same time.
*/
class StopWatch {
/**
* @var $start float The start time of the StopWatch
*/
@itsjavi
itsjavi / bootstrap-equal-height.css
Created June 10, 2014 16:12
Bootstrap 3 responsive equal height columns
/* From: http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-columns-of-same-height */
/* columns of same height styles */
.container-xs-height {
display:table;
padding-left:0px;
padding-right:0px;
}
.row-xs-height {
display:table-row;
@itsjavi
itsjavi / html2image.js
Created May 20, 2014 14:16
Convert an HTML element to a PNG image with html2canvas
// this demo works in http://html2canvas.hertzen.com/examples.html
var $w = window;
html2canvas($('.btn:first').get(0), {
onrendered: function(canvas) {
var win = $w.open();
win.document.write('<img src="'+canvas.toDataURL("image/png")+'"/>');
}
});
@itsjavi
itsjavi / regexp_arrayToFnCall.txt
Created May 12, 2014 11:26
Netbeans array to fn replace
search: \$_SERVER\[\'([A-Z_]{1,})\']
replace: \$this\-\>app\-\>server\(\'$1\'\)
@itsjavi
itsjavi / EventDispatcher.php
Created May 11, 2014 04:46
Basic Event Dispatcher for PHP 5.2+
<?php
/**
* Event dispatcher
*
*/
class EventDispatcher {
public $handlers = array();
public $emitted = array();