Skip to content

Instantly share code, notes, and snippets.

View morontt's full-sized avatar
🤖
Just for Fun

Alexander Kharchenko morontt

🤖
Just for Fun
View GitHub Profile
@morontt
morontt / compact.php
Last active November 10, 2024 20:23
CIDR
<?php
class Cidr {
public string $raw;
public int $subnet;
public int $length;
public string $ip;
public function __construct(string $str)
{
/**
* examples:
* 10.10.85.13/32
* 10.10.85.13/24
*/
[$subnet, $mask] = explode('/', $cidr);
return (ip2long($clientIP) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet);
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${RED}Red${NC}"
echo -e "${GREEN}Green${NC}"
@morontt
morontt / excel.php
Created June 24, 2022 13:27
Excel letter columns to number
<?php
function number($str) {
$arr = str_split($str);
$sum = 0;
for ($i = count($arr) - 1; $i >= 0; $i--) {
$idx = ord(strtoupper($arr[$i])) - 64;
$sum += $idx * (26 ** (count($arr) - $i - 1));
}
ip_addresses_*.txt
<?php
/**
* Результат:
* Тестовый текст с тегом 1,
* Итак, счётчик 2, 3 - 4
* И ещё 5
* 6
*/
$text = <<<TEXT
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset slow -c:a copy output.mp4
@morontt
morontt / chicken.go
Last active May 16, 2019 16:09
Chicken problem
package main
// About chickens
// https://habr.com/ru/post/348066
import (
crand "crypto/rand"
"fmt"
"math"
"math/rand"
#!/bin/sh
echo "Test CS-fixer"
echo ""
docker exec container_name sudo -u www-data /var/www/html/vendor/bin/php-cs-fixer fix --dry-run
if [ $? -gt 0 ]
then
echo ""
echo "Found ugly code, not pushing"
@morontt
morontt / .gitignore
Last active December 4, 2018 10:41
log parser
We couldn’t find that file to show.