Skip to content

Instantly share code, notes, and snippets.

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

Mr.Buzz thinhbuzz

🏠
Working from home
View GitHub Profile
@thinhbuzz
thinhbuzz / template.js
Last active April 20, 2020 19:44
simple template function
export function isFunction(arg) {
return typeof arg === 'function';
}
const cachedKeys = new Map();
/**
* Get data by key
* const data = {age: {value: 9}};
* getData(data, 'age.value') => 9
* getData(data, 'age.buzz') => 'age.buzz'
*
@thinhbuzz
thinhbuzz / dbschema-license-key-generator.html
Created August 1, 2018 07:51
DbSchema License Key Generator
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>DbSchema License Key Generator</title>
</head>
<body>
@thinhbuzz
thinhbuzz / main.js
Created October 16, 2018 17:03
Node JS gitlab webhook receiver and trigger pipelines
const qs = require('querystring');
const http = require('http');
const https = require('https');
const assert = require('assert');
const config = {
port: 3000,
projectId: '',
pipelineTriggerToken: '',
secretToken: null
@thinhbuzz
thinhbuzz / postMessage.js
Last active November 12, 2018 12:47
postMessage
window.addEventListener("message", function (event) {
console.log(event);
}, false);
console.log(123;
@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 / 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 / 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 / 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 / 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 / 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');