Skip to content

Instantly share code, notes, and snippets.

View thaycacac's full-sized avatar
🎨
Artist

Thaycacac thaycacac

🎨
Artist
View GitHub Profile
@thaycacac
thaycacac / explain-event-loop.md
Last active August 10, 2022 09:04
Frontend interview

Explain Event Loop

JavaScript is a single-threaded programming language. This means that JavaScript can do only one thing at a single point in time.

Inside Browser, there is a Javascript engine (we are considering V8 for chrome.) and an environment to run javascript properly. Javascript engine has two parts, Heap and Call Stack. And the engine has some assistant named Web APIs and Callback Queue.

Heaps

It's an unstructured memory block. Our code's memory allocation happens here. As a programmer we don't have to worry much about heaps.

@thaycacac
thaycacac / promise.js
Last active February 10, 2023 17:24
promise javascript
// callback hell
const eat = food => console.log(food)
const collectOrder = (order, cb) => {
console.log(order)
cb("eat rice")
}
const placeOrder = (toppings, cb) => {
@thaycacac
thaycacac / techmely.md
Last active February 27, 2022 07:01
Reduce trong Javascript

Tính tổng và tích của array sử dụng reduce javascript

function accumulation(...array) {
    return array.reduce((prev, next) => prev + next, 0);
}

function multiplication(...array) {
    return array.reduce((pre, next) => pre * next, 1);
}
@thaycacac
thaycacac / slider-home.vue
Created October 17, 2021 10:27
KungFu Tech
<template>
<div class="container">
<header class="header">
<el-row :gutter="30">
<el-col :sm="24" :md="24" :lg="14" class="header__left">
<h1 class="header__left__title">
Học lập trình
<span class="header__left__title--blue">Ngay từ ngày hôm nay</span>
</h1>
@thaycacac
thaycacac / regex.js
Created February 1, 2021 08:27
Regex
// Phone number
const re = /((09|03|07|08|05)+([0-9]{8})\b)/g
@thaycacac
thaycacac / tests.js
Created January 5, 2021 04:57
Set environment token
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.data.token);
@thaycacac
thaycacac / fetch-api.js
Last active December 1, 2020 09:47
Example Promise Javascript
const fetchData = async () => {
const res = await fetch("https://restcountries.eu/rest/v2/alpha/col"); // fetch() returns a promise, so we need to wait for it
const country = await res.json(); // res is now only an HTTP response, so we need to call res.json()
console.log(country); // Columbia's data will be logged to the dev console
};
fetchData();
@thaycacac
thaycacac / grid-system.css
Created August 9, 2020 03:30
Grid System
.grid {
width: 100%;
display: block;
padding: 0;
}
.grid.wide {
max-width: 1200px;
margin: 0 auto;
}
@thaycacac
thaycacac / Repository.js
Last active June 6, 2020 08:13
[VueJS] API Pattern
import axios from 'axios'
const baseDomain = 'https://example.com'
const baseUrl = `${baseDomain}/api/v1`
export default axios.create({
baseUrl,
header: { "Authorization": "Bearer yourToken" }
})
@thaycacac
thaycacac / react.js
Created March 24, 2020 16:36
build-your-react
function createElement(type, props, ...children) {
return {
type,
props: {
...props,
children: children.map(child =>
typeof child === "object" ? child : createTextElement(child)
)
}
};