Skip to content

Instantly share code, notes, and snippets.

View atakde's full-sized avatar
🎯
Focusing

Atakan Demircioğlu atakde

🎯
Focusing
View GitHub Profile
<?php
$array = range(1, 1000000);
$start = microtime(true);
$count = count($array);
for ($i = 0; $i < $count; $i++) {
$array[$i] = $i + 1;
}
echo "Method 2: ".((microtime(true)-$start));
<?php
$array = range(1, 1000000);
$start = microtime(true);
// do while
$count = count($array);
$i = 0;
do {
@atakde
atakde / PSession.php
Created November 15, 2022 21:09
Php Session Wrapper Class
<?php
class PSession
{
/**
* @var array
*/
private array $options = [];
/**
* @var array|string[]
@atakde
atakde / RateLimiter.php
Created December 7, 2022 17:47
Rate limiter php
<?php
namespace Atakde\RateLimiter;
use Atakde\RateLimiter\Storage\StorageInterface;
/**
* Class RateLimiter
* Token Bucket Algorithm
* @package Atakde\RateLimiter
// check first letter capital and end with a dot
const checkWord = (word) => {
if (word[0] === word[0].toUpperCase() && word[word.length - 1] === ".") {
return true;
}
return false;
};
console.log(checkWord("Hello.")); // true
const isFirtstLetterCapital = word => word[0] === word[0].toUpperCase();
const isEndWithDot = word => word[word.length - 1] === ".";
const checkWord = word => isFirtstLetterCapital(word) && isEndWithDot(word);
console.log(checkWord("Hello.")); // true
@atakde
atakde / Facade.php
Created January 22, 2023 06:57
Facade Design Pattern PHP Example
<?php
interface Shape
{
public function draw();
}
class Rectangle implements Shape
{
public function draw()
@atakde
atakde / RemoveTweets.js
Created January 24, 2023 05:46
RemoveTweets With JS
try {
(async () => {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let found;
while (found = document.querySelectorAll('[data-testid="caret"]').length) {
@atakde
atakde / main.py
Created February 1, 2023 13:28
Caption Generator FastAPI
import os
from fastapi import FastAPI
from pydantic import BaseModel
import replicate
app = FastAPI()
os.environ.get("REPLICATE_API_TOKEN")
class Item(BaseModel):
image: str
@atakde
atakde / vercel.json
Created February 1, 2023 15:05
Vercel Json For FastAPI App
{
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",