Skip to content

Instantly share code, notes, and snippets.

View diloabininyeri's full-sized avatar
🏠
Working from home

Dılo abinin yeri diloabininyeri

🏠
Working from home
View GitHub Profile
@diloabininyeri
diloabininyeri / test.php
Created April 14, 2024 04:31
serialize a closure in php
<?php
class ReflectionClosure extends ReflectionFunction
{
const string REGEX_PATTERN = '/function\s*\(\s*(.*?)\s*\)\s*(?:use\s*\(([^)]*)\)\s*)?{\s*(.*?)\s*}/s';
public function getCode(): string
{
$startLine = $this->getStartLine();
$endLine = $this->getEndLine();
@diloabininyeri
diloabininyeri / chain_closure.php
Created March 10, 2024 10:09
The an example of chain closure in php
//dilo surucu
class Step
{
/**
* @var Closure[] $steps
*/
private array $steps;
@diloabininyeri
diloabininyeri / ddd.php
Created February 6, 2024 09:04
Entity,ValueObject and Aggregate in the php(DDD)
<?php
class BookEntity
{
public function __construct(private int $id, private string $title)
{
}
public function getId(): int
@diloabininyeri
diloabininyeri / command.php
Created January 31, 2024 12:13
Get a live output of any command in the php ...
<?php
//Dilo surucu
$spec = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w') // stderr
);
@diloabininyeri
diloabininyeri / Parallel.php
Created January 10, 2024 08:51
php async promise
class Parallel
{
private array $threads = [];
private array $process = [];
public function add(PromiseInterface $promise): self
{
$this->threads[] = $promise;
return $this;
@diloabininyeri
diloabininyeri / index.html
Created December 28, 2023 10:10
An example of php socket server and js socket client
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket Client</title>
</head>
<body>
<button onclick="sendCalculation()">Calculate</button>
<div id="result"></div>
@diloabininyeri
diloabininyeri / client.php
Created December 28, 2023 09:45
simple php socket server and client
<?php
$date = date('Y-m-d H:i:s');
$socket_client = stream_socket_client('tcp://localhost:8080');
while (true) {
fwrite($socket_client, "son gelen $date");
echo fread($socket_client, 1024).PHP_EOL;
sleep(1);
}
@diloabininyeri
diloabininyeri / test.php
Created December 16, 2023 05:08
Bitwise operations permission system example in PHP
class Permission
{
private const int READ = 10;
private const int WRITE = 20;
private const int DELETE = 40;
@diloabininyeri
diloabininyeri / test.php
Created March 22, 2023 11:32
The an example observer design pattern in php
<?php
interface Subscriber
{
public function handle(Blog $blog): void;
}
trait ObserveAble
{
@diloabininyeri
diloabininyeri / mysql.conf
Created March 15, 2023 08:52
logstash input mysql and output mysql
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/database_name"
jdbc_user => "admin"
jdbc_password => "admin"
jdbc_driver_library => "/home/log-stash/drivers/mysql-connector-java-8.0.25.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * FROM my_table_input WHERE id > :sql_last_value ORDER BY id ASC limit 1"
tracking_column => "id"
tracking_column_type => "numeric"