Skip to content

Instantly share code, notes, and snippets.

View egulhan's full-sized avatar
Here we go again...

Erman Gülhan egulhan

Here we go again...
View GitHub Profile
@egulhan
egulhan / request-with-multipart-data-using-guzzle.php
Created January 31, 2019 11:55
Request with Multipart data using Guzzle Http Client
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
function uploadImage($requestUrl, $imageFilePath)
{
$data = [];
try {
@egulhan
egulhan / generate-random-string.js
Created January 7, 2019 13:22
Generate a random string using Javascript
/**
* Generates random string
* @param length
* @returns {string}
*/
function generateRandomString(length) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
length = typeof length == 'undefined' ? 16 : length;
var rndCharIndex, rndStr = "";
@egulhan
egulhan / test-validations-of-formrequest.php
Last active June 30, 2021 08:39
Test validations of a FormRequest in Laravel
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Models\Notification\PushNotification;
use App\Modules\Partner\Requests\CreatePushNotificationRequest;
@egulhan
egulhan / request-with-cookies-using-guzzle.php
Created November 30, 2018 09:09
Request with cookies using Guzzle Http Client
<?php
$cookies = [
'geo' => 'TR',
'goip' => 'JO',
];
$cookieJar = \GuzzleHttp\Cookie\CookieJar::fromArray($cookies, 'example.com');
$client = new \GuzzleHttp\Client(['cookies' => $cookieJar]);
$response = $client->request('GET', $url);
@egulhan
egulhan / check-if-contain-domain-name.php
Last active January 22, 2023 01:33
Validate domain name or check if a string contains a domain name using PHP
<?php
/**
* Checks if string contains a domain name
* @param $string
* @return false|int
*/
function checkIfContainsDomainName($string)
{
$pattern = '/(http[s]?\:\/\/)?(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}/';
@egulhan
egulhan / check-text-contain-any-arabic-characters.php
Created September 20, 2018 11:22
Check if text contains any arabic characters using php
<?php
public static function checkTextContainAnyArabicCharacters($text)
{
return preg_match('/[^\x{0600}-\x{06FF}]/u', $text);
}
?>
@egulhan
egulhan / find-weeks-between-two-dates.php
Created April 25, 2018 09:31
Find weeks between two dates
<?php
/**
* Finds weeks by two dates
* @param $startDate
* @param $endDate
* @return array
*/
public static function findWeeksBetweenTwoDates($startDate, $endDate)
{
@egulhan
egulhan / pull-one-file-with-git.sh
Created April 9, 2018 07:19
How to pull one file from remote with GIT
git checkout dev -- public/images/nav-logo.png
@egulhan
egulhan / generate-random-string.php
Last active January 24, 2018 17:25
Randon string generator by PHP
<?php
/**
* Generates random string
* @param int $length
* @param string $charSet
* @return string
*/
function generateRandomString($length = 10, $charSet = '')
{
@egulhan
egulhan / drop-all-db-tables.txt
Created December 20, 2017 07:13
Drop all MySQL database tables without foreign key checks
### connect mysql with -s and -r parameter to print "DROP TABLE ..." lines without formated
mysql -u -s -r
### run the following sql query to generate "DROP TABLE ..." queries
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')
FROM information_schema.tables
WHERE table_schema = '{DBNAME}';
### disable foreign key check
SET FOREIGN_KEY_CHECKS = 0;