Skip to content

Instantly share code, notes, and snippets.

View finagin's full-sized avatar
🖖

Igor Finagin finagin

🖖
View GitHub Profile
@finagin
finagin / IdeHelperCommand.php
Last active April 14, 2020 09:29
Must have Laravel Commands
<?php
namespace App\Console\Commands;
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use RuntimeException;
use Throwable;
@finagin
finagin / socks5.sh
Last active September 29, 2021 12:23
#!/usr/bin/env bash
SUDO=''
if [ "$(id -u)" != "0" ]; then
SUDO='sudo'
echo "This script requires superuser access."
echo "You will be prompted for your password by sudo."
# clear any previous sudo permission
sudo -k
fi
@finagin
finagin / collection.php
Created May 28, 2019 15:20
Laravel divide collection
<?php
collect([])
->tap(static function (\Illuminate\Support\Collection $collection) {
$collection->macro('divide', function (int $chunks = 2) {
$size = ceil($this->count() / $chunks);
return $this->chunk($size);
});
})
<?php
function isPalindrome($str)
{
$A = ord('A');
$Z = ord('Z');
$a = ord('a');
$z = ord('z');
$Aa = $a - $A;
$l = 0;
<?php
namespace {
use Illuminate\Support\HigherOrderTapProxy;
if (!function_exists('tap')) {
/**
* Call the given Closure with the given value then return the value.
*
<?php
/**
* Class Certbot
*/
class Certbot
{
/**
* @var self
*/
@finagin
finagin / TruthTable.php
Created September 4, 2018 12:31
Генерация таблицы истинности
<?php declare(strict_types=1);
/**
* @param int $base
*
* @return array[]
*
* @throws \InvalidArgumentException
*/
function generateTruthTable(int $base): array
@finagin
finagin / Cache.php
Last active April 10, 2019 15:03
RunTime Cache
<?php declare(strict_types=1);
namespace Core;
class Cache
{
private $object = null;
private $cache = null;
@finagin
finagin / mutex.php
Created July 17, 2018 08:38
MUTual EXclusion. Semaphore.
<?php declare(strict_types=1);
function phone_semaphore($phone, callable $callback)
{
$sem = sem_get($phone, 1);
if (sem_acquire($sem)) {
$result = $callback();
sem_release($sem);
<?php
$ips = [
'127.0.0.1',
];
$ports = [
20 => 'FTP data',
21 => 'FTP control port',
22 => 'SSH',