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 / MySearchEngine.php
Created January 6, 2024 09:55
MySearchEngine (Medium Elastic Example)
<?php
namespace Atakan\ElasticEx;
class MySearchEngine
{
public function search($params)
{
$elastic = Elastic::getInstance();
$client = $elastic->getClient();
@atakde
atakde / Elastic.php
Created January 6, 2024 09:52
Elastic PHP (Medium Ex)
<?php
namespace Atakan\ElasticEx;
class Elastic
{
private static $instance = null;
private $client = null;
private function __construct()
@atakde
atakde / checker.sh
Created May 29, 2023 21:02
Run process if not runs
#!/bin/bash
# Define the process name to monitor
process_name="chrome"
# Check if the process is running
if pgrep -x "$process_name" >/dev/null; then
echo "Puppeteer script is running."
else
echo "Puppeteer script is not running. Starting it..."
@atakde
atakde / cli
Created April 22, 2023 09:21
cli
#!/usr/bin/env php
<?php
use PhpCliAppExample\ExampleCLI as PhpCliAppExampleExampleCLI;
require __DIR__.'/vendor/autoload.php';
$app = new PhpCliAppExampleExampleCLI(new Symfony\Component\Console\Application());
$app->run();
@atakde
atakde / ExampleCommand.php
Created April 22, 2023 09:17
example commands symfony console php
<?php
namespace PhpCliAppExample\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@atakde
atakde / ExampleCLI.php
Created April 22, 2023 09:15
Example CLI with PHP
<?php
namespace PhpCliAppExample;
use PhpCliAppExample\Commands\ExampleCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
class ExampleCLI
{
@atakde
atakde / guard-class-test.php
Created April 15, 2023 17:20
PHP Guard Clause
<?php
class TestClass
{
public function isUsernameStartsWithLetter($username)
{
// if empty string trow exception
if (empty($username)) {
throw new Exception('Username is empty');
}
@atakde
atakde / guard_ex2.php
Created April 13, 2023 20:20
Guard Clause Example In PHP
<?php
function saveProfile($data) {
$errors = [];
if (!isset($data['email'])) {
$errors[] = 'Email address is required';
} else {
if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Email address is not valid';
@atakde
atakde / guard_ex.php
Created April 13, 2023 20:11
Guard Clause Example In PHP
<?php
function update($contact, $data) {
if (valid($data)) {
$contact->update($data);
}
}
// How about like that?
const axios = require("axios");
const xml2js = require("xml2js");
const mediumFeedURL = "https://medium.com/feed/@";
const { sendResponse } = require("./responseController");
// find first image in the body of the article
const findImage = (body) => {
const imgRegex = /<img.*?src="(.*?)"/;
const imgSrc = body.match(imgRegex);
if (imgSrc) {