Skip to content

Instantly share code, notes, and snippets.

View atakde's full-sized avatar
🎯
Focusing

Atakan Demircioğlu atakde

🎯
Focusing
View GitHub Profile
@atakde
atakde / Prototype.php
Created June 29, 2022 17:49
Prototype Design Pattern PHP Example
<?php
abstract class MealPrototype
{
protected $mealName;
protected $mealCategory;
public function getMealName(): string
{
return $this->mealName;
@atakde
atakde / Pool.php
Created June 29, 2022 17:54
Pool Design Pattern PHP Example
<?php
class WorkerEntity
{
private $workerId;
private $workerName;
public function __construct($workerId, $workerName)
{
$this->workerId = $workerId;
@atakde
atakde / deploy.yml
Created August 21, 2022 15:51
Deploy in Digital Ocean With Github Actions
# This is a basic workflow to help you get started with Actions
name: Build And Deploy
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
@atakde
atakde / SitemapController.php
Created September 5, 2022 17:58
Symfony 6 Sitemap Generator
<?php
namespace App\Controller;
use App\Repository\PostRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@atakde
atakde / sitemap.twig.html
Created September 5, 2022 18:03
Symfony 6 Sitemap Twig Template
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
{% for url in urls %}
<url>{# check if hostname is not alreay in url#}
<loc>{{ url.loc }}</loc>
{% if url.lastmod is defined %}
<lastmod>{{url.lastmod}}</lastmod>
@atakde
atakde / DigitalOceanFileUpload.php
Last active May 6, 2023 21:37
Image & File Upload To Digital Ocean Space With PHP
<?php
use Aws\S3\S3Client;
use Symfony\Component\HttpFoundation\Request;
// settings
$client = new S3Client([
'version' => 'latest',
'region' => '{REGION}',
'endpoint' => 'https://{REGION}.digitaloceanspaces.com',
@atakde
atakde / imageUpload.tsx
Created October 16, 2022 13:05
Convert to base 64
const handleImageUpload = (e: any) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
console.log(reader.result);
// make request to your backend
};
};
@atakde
atakde / CompositionAndInheritance.php
Created November 7, 2022 16:56
Inheritance vs Composition with PHP
<?php
class View
{
public function render($name)
{
echo "Rendering view $name";
}
}
<?php
$array = [];
for ($i = 0; $i < 10000; $i++) {
$array[] = $i;
}
$start = microtime(true);
foreach ($array as $k => $v) {
<?php
$array = [];
for ($i = 0; $i < 10000; $i++) {
$array[] = $i;
}
$start = microtime(true);
foreach ($array as $k => $v) {