Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / IntercomClientService.php
Created August 14, 2016 17:04
A basic Intercom API wrapper
<?php
/**
* Basic Intercom API wrapper, in case you don't want to use the official,
* or you don't meet the requirements (ex. your PHP is < 5.6)
*
* Official:
* https://packagist.org/packages/intercom/intercom-php
*/
/*
@mylk
mylk / VatCheckerService.php
Created August 14, 2016 17:21
VIES VAT checker service (uses europe.eu)
<?php
/*
* Installation (Symfony):
* =======================
* # services.yml
* services:
* # ...
* acme.vat_checker:
* class: Acme\AcmeBundle\Service\VatCheckerService
@mylk
mylk / FileExtensionGuesserService.php
Created August 15, 2016 08:49
A class that guesses the file extension either from raw binary or base64 data
<?php
namespace Acme\AcmeBundle\Service;
class FileExtensionGuesserService
{
/**
* Guesses the mime type of a file by raw binary or base64 encoded content
* and returns its file type.
*
@mylk
mylk / xvfb.service
Created August 16, 2016 14:15
Xvfb systemd script
# /etc/systemd/system/xvfb.service
[Unit]
Description=X virtual framebuffer
[Service]
Type=simple
User=root
ExecStart=/usr/bin/Xvfb :99 -ac
@mylk
mylk / selenium.service
Created August 16, 2016 14:17
Selenium standalone server systemd script
# /etc/systemd/system/selenium.service
# assumes selenium server and chromedriver exist in the following paths:
# /var/selenium/selenium-server-standalone-2.45.0.jar
# /var/selenium/chromedriver
[Unit]
Description=Selenium Standalone Server
Requires=xvfb.service
After=xvfb.service
@mylk
mylk / Xvfb
Created August 16, 2016 22:01
Xvfb init.d script
#! /bin/sh
# /etc/init.d/Xvfb
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="X virtual framebuffer"
NAME=Xvfb
DAEMON=/usr/bin/$NAME
@mylk
mylk / selenium
Last active August 17, 2016 08:41
Selenium standalone server init.d script
#! /bin/sh
# /etc/init.d/selenium
# assumes that selenium server and chromedriver exist in:
# /var/selenium/selenium-server-standalone-2.45.0.jar
# /var/selenium/chromedriver
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script