Skip to content

Instantly share code, notes, and snippets.

@mylk
mylk / GeoIpService.php
Created August 14, 2016 16:32
Symfony Geolocation service using geoplugin.net
<?php
/*
* Installation (Symfony):
* =======================
* # services.yml
* services:
* # ...
* acme.geoip:
* class: Acme\AcmeBundle\Service\GeoIpService
@mylk
mylk / UrlCampaignBuilderServiceTest.php
Created August 14, 2016 14:42
Test suite for the UrlCampaignBuilderService
<?php
/**
* Test suite for the UrlCampaignBuilderService at:
* https://gist.github.com/mylk/9a6fe3eaacb605b31aaa7808ac6e6dab
*/
namespace Acme\AcmeBundle\Tests\Service;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@mylk
mylk / UrlCampaignBuilderService.php
Last active August 14, 2016 14:43
A converter of URL to URL with "campaign" query parameters
<?php
/**
* PHPUnit test suite available at:
* https://gist.github.com/mylk/33e3d0e49152cf6b74362dc8a09b9d39
*/
/*
* Installation (Symfony):
* =======================
* # services.yml
@mylk
mylk / UrlShortenerService.php
Last active August 14, 2016 16:57
A Google Shortener API wrapper
<?php
/**
* Supports URL shortening, expanding and analytics retrieval of a given period type.
*/
/*
* Installation (Symfony):
* =======================
* # services.yml
* services:
@mylk
mylk / GreekTaxOfficeType.php
Last active August 14, 2016 14:10
A Symfony Form choice type of Greek tax offices
<?php
/**
* Greek tax offices as in:
* http://www.gsis.gr/gsis/export/sites/default/gsis_site/PublicIssue/documents_DOY/kwdikoi_doy.pdf
*/
/*
* Installation:
* =============
* # services.yml
@mylk
mylk / StatesType.php
Last active April 30, 2021 10:58
A Symfony Forms choice type of the US states
<?php
/*
* Installation:
* =============
* # services.yml
* services:
* # ...
* acme.form.states:
* class: Acme\AcmeBundle\Form\Extension\StatesType
@mylk
mylk / TimezoneType.php
Last active November 9, 2018 18:04
A modified Symfony Forms "timezone" type that also displays the timezone offset
<?php
/**
* A modified version of the original symfony form type that adds the timezone offset.
*
* Original version at:
* https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php
*/
/*
* Installation:
@mylk
mylk / TimeAgoExtension.php
Last active August 14, 2016 14:19
Twig filter that converts a datetime string to an "ago format", like "posted 9 months ago"
<?php
/*
* Installation:
* =============
* # services.yml
* services:
* # ...
* acme.twig.time_ago:
* class: Acme\AcmeBundle\Twig\TimeAgoExtension
@mylk
mylk / JsonDecodeExtension.php
Last active August 14, 2016 14:19
Twig filter that converts a JSON string to object
<?php
/*
* Installation:
* =============
* # services.yml
* services:
* # ...
* acme.twig.json_decode:
* class: Acme\AcmeBundle\Twig\JsonDecodeExtension
@mylk
mylk / IfNullExtension.php
Last active August 14, 2016 14:18
Twig filter that returns a default value if the given one is null
<?php
/*
* Installation:
* =============
* # services.yml
* services:
* # ...
* acme.twig.if_null_extension:
* class: Acme\AcmeBundle\Twig\IfNullExtension