Skip to content

Instantly share code, notes, and snippets.

View semihkeskindev's full-sized avatar
🎉

Semih keskin semihkeskindev

🎉
View GitHub Profile
@semihkeskindev
semihkeskindev / ErrorHelper.ts
Created March 20, 2024 14:10
Print 422 Error messages came from laravel endpoints on frontend
import {message} from 'antd'
export const errorMessage = (error: any, printErrorMessage: boolean = true) => {
if (!error.response) {
return
}
let response = error.response
let data = response.data
let statusCode = response.status
const defaultMessage = 'Bir şeyler ters gitti. Lütfen daha sonra tekrar dene.'
@semihkeskindev
semihkeskindev / search_builder_macro.php
Created May 15, 2024 17:01
Laravel Eloquent Model Builder Macro - Search
Builder::macro('search', function ($attributes, $searchTerm, $compact = false): Builder {
$this->where(function (Builder $query) use ($compact, $attributes, $searchTerm): void {
if ($compact) {
$joinedAttributes = '`'.implode('`, " " ,`', $attributes).'`';
$query->orWhereRaw('upper('.\DB::raw("concat({$joinedAttributes})").') LIKE ?', ["%{$searchTerm}%"]);
} else {
foreach ($attributes as $attribute) {
$query->when(
str_contains($attribute, '.'),
function (Builder $query) use ($attribute, $searchTerm): void {
@semihkeskindev
semihkeskindev / example.js
Last active September 28, 2024 21:11
Selenium Webdriver, listen network traffic
import {Builder, By, until} from 'selenium-webdriver';
import fs from 'fs';
// Tarayıcıyı başlat (bu örnekte Chrome kullanılıyor)
/** @type {WebDriver} */
let driver = await new Builder()
.forBrowser('chrome')
.setLoggingPrefs({performance: 'ALL'})
.build();
@semihkeskindev
semihkeskindev / index.php
Last active January 1, 2025 01:42
Convert class to simple object using reflection
<?php
/**
* Create a simplified object suitable for straightforward
* conversion to JSON. This is relatively expensive
* due to the usage of reflection, but shouldn't be called
* a whole lot, and is the most straightforward way to filter.
*/
public function toSimpleObject()
{