Skip to content

Instantly share code, notes, and snippets.

View thinhbuzz's full-sized avatar
🏠
Working from home

Thinh Buzz thinhbuzz

🏠
Working from home
View GitHub Profile
@thinhbuzz
thinhbuzz / teleport.js
Last active June 19, 2021 09:48
moonani click to teleport
document.body.addEventListener('click', event => {
if (!event.target.matches('button[data-clipboard-text]')) {
return;
}
event.preventDefault();
const href = event.target.getAttribute('data-clipboard-text');
const location = href.split(',');
console.log(location);
fetch('http://localhost:4444/adb', {
@thinhbuzz
thinhbuzz / nginx.conf
Last active May 17, 2021 09:47
nginx config for react application
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/html;
@thinhbuzz
thinhbuzz / Dockerfile
Created May 17, 2021 03:02
build docker image for react application
FROM node:14-alpine3.10 AS builder
WORKDIR /usr/src/app
ARG API_ENDPOINT=http://localhost:3333/api
ENV REACT_APP_API_ENDPOINT=$API_ENDPOINT
COPY package*.json ./
RUN npm ci
COPY . .
@thinhbuzz
thinhbuzz / image-optimizer.js
Created June 20, 2020 05:21
Optimize image before upload
export const IMAGE_OPTIMIZER_OPTIONS = {
MAX_WIDTH: 1920,
MAX_HEIGHT: 1080,
MAX_QUALITY: 0.8
};
export function optimizeImageFile(file, {MAX_WIDTH, MAX_HEIGHT, MAX_QUALITY} = IMAGE_OPTIMIZER_OPTIONS) {
return new Promise(resolve => {
const img = document.createElement('img');
@thinhbuzz
thinhbuzz / extra-webpack.config.js
Created June 15, 2020 17:53
Completely customize angular build files hashing.
module.exports = function (config) {
const buzz = `${Date.now()}.buzz`; //change the value to what do you want
if (config.output.filename) {
const splicedOut = config.output.filename.split('.');
config.output.filename = `${splicedOut.slice(0, -1).join('.')}.${buzz}.${splicedOut.slice(-1).join('.')}`;
}
if (config.output.chunkFilename) {
const splicedOut = config.output.chunkFilename.split('.');
config.output.chunkFilename = `${splicedOut.slice(0, -1).join('.')}.${buzz}.${splicedOut.slice(-1).join('.')}`;
}
@thinhbuzz
thinhbuzz / app.component.ts
Last active December 3, 2019 16:16
Angular loading indicator example. Put loader.css file into `src/assets` folder.
import { Component } from '@angular/core';
import { LoaderService } from './loader.service';
import { timer } from 'rxjs';
@Component({
selector: 'app-root',
template: `
<p>
<button (click)="randomTimeout()">Random time out</button>
</p>
@thinhbuzz
thinhbuzz / luxon.date-adapter.ts
Created April 8, 2019 20:53
mattlewis92 Angular calendar luxon date adapter
import { DateAdapter } from 'angular-calendar';
import { DateTime, DateTimeOptions } from 'luxon';
export function getLuxonObject(value: Date | string | number, options?: DateTimeOptions & { format?: string }): DateTime {
if (value instanceof DateTime) {
return value;
}
let dateTime: DateTime;
if (value instanceof Date) {
dateTime = DateTime.fromJSDate(value, options);
@thinhbuzz
thinhbuzz / facebook message downloader.js
Created December 10, 2018 16:12
Download facebook messages by js
(async function (globalOptions) {
let batch = 1;
window['finalResult'] = {
user_id: '',
requestToken: '',
messages: [],
friend: {id: globalOptions.friend_id || 0, name: ''}
};
if (!finalResult.friend.id) {
@thinhbuzz
thinhbuzz / kebabCase.js
Created November 28, 2018 04:36
javascript kebab case convert
function kebabCase(str) {
return str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase()) // lower case and add -
.replace(/[^\w]/g, '-') // replace non-word characters by -
.replace(/-+/g, '-') // remove multiple - characters
.replace(/^-|-$/g, ''); // trim first and last - character
}
@thinhbuzz
thinhbuzz / postMessage.js
Last active November 12, 2018 12:47
postMessage
window.addEventListener("message", function (event) {
console.log(event);
}, false);
console.log(123;