Skip to content

Instantly share code, notes, and snippets.

View alaminfirdows's full-sized avatar
🎯

Al-Amin Firdows alaminfirdows

🎯
View GitHub Profile
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
@alaminfirdows
alaminfirdows / ExampleServiceProvider.php
Last active October 19, 2022 05:14
Example Service Provider for WPSmartPay
<?php
namespace Example\Providers;
use SmartPay\Framework\Support\ServiceProvider;
class ExampleServiceProvider extends ServiceProvider
{
public function register()
{
@alaminfirdows
alaminfirdows / code.php
Created September 19, 2022 12:03
Laravel rate limit/attempts by second
<?php
$shouldExecute = RateLimiter::attempt(
'browser_tracker' . geoip()->getClientIP(),
1, // max attempts
function () {
// your code here
},
2 // seconds
);
@alaminfirdows
alaminfirdows / solution.php
Last active September 11, 2022 03:37
LeetCode - 238. Product of Array Except Self
<?php
class Solution {
/**
* @param Integer[] $numbers
* @return Integer[]
*/
function productExceptSelf($numbers) {
$answer = [];
@alaminfirdows
alaminfirdows / nano-id.es6.js
Last active August 29, 2024 05:57
Generate nano ID with length by TS, ES6 or JS
const nanoid = (length = 10) => {
let id = '';
while (id.length < length) {
id += 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'.charAt(Math.floor(Math.random() * 34));
}
return id;
};
@alaminfirdows
alaminfirdows / convert-json-object-to-form-data-es6.js
Last active August 10, 2022 17:03
Convert json object to form data. Available for TS, ES6 Module, and JS
"use strict";
/**
* Convert json object to FormData
*
* @param data
* @param options
* @returns FormData
*/
const jsonObjectToFormaData = (data, formData = new FormData()) => {
convertRecursively(data, formData);
@alaminfirdows
alaminfirdows / bubble.html
Last active August 1, 2022 09:21
Tailwindcss typing bubble animation
<div class="p-10">
<div class="flex items-center space-x-3 text-gray-600 text-sm">
<div class="flex h-full items-center space-x-1">
<div class="h-5 animate-bounce animation-delay-200">
<div class="h-1.5 w-1.5 rounded-full bg-gray-400"></div>
</div>
<div class="h-5 animate-bounce animation-delay-300">
<div class="h-1.5 w-1.5 rounded-full bg-gray-400"></div>
</div>
<div class="h-5 animate-bounce animation-delay-400">
const uuid = function () {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x7) | 0x8).toString(16);
});
return uuid;
};