Skip to content

Instantly share code, notes, and snippets.

@mylk
mylk / chromedriver_downloader.sh
Created December 13, 2020 17:15
Downloads the suitable chromedriver for your Chrome browser version
#!/bin/bash
CHROME_VERSION=`google-chrome-stable --version | awk '{print($3)}' | awk -F '.' '{print($1"."$2"."$3)}'`
CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION}"`
echo "Chrome version: ${CHROME_VERSION}"
echo "Suitable chromedriver version: ${CHROMEDRIVER_VERSION}"
echo ""
echo "Downloading chromedriver..."
@mylk
mylk / RssFeedGeneratorService.php
Created October 16, 2016 15:28
A class that generates an RSS feed from an array of entities
<?php
/*
* Installation (Symfony):
* =======================
* # services.yml
* services:
* # ...
* acme.rss_feed_generator:
* class: Acme\AcmeBundle\Service\RssFeedGeneratorService
@mylk
mylk / executeWithExponentialBackOff.php
Last active October 15, 2016 14:10
A method that performs exponential backoff on a callback method
<?php
// $this->executeWithExponentialBackOff("self::myMethodName", array("id" => 1), 64);
// in this exmaple myFunctionName() is private and resides in the same class as executeWithExponentialBackOff().
// myFunctionName() has to throw an exception when it fails for the backoff to be performed.
class Foo
{
private function executeWithExponentialBackOff($callback, $parameters, $timeout)
{
@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
@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.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.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 / 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 / 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 / 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
*/
/*