Skip to content

Instantly share code, notes, and snippets.

View fysherman's full-sized avatar
🍒
cherry

Duy Khanh Bui fysherman

🍒
cherry
  • Viet Nam
View GitHub Profile
@fysherman
fysherman / overflow-hidden-with-animation.css
Created October 26, 2021 15:14
Safari: Apply overflow hidden on parent element when its child is running animation
.parent {
overflow: hidden;
backface-visibility: hidden;
transform: translate3d(0, 0, 0);
}
.child {
/* Has animation */
}
// Check if device is mobile
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
}
// Check if device is touchable
function isTouchDevice() {
return 'ontouchstart' in document.documentElement;
}
@fysherman
fysherman / is-function.js
Created October 26, 2021 15:19
Check if data is a function
function isFunction(obj) {
return obj && {}.toString.call(obj) === '[object Function]';
}
@fysherman
fysherman / gg-signin-button.js
Created October 26, 2021 15:23
Google signin button
// Function handle data response from sigin in action, use jwt to decode data
function handleCredentialResponse(response) {
const responseDecode = jwt_decode(response.credential);
}
function initGGAuth() {
google.accounts.id.initialize({
client_id: CLIENT_ID,
callback: handleCredentialResponse
});
google.accounts.id.renderButton(
function loginFb() {
if (!window.FB) return;
let fbToken = null;
function loginMethod(response) {
if (response.authResponse) {
if (response.authResponse.accessToken) {
fbToken = response.authResponse.accessToken;
const res = await $axios.$get(`https://graph.facebook.com/${response.authResponse.userID}?fields=id,first_name,last_name,email,picture,location&access_token=${fbToken}`);
let orientation = 'portrait';
if(window?.screen?.orientation?.angle && [270, 90].includes(window.screen.orientation.angle)) {
orientation = 'landscape';
} else if(window.orientation && [90, -90].includes(window.orientation)) {
orientation = 'landscape';
}
@fysherman
fysherman / vi-to-en.js
Created October 27, 2021 02:13
Convert Vietnamese string to English
function convertViToEn(str) {
str = str.toLowerCase();
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
str = str.replace(/đ/g, "d");
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ""); // Huyền sắc hỏi ngã nặng
@fysherman
fysherman / nuxt-scss-global-variable.js
Created October 28, 2021 04:00
Use scss global variable in Nuxt js
{
buildModules: [
'@nuxtjs/style-resources'
],
styleResources: {
scss: [
'./assets/scss/_responsive.scss', // use underscore "_" & also file extension ".scss"
'./assets/scss/_variables.scss' // use underscore "_" & also file extension ".scss"
]
}
@fysherman
fysherman / index.html
Created October 31, 2021 11:14
Safe area from iphone's notch
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
@fysherman
fysherman / download-file.js
Created November 15, 2021 06:54
Convert data to file and download in browser
//data: file data
// fileName: file's name to download
// typeFile: type file download. eg: text/html
function downloadFile(data, fileName, typeFile) {
const aEl = document.createElement('a')
const file = new Blob([data], { type: typeFile})
aEl.href = URL.createObjectURL(file)
aEl.download = fileName
aEl.click()