Skip to content

Instantly share code, notes, and snippets.

View marifuli's full-sized avatar
🏠
Working from home

Md Ariful Islam marifuli

🏠
Working from home
View GitHub Profile
@marifuli
marifuli / adblock-checker.js
Last active July 2, 2022 12:42
JS Adblock checker
/*
After loading this js,Do Smething like this:
if(typeof blockAdBlock === 'undefined') {
adBlockDetected();
} else {
blockAdBlock.onDetected(adBlockDetected);
blockAdBlock.onNotDetected(adBlockNotDetected);
// and|or
blockAdBlock.on(true, adBlockDetected);
blockAdBlock.on(false, adBlockNotDetected);
@marifuli
marifuli / sort.alpha.key.php
Created June 2, 2022 06:41
PHP array sort by key - Alphatically
$data = [
'India'=>73,
'United States'=>74,
'United Kingdom'=> 75,
'Singapore'=>77,
'Australia'=>87,
'Canada'=>102
];
uksort($data, function($a, $b) {
return strcmp($a, $b);
@marifuli
marifuli / countries.php
Created May 28, 2022 10:47
Country list in php array
<?php
$countries = array(
"AF" => array( 'alpha2'=>'AF', 'alpha3'=>'AFG', 'num'=>'004', 'isd'=> '93', "name" => "Afghanistan", "continent" => "Asia", ),
"AX" => array( 'alpha2'=>'AX', 'alpha3'=>'ALA', 'num'=>'248', 'isd'=> '358', "name" => "Åland Islands", "continent" => "Europe"),
"AL" => array( 'alpha2'=>'AL', 'alpha3'=>'ALB', 'num'=>'008', 'isd'=> '355', "name" => "Albania", "continent" => "Europe"),
"DZ" => array( 'alpha2'=>'DZ', 'alpha3'=>'DZA', 'num'=>'012', 'isd'=> '213', "name" => "Algeria", "continent" => "Africa"),
"AS" => array( 'alpha2'=>'AS', 'alpha3'=>'ASM', 'num'=>'016', 'isd'=> '1684', "name" => "American Samoa", "continent" => "Oceania"),
"AD" => array( 'alpha2'=>'AD', 'alpha3'=>'AND', 'num'=>'020', 'isd'=> '376', "name" => "Andorra", "continent" => "Europe"),
"AO" => array( 'alpha2'=>'AO', 'alpha3'=>'AGO', 'num'=>'024', 'isd'=> '244', "name" => "Angola", "continent" => "Africa"),
"AI" => array( 'alpha2'=>'AI', 'alpha3'=>'AIA',
@marifuli
marifuli / Save file in Laravel
Created April 2, 2022 16:58
Save file in Laravel
$file = $req->file('picture');
$old = public_path($user->getAttributes()['picture']);
if(
$old &&
is_file($old)
)
{
unlink($old);
}
$name = $user->id .'-picture.' . $file->getClientOriginalExtension();
Route::any('/dynamic/route/{class}/{method}', function ($class, $method) {
$class = "\App\Http\Controllers\\" . str_replace('-', "/", $class);
// return $class;
$con = new $class();
return $con->$method();
})->name('dynamic.route');
global.route2 = (classAndMethodName, params = {}) => {
let array = classAndMethodName.split('@')
params.class = array[0].replace(/\\/g, '-')
function generate_slug($modelClass, $modelColumnName, $title)
{
$slug = \Illuminate\Support\Str::slug($title);
$slugCount = count( $modelClass::whereRaw($modelColumnName . " REGEXP '^{$slug}(-[0-9]*)?$'")->get() );
return ($slugCount > 0) ? "{$slug}-{$slugCount}" : $slug;
}
// Route
Route::any('/dynamic/route/{class}/{method}', function ($class, $method) {
$class = "\App\Http\Controllers\\" . str_replace('-', "/", $class);
$con = new $class();
return $con->$method();
})->name('dynamic.route');
// JS
global.route2 = (classAndMethodName, params = {}) => {
let array = classAndMethodName.split('@')
let data = new FormData();
data.append('file', file, file.name);
axios.post(
URL,
data,
{
headers: {
'accept': 'application/json',
'Accept-Language': 'en-US,en;q=0.8',
@marifuli
marifuli / Axios-Laravel-Validate-response.js
Last active April 2, 2022 16:31
JSON object loop of Laravel error response
if(data && data.response && data.response.data && data.response.data.errors)
{
for (const error in data.response.data.errors)
{
data.response.data.errors[error].forEach(err2 => {
createToast(err2, {type: 'danger'})
})
}
}else
if(data && data.response && data.response.data && data.response.data.message)
@marifuli
marifuli / Vue3LaravelPagination.vue
Created December 29, 2021 03:46
Vue3 and Laravel Pagination Component
/*
<pagination
:current="files.current_page"
:total="files.total"
:per-page="files.per_page"
@page-changed="get_results"
/>
*/
<template>
<div class="text-center">