Skip to content

Instantly share code, notes, and snippets.

View KaiCMueller's full-sized avatar

Kai Müller KaiCMueller

View GitHub Profile
@KaiCMueller
KaiCMueller / array_merge_recursive_distinct.php
Created November 9, 2017 10:12
Merging two multi dimensional arrays, overwriting existing values
<?php
/**
* array_merge_recursive does indeed merge arrays, but it converts values with duplicate
* keys to arrays rather than overwriting the value in the first array with the duplicate
* value in the second array, as array_merge does. I.e., with array_merge_recursive,
* this happens (documented behavior):
*
* array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
* => array('key' => array('org value', 'new value'));
// global array
array = new Array();
Selenium.prototype.doStoreCellValue = function(variableName,cellPosition)
{
var xy = cellPosition.split(",");
var x = xy[0] - 1;
var y = xy[1] - 1;
var value = array[x][y];
storedVars[variableName] = value;
@KaiCMueller
KaiCMueller / AdminController.php
Last active April 2, 2018 11:49
Add template parameters in EasyAdmin
<?php
namespace App\Controller;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
/**
* General controller for administrating all entities
*/
class AdminController extends BaseAdminController
@KaiCMueller
KaiCMueller / services.yaml
Last active June 18, 2018 12:36
Symfony Framework: Using methods and constants in service parameters
services:
My\Custom\Service:
class: My\Custom\Service
arguments:
- "@=service('My\\\\Custom\\\\Config').getCustomString()"
- !php/const My\Custom\ServiceConstants::MY_CONSTANT
- "@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"
@KaiCMueller
KaiCMueller / doctrine_migrations.yaml
Last active November 28, 2023 07:13
Doctrine Migrations Template
doctrine_migrations:
dir_name: "%kernel.project_dir%/src/Migrations"
namespace: "App\\Migrations"
custom_template: "%kernel.project_dir%/src/Migrations/migration.tpl"
@KaiCMueller
KaiCMueller / layout.html.twig
Last active July 3, 2018 11:35
Extending the EasyAdmin core template
{# this template is located in templates/bundles/EasyAdminBundle/default/layout.html.twig #}
{# pay attention to the "!" in front of the bundle name which tells symfony to use the core template #}
{% extends '@!EasyAdmin/default/layout.html.twig' %}
{% block head_javascript %}
{{ parent() }}
{% block application_javascript %}{% endblock application_javascript %}
{% endblock head_javascript %}
@KaiCMueller
KaiCMueller / paginator.html.twig
Created August 27, 2018 15:10
Adding page numbers to EasyAdmin list views
{% trans_default_domain 'EasyAdminBundle' %}
{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %}
{% if paginator.haveToPaginate %}
<div class="list-pagination">
<div class="row">
<div class="col-sm-3 hidden-xs list-pagination-counter">
{{ 'paginator.counter'|trans({ '%start%': paginator.currentPageOffsetStart, '%end%': paginator.currentPageOffsetEnd, '%results%': paginator.nbResults})|raw }}
</div>
@KaiCMueller
KaiCMueller / menu.html.twig
Created December 12, 2018 16:27
EasyAdmin: Active entity menu items
{% macro render_menu_item(item, translation_domain) %}
{% if item.type == 'divider' %}
{{ item.label|trans(domain = translation_domain) }}
{% else %}
{% set menu_params = { menuIndex: item.menu_index, submenuIndex: item.submenu_index } %}
{% set path =
item.type == 'link' ? item.url :
item.type == 'route' ? path(item.route, item.params) :
item.type == 'entity' ? path('easyadmin', { entity: item.entity, action: 'list' }|merge(menu_params)|merge(item.params)) :
item.type == 'empty' ? '#' : ''
@KaiCMueller
KaiCMueller / index.js
Last active March 20, 2019 11:58
Cordova app which loads a website in full screen and opens external links in system browser
var appUrl = 'https://www.my-website.com';
var app = {
currentUrl: appUrl,
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
@KaiCMueller
KaiCMueller / doctrine_order_by_null_values_first.php
Created September 16, 2019 12:27
Doctrine: Order by NULL values first
<?php
$queryBuilder
->addSelect("(CASE WHEN entity.placedDate IS NULL THEN 1 ELSE 0 END) AS HIDDEN PLACED")
->orderBy('PLACED', 'DESC')
->addOrderBy('entity.placedDate', 'DESC');