Skip to content

Instantly share code, notes, and snippets.

@Gemorroj
Gemorroj / anti-terrorism
Last active December 27, 2022 20:02
stopping-support-for-terrorism
#!/usr/bin/env php
<?php
/**
* https://gist.github.com/Gemorroj/be72bb393f5de423f0404a43dedbddda
*
* Create file `bin/anti-terrorism`
* Add to composer.json like this:
```
"scripts": {
"post-install-cmd": [
@Gemorroj
Gemorroj / sorters.php
Created August 31, 2022 14:25
sorters
<?php
$arr = [10, 1, 3, 2, 4, 7, 6, 11];
$out = qsort($arr);
// $out = bsort($arr);
// $out = msort($arr);
print_r([$arr, $out]);
// quick sort
function qsort(array $array): array {
@Gemorroj
Gemorroj / test.php
Created September 28, 2020 18:53
shmop + pcntl example
<?php
// @see https://www.php.net/manual/ru/function.pcntl-fork.php#115855
function forkProcess(array $processes, callable $callback, int $memorySizePerProcess = 1024)
{
$l = \count($processes);
$sharedMemoryMonitor = \shmop_open(\ftok(__FILE__, \chr(0)), 'c', 0644, $l);
$sharedMemoryIds = [];
for ($i = 1; $i <= $l; $i++) {
@Gemorroj
Gemorroj / README.md
Created December 28, 2018 10:15
tempo.io 429 - to many requests
@Gemorroj
Gemorroj / state.json
Last active July 29, 2018 10:19
redux global state example
{
"isLoggedInUser": false,
"components": {
"login": {
"isLoading": false,
"error": null
},
"grid_posts": {
"isLoading": false,
"error": null,
@Gemorroj
Gemorroj / Decimal.php
Last active July 2, 2017 13:15
Litipk\BigNumber
<?php
namespace Litipk\BigNumbers;
class Decimal
{
public static function fromInteger(int $intValue): Decimal // notify IDE Decimal object
{
self::paramsValidation($intValue, null);
return new static((string)$intValue, 0); // use static (not self). Price object, not Decimal
@Gemorroj
Gemorroj / client.php
Created June 13, 2017 11:11
php bug #74679
<?php
$client = new SoapClient(__DIR__ . '/test.wsdl', array(
'trace' => true,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
));
$client->receiveEDIMessages();
echo $client->__getLastResponse();
<?php
namespace SoftClub\Butb2Bundle\Command;
use SoftClub\Butb2Bundle\Service\SoapClient;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder;
@Gemorroj
Gemorroj / alpari.sql
Last active August 29, 2016 17:58
Alpari SQL
-- scheme
CREATE TABLE `ticks` (
`id` int(10) UNSIGNED NOT NULL,
`symbol` varchar(255) NOT NULL,
`date` date NOT NULL,
`value` decimal(3,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `ticks` (`id`, `symbol`, `date`, `value`) VALUES
(1, 'EURUSD', '2014-01-10', '1.34'),