Skip to content

Instantly share code, notes, and snippets.

View alaminfirdows's full-sized avatar
🎯

Al-Amin Firdows alaminfirdows

🎯
View GitHub Profile
Subject: [PATCH] Mastering Collections
---
Index: .tinkerwell/snippets/csv_surgery.php
===================================================================
diff --git a/.tinkerwell/snippets/csv_surgery.php b/.tinkerwell/snippets/csv_surgery.php
new file mode 100644
--- /dev/null (revision b28c56a0c000c8d1e80836cc75b13980ef53310b)
+++ b/.tinkerwell/snippets/csv_surgery.php (revision b28c56a0c000c8d1e80836cc75b13980ef53310b)
@@ -0,0 +1,13 @@
+<?php
@alaminfirdows
alaminfirdows / uses-of-service-class-in-laravel.md
Created May 30, 2024 04:21
uses-of-service-class-in-laravel.md

We can use service classes in laravel -

  • ⁠To Separate Complex Business Logic
  • ⁠Third-Party Service Integration
  • ⁠Improve Code Reusability
  • ⁠Separate Logics for Testing
  • ⁠Data Transformation (Convert Data from One Format to Another)
  • ⁠Service Layer Abstraction

Here are some examples:

import React, { useState } from 'react';
import axios from 'axios';
import classNames from 'classnames';
import { usePage } from '@inertiajs/react';
import { CommentType, PageProps, PostType, User } from '@/types';
import { formatDate } from '@/utils';
import CommentBox from './CommentBox';
type CommentProps = {
@alaminfirdows
alaminfirdows / has-many-deep.md
Last active May 1, 2024 10:45
Laravel Deep Relation Data Fetching

Deep Relations in Laravel: Handling Course-Episode Relationships

In Laravel, you often deal with relationships that span multiple tables. Here's a quick guide to counting related data through deep relations:

Option 1: Using hasManyThrough

When you store a direct reference like course_id in the episodes table, you can establish a deep relation using hasManyThrough. This is perfect for counting through intermediate relationships.

// file: Topic.php
<?php
use App\Services\ScrappingService;
$service = new ScrappingService();
$data = $service->fetchRecursive('https://google.com');
var_dump($data);
@alaminfirdows
alaminfirdows / outbound-email-with-cloudflare.md
Created January 24, 2024 07:20 — forked from irazasyed/outbound-email-with-cloudflare.md
Using Gmail SMTP with Cloudflare Email Routing: A Step-by-Step Guide

Using Gmail SMTP with Cloudflare Email Routing: Step-by-Step Guide

Learn how to send emails through Gmail SMTP with Cloudflare Email Routing in this comprehensive guide.

Step 1: Enable 2-Factor Authentication

To proceed with this method, ensure that you have enabled two-factor authentication for your Google account. If you haven't done so already, you can follow the link to set it up → Enable 2FA in your Google account.

Step 2: Create an App Password for Mail

<?php
$country_list = [
[
"name" => "Afghanistan",
"currency" => "AFN",
"continent" => "AS",
"code" => "AFG",
],
[
export const countriesFlag = [
{
emoji: '🇦🇫',
code: 'AF',
},
{
emoji: '🇦🇽',
code: 'AX',
},
{
@alaminfirdows
alaminfirdows / CopyToClipboard.ts
Created December 30, 2023 08:18
This JavaScript function, copyToClipboard, facilitates easy text copying to the clipboard. It first checks for compatibility with the modern Clipboard API in secure contexts. If supported, it uses the API for asynchronous clipboard writes. In cases where the API is unavailable or the context is not secure, it employs the 'out of viewport hidden …
export const copyToClipboard = async (textToCopy: string) => {
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(textToCopy);
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
// Move textarea out of the viewport so it's not visible
export const copyToClipboard = async (textToCopy) => {
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(textToCopy);
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
// Move textarea out of the viewport so it's not visible