Skip to content

Instantly share code, notes, and snippets.

View akmandev's full-sized avatar
🐧
Focusing

Ozan Akman akmandev

🐧
Focusing
View GitHub Profile
[
{"US":"United States"},
{"CA":"Canada"},
{"AF":"Afghanistan"},
{"AL":"Albania"},
{"DZ":"Algeria"},
{"DS":"American Samoa"},
{"AD":"Andorra"},
{"AO":"Angola"},
{"AI":"Anguilla"},
@akmandev
akmandev / urlValidationWithRegex.php
Last active December 23, 2016 12:34
Perfect URL Validation with Regex
<?php
// Regex Pattern By Diego Perini (https://gist.github.com/dperini/729294)
$url = 'http://github.com';
if(!preg_match('_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS',$url){
echo $url. ' is NOT a valid URL';
}else{
echo $url. ' is a valid URL';
<?php
$userIP = $_SERVER['REMOTE_ADDR'];
//$userIP = '78.179.207.153';
$ipToGeo = file_get_contents('http://www.telize.com/geoip/'. $userIP);
$ipToGeo = json_decode($ipToGeo);
$userCountry = $ipToGeo->country;
?>
<!doctype html>
<?php
namespace App\Helpers;
abstract class RecursiveCategories
{
public static function getChildren($items, $parent = 0)
{
$element = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parent) {
@akmandev
akmandev / Laravel51_FileArrayValidation_Snippet.php
Last active February 6, 2023 04:10
Laravel 5.1 - File Array Validation + Custom Error Messages for Array Data
<?php
$rules = [
'name' => 'required',
'email' => 'required|email',
//etc..
];
foreach($request->file('files') as $index => $file) {
$rules['files.' . $index] = 'mimes:jpeg,gif,png,pdf';
@akmandev
akmandev / .htaccess
Created May 25, 2016 13:42
Force User to HTTPS Link
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
<?php
namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
<?php
public function authenticated(Request $request, $user){
if(!$user->authority){
return redirect('/admin');
}else{
return redirect('/');
}
}
.element{
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}