Skip to content

Instantly share code, notes, and snippets.

View gskema's full-sized avatar

Gytis Šk. gskema

  • Kaunas, Lithuania
View GitHub Profile
@gskema
gskema / noinspection.php
Last active April 30, 2024 18:08
PhpStorm @noinspection list of all tags
<?php
/** @noinspection ? */
// PhpUndefinedGotoLabelInspection Undefined goto label
// PhpUndefinedVariableInspection Undefined variable
// PhpUndefinedMethodInspection Undefined method
// PhpUndefinedNamespaceInspection Undefined namespace
// PhpUndefinedClassInspection Undefined class
// PhpUndefinedFunctionInspection Undefined function
@gskema
gskema / color-gradient.js
Last active March 2, 2024 22:14
Generate gradient color from 2 or 3 colors using JavaScript. Example: https://jsfiddle.net/e18g5f3L/
/**
* You may use this function with both 2 or 3 interval colors for your gradient.
* For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
*/
function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) {
var color1 = rgbColor1;
var color2 = rgbColor2;
var fade = fadeFraction;
// Do we have 3 colors for the gradient? Need to adjust the params.
@gskema
gskema / BulkInsertQuery.php
Last active November 4, 2023 10:56
PHP PDO / Doctrine DBAL bulk insert query
<?php
namespace YourApp\Repository\Query;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Identifier;
/**
* Class BulkInsertQuery
*
@gskema
gskema / convert.php
Created February 4, 2016 12:53
Integer number in Lithuanian words
<?php
/**
* Converts an integer number to a word in Lithuanian language.
*
* @param int $number Integer number to be converted into words
* @param array|bool $units Units array like array(0 => šimtas, 1 => šimtai, 2 => šimtų);
* @param bool $one If false, word "vienas" is omitted
* @return string
*/
@gskema
gskema / db.php
Created September 1, 2015 11:15
PHP PDO bulk INSERT
<?php
class Db
{
public function batchInsert($table, array $rows, array $columns = array())
{
// Is array empty? Nothing to insert!
if (empty($rows)) {
return true;
}
@gskema
gskema / NestedIterator.php
Last active May 3, 2021 14:32
PHP Nested Iterator
<?php
namespace Iterator;
use ArrayIterator;
use Iterator;
/**
* Takes a set of iterators [iterator1, iterator2, iterator3, ...]
* and iterates in an equivalent way to:
@gskema
gskema / ContainerServiceId.php
Created April 22, 2020 07:09
Get service ID from Symfony container by object service
<?php
namespace Vrt\UtilsBundle\Service;
use RuntimeException;
use Symfony\Component\DependencyInjection\Container;
// AppKernel::initializeContainer()
// if ('dev' === $this->environment) {
// ContainerServiceId::setContainer($this->container);
@gskema
gskema / permutation_iterator.php
Created February 14, 2019 12:35
PHP Permutation Iterator
<?php
class PermutationIterator implements Iterator
{
/** @var array */
protected $items;
/** @var int */
protected $slots;
@gskema
gskema / html_trim_whitespace.php
Last active August 4, 2018 06:44
HTML whitespace trim RegEx (regular expression) for PHP. Useful for trimming HTML content before TCPDF processing.
<?php
// Trims whitespaces after any tags. Assumes that a tag ends with '/>', '\w>', '">'.
$html = preg_replace('#(["|\/|\w]>)(\s+)#', '$1', $html);
// Trims whitespaces before any tags. Assumes that tags start with '<\w+'
$html = preg_replace('#(\s+)(<\/?\w+)#', '$2', $html);
// Trims spaces between tags (both opening and closing).
// Assumes that a tag ends with '/>', '\w>', '">' and starts with '<\w+'
@gskema
gskema / auto_test_clone.php
Last active June 8, 2018 21:20
Automatic PHPUnit test for object cloning ::__clone()
<?php
use PHPUnit\Framework\TestCase;
class CloneTest extends TestCase
{
/**
* @dataProvider testClone
*
* @param object $obj0