Skip to content

Instantly share code, notes, and snippets.

View afrijaldz's full-sized avatar
:octocat:
Focusing

Afrijal Dzuhri afrijaldz

:octocat:
Focusing
View GitHub Profile
@afrijaldz
afrijaldz / country-phone-number-code.json
Last active June 7, 2023 08:32
country phone code number
[
{
"countryName": "Afghanistan",
"phoneCode": 93,
"countryCode": "AF / AFG"
},
{
"countryName": "Albania",
"phoneCode": 355,
"countryCode": "AL / ALB"
@afrijaldz
afrijaldz / email-regex.txt
Created February 28, 2023 06:14
regex for email
/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
@afrijaldz
afrijaldz / img.js
Created November 22, 2022 08:41
change image url to base64 or file
***Here is the code for converting "image source" (url) to "Base64".***
let url = 'https://cdn.shopify.com/s/files/1/0234/8017/2591/products/young-man-in-bright-fashion_925x_f7029e2b-80f0-4a40-a87b-834b9a283c39.jpg'
const toDataURL = url => fetch(url)
.then(response => response.blob())
.then(blob => new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(blob)
export const capitalizeFirstChar = (char) => {
const result = char
.split(" ")
.map((c) => {
const first =
c.slice(0, 1) === "x" ? c.slice(0, 1) : c.slice(0, 1).toUpperCase();
const leas = c.slice(1);
return `${first}${leas}`;
})
@afrijaldz
afrijaldz / filter_array_from_array.js
Created September 29, 2021 07:52
filter array from array if value matched
const filtered = [1, 2, 3, 4].filter(
function(e) {
return this.indexOf(e) < 0;
},
[2, 4]
);
console.log(filtered); // [1,3]
@afrijaldz
afrijaldz / angka_dengan_tanda_titik.js
Last active February 18, 2021 07:22
mengubah angka (number) menjadi string dengan penghubung separator ribuan
function numberWithDots(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
@afrijaldz
afrijaldz / difference_date.js
Created February 4, 2021 08:27
get difference days from two days
const date1 = new Date('12/31/2020');
const date2 = new Date();
const difference = date1.getTime() - date2.getTime();
const days = Math.abs(Math.ceil(difference / (1000 * 3600 * 24)));
console.log(days + ' days to go to new year!');
@afrijaldz
afrijaldz / arrayoflength.js
Created January 28, 2021 11:52
membuat array berisi index sebanyak panjang array
// contoh ada array hewan = ["ayam", "bebek", "lele"]
// ingin membuat array yang isinya index dari berapa panjang array hewan
// cara 1
Array.from(Array(hewan.length).keys())
//=> [0, 1, 2]
// cara 2
[...Array(hewan.length).keys()]
//=> [0, 1, 2]
@afrijaldz
afrijaldz / chunks.js
Created October 8, 2020 03:59
create chunk of array with same size
const colors = ['red', 'blue', 'yellow', 'purple', 'green', 'grey', 'brown', 'white', 'black']
function chunkArray(myArray, chunk_size) {
let index = 0
let arrayLength = myArray.length
let tempArray = []
for (index = 0; index < arrayLength; index += chunk_size) {
let myChunk = myArray.slice(index, index + chunk_size)
tempArray.push(myChunk)
@afrijaldz
afrijaldz / youtubeID.js
Created August 4, 2020 03:45 — forked from takien/youtubeID.js
Get YouTube ID from various YouTube URL using JavaScript
/**
* Get YouTube ID from various YouTube URL
* @author: takien
* @url: http://takien.com
* For PHP YouTube parser, go here http://takien.com/864
*/
function YouTubeGetID(url){
var ID = '';
url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);