Skip to content

Instantly share code, notes, and snippets.

@Veve2
Veve2 / exception_error_handler.php
Created June 14, 2017 14:41
Error to Exception error_handler for PHP
<?php
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
set_error_handler("exception_error_handler");
#!/usr/bin/env php
<?php
include_once 'app/global_vars.php';
require ROOT_DIR . 'vendor/autoload.php';
use Application\Command\InsertFixturesCommand;
use Symfony\Component\Console\Application;
@chalasr
chalasr / BaseEntity.php
Created February 5, 2016 10:30
Selective mapping inheritance in Doctrine2
<?php
namespace App\Util\Doctrine\Entity;
/**
* Base Entity.
*/
class BaseEntity
{
/**
@fredbenenson
fredbenenson / kickstarter_sql_style_guide.md
Last active June 24, 2024 03:28
Kickstarter SQL Style Guide
layout title description tags
default
SQL Style Guide
A guide to writing clean, clear, and consistent SQL.
data
process

Purpose

@johnpolacek
johnpolacek / .gitconfig
Last active July 9, 2024 12:14
My current .gitconfig aliases
[alias]
co = checkout
cob = checkout -b
coo = !git fetch && git checkout
br = branch
brd = branch -d
brD = branch -D
merged = branch --merged
st = status
aa = add -A .
@staltz
staltz / introrx.md
Last active July 22, 2024 09:31
The introduction to Reactive Programming you've been missing
@jasonhofer
jasonhofer / doctrine-dql-type-function.php
Last active December 30, 2021 21:11
Doctrine TYPE() function for DQL. Provides a way to access an entity's discriminator field in DQL queries.
<?php
namespace My\Doctrine\ORM\Query\Functions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
@cou929
cou929 / detect-private-browsing.js
Last active May 1, 2024 21:07
Detect private browsing mode (InPrivate Browsing or Incognito).
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);
@pschultz
pschultz / ForceCharsetPlugin.php
Last active December 9, 2021 16:26
Guzzle plugin to force the response charset. Useful ~if~ when webservers lie to you again.
<?php
use Guzzle\Common\Event;
use Guzzle\Http\Message\Header;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ForceCharsetPlugin implements EventSubscriberInterface
{
private $forcedCharset = 'utf8';
@Graceas
Graceas / FormErrorsSerializer.php
Created September 10, 2013 06:26
Symfony 2 Form Error Serializer. May be used for AJAX form validation. Allows tree and flat array styles for errors.
class FormErrorsSerializer {
public function serializeFormErrors(\Symfony\Component\Form\Form $form, $flat_array = false, $add_form_name = false, $glue_keys = '_')
{
$errors = array();
$errors['global'] = array();
$errors['fields'] = array();
foreach ($form->getErrors() as $error) {
$errors['global'][] = $error->getMessage();