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
/*
Just add this JS code in you HTML however you want. it will check all kinds of AdBlocker with JS
*/
var adBlockEnabled = false;
var testAd = document.createElement('div');
testAd.innerHTML = ' ';
testAd.className = 'adsbox';
document.body.appendChild(testAd);
window.setTimeout(function() {
if (testAd.offsetHeight === 0) {
<?php
/*
* Resize images dynamically using wp built in functions
* @author Victor Teixeira
* @link http://core.trac.wordpress.org/ticket/15311
*
* php 5.2+
*
* Exemple use:
@marifuli
marifuli / pagination.php
Created August 27, 2021 17:32
Raw PHP-MySQL Pagination
<?php
// php >= 7.0
function paginate ($total, $per_page, $curr_page)
{
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$result = [];
$result['html'] = '<div class="pagination">';
$result['offset'] = ($curr_page - 1) < 0 ? 0 : ($curr_page - 1) * $per_page ;
@marifuli
marifuli / image-resizing-in-laravel.php
Last active December 18, 2021 19:56
Helper function for Image resizing in PHP, especially in php
function dynamic_image($url, $width = false, $height = -1, $quality = 80, $compression = 75)
{
$parsed = parse_url($url);
$path = $parsed['path'];
$file_name = basename($path);
$only_path = str_replace($file_name, '', $path);
$public_path = public_path($path);
if(file_exists($public_path))
@marifuli
marifuli / copy-text.js
Last active December 25, 2021 11:54
Copy text to clipboard
const CopyText = function() {
let t;
const e = function(e) {
t || (t = document.createElement("textarea"), document.body.appendChild(t)), t.value = e, t.setAttribute("readonly", "true"), t.setAttribute("type", "text"), t.select(), t.setSelectionRange(0, 9999);
try {
return document.execCommand("copy"), !0
} catch (t) {
return !1
} finally {
t.setAttribute("type", "hidden")
@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">
@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)
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',
// 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('@')
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;
}