Skip to content

Instantly share code, notes, and snippets.

View franzose's full-sized avatar

Yan Ivanov franzose

View GitHub Profile
@franzose
franzose / ga_reporting.php
Last active August 15, 2021 18:11
Google Analytics Reporting API usage example
<?php
// composer require google/apiclient
require __DIR__ . '/vendor/autoload.php';
// This is the file obtained from Google during the service account creation process
// see these links:
// 1. https://console.developers.google.com/apis/credentials/serviceaccountkey
// 2. https://console.developers.google.com/iam-admin/serviceaccounts/create
@franzose
franzose / 01_repository.php
Created April 7, 2021 02:13
Query objects
<?php
class SomeEntityRepository extends EntityRepository
{
public function findThis()
{
// method body
}
public function findThat()
@franzose
franzose / jade-to-laravel-blade-mixins.jade
Last active December 30, 2019 22:05
Jade -> Laravel Blade mixins
//- As you may know, Laravel 5 provides the Elixir to compile assets with no pain.
These mixins is for those of you who want to use Jade power combined with that of Laravel Blade.
The syntax mimic Blade statements, however identation differs in some cases.
- var newline = "\r\n"
- var loopIterator = '$iterator'
//- @extends mixin
Example: +extends('layouts/master')
Compiled: @extends('layouts/master')
<?php
class MakeCoolStuff extends AbstractController
{
public function __construct(
EntityManagerInterface $manager,
YourFunkyService $service
) {
$this->manager = $manager;
$this->service = $service;
<?php
// YourVendor/YourPackage/Behat/Legacy/ClassLoader.php
declare(strict_types=1);
namespace YourVendor\YourPackage\Behat\Legacy;
use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader;
try {
require_once 'path/to/vendor/symfony/class-loader/ClassLoader.php';
@franzose
franzose / maintenance.php
Created January 21, 2018 03:04
Maintenance Mode try
<?php
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if ($this->isMaintenanceMode() && !$this->isUserAdmin()) {
$event->setResponse($this->renderMaintenanceView());
@franzose
franzose / reference.yml
Created April 23, 2017 00:12 — forked from mnapoli/reference.yml
Doctrine YAML configuration reference
# Inspired from http://blog.hio.fr/2011/09/17/doctrine2-yaml-mapping-example.html
MyEntity:
type: entity
repositoryClass: MyRepositoryClass
table: my_entity
namedQueries:
all: "SELECT u FROM __CLASS__ u"
# Class-Table-Inheritance
@franzose
franzose / gist:6837241
Created October 5, 2013 05:58
in app/routes.php
// everything's creating fine. Positions and closure table, all's fine.
$Test = Test::create(array());
$child1 = $Test->appendChild(Test::make(), 0, true);
$child2 = $Test->appendChild(Test::make(), 1, true);
$child3 = $Test->appendChild(Test::make(), 2, true);
$child4 = $Test->appendChild(Test::make(), 3, true);
// this returns ids of $Test, $child1, $child2 and $child3...
dd($child4->prevSiblings()->lists('id'));
@franzose
franzose / gist:6836910
Created October 5, 2013 05:08
`$page = Page::make();` instead of `$page = new Page()`; Then we can set proper position...
public static function make(array $attributes = array())
{
$model = new static();
// Workaround to set the position
if ( ! isset($attributes[static::POSITION]))
{
// We set depth to 0 because newly created model
// via 'create' method has no default closure table
// attributes and is inserted as a root node