Skip to content

Instantly share code, notes, and snippets.

View mgsmus's full-sized avatar

Mustafa Akçakaya mgsmus

View GitHub Profile
@mgsmus
mgsmus / gist:3c7ed5e443f28c0f83e8684b508c359e
Created February 11, 2022 09:21 — forked from devodo/gist:8b39748d65e8185fbd89
PostgreSQL create UUID max aggregate function
CREATE OR REPLACE FUNCTION max (uuid, uuid)
RETURNS uuid AS $$
BEGIN
IF $1 IS NULL OR $1 < $2 THEN
RETURN $2;
END IF;
RETURN $1;
END;
$$ LANGUAGE plpgsql;
<?php
namespace Mgsmus\MyPackage\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
class MyPackageServiceProvider extends ServiceProvider
{
/**
<?php
namespace Mgsmus\MyPackage\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
class MyPackageEventServiceProvider extends EventServiceProvider
{
protected $listen = [
\Mgsmus\MyPackage\Events\EntityCreated::class => [
<?php
//EventServiceProvider::boot()
public function boot()
{
parent::boot();
Event::listen('eloquent.created: App\User', function ($user) {
// $user burada yeni oluşturulmuş User modeli...
});
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
<?php
// Bunun yerine
$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? 'value';
// Şu şekilde bir kullanım mümkün.
// Kod tekrarının önüne geçilmiş oluyor.
$this->request->data['comments']['user_id'] ??= 'value';
<?php
$arr1 = [1, 2, 3];
$arr2 = […$arr1]; //[1, 2, 3]
$arr3 = [0, …$arr1]; //[0, 1, 2, 3]
$arr4 = array(…$arr1, …$arr2, 111); //[1, 2, 3, 1, 2, 3, 111]
$arr5 = […$arr1, …$arr1]; //[1, 2, 3, 1, 2, 3]
function getArr() {
return ['a', 'b'];
<?php
interface Concatable {
function concat(Iterator $input);
}
class Collection implements Concatable {
// Sadece Iterator değil tüm iterable tipleri kabul edecek
function concat(iterable $input) {}
}
<?php
interface Factory {
function make(): object;
}
class UserFactory implements Factory {
function make(): User {}
}
<?php
$y = 1;
$total = fn($x) => $x + $y;