Skip to content

Instantly share code, notes, and snippets.

View tientp-floware's full-sized avatar
🎯
Focusing

Tiến Trần tientp-floware

🎯
Focusing
View GitHub Profile
@tientp-floware
tientp-floware / title.doc.html
Created December 22, 2022 10:30
Title google document
<html><head></head><body>
<script>
var YOUR_CLIENT_ID = 'REPLACE_THIS_VALUE';
var YOUR_REDIRECT_URI = 'REPLACE_THIS_VALUE';
var fragmentString = location.hash.substring(1);
// Parse query string to see if page request is coming from OAuth 2.0 server.
var params = {};
var regex = /([^&=]+)=([^&]*)/g, m;
while (m = regex.exec(fragmentString)) {
@tientp-floware
tientp-floware / crypto.js
Created April 12, 2021 09:24
New update nodejs above v10
import crypto = require('crypto');
export class CryptoAES {
private algorithm = 'aes-256-cbc';
private key: string;
private IV_LENGTH: number = 16;
private iv: Buffer; // random bytes
/**
* @example crytpo = new CryptoAES(<string 16,32 bits>) {Class object}
@tientp-floware
tientp-floware / model.dto.js
Created March 30, 2021 03:34
Nestjs validator array of object
import { IsString, IsNumber, IsArray, ValidateNested, ArrayMinSize, ArrayMaxSize } from 'class-validator';
import { Type } from 'class-transformer';
export class SMa1 {
@IsNumber()
id: number;
@IsString()
type: string;
@tientp-floware
tientp-floware / mongodb-in-file.go
Last active October 14, 2020 03:22
Upload large file into Mongodb
package main
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path"
@tientp-floware
tientp-floware / refresh_session.js
Last active October 6, 2020 03:14
Auto refresh token in session on google api
function refreshSession() {
if (!gapi.auth2.getAuthInstance().currentUser.get().isSignedIn()) {
return;
}
var authResponse = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse();
if (authResponse.expires_at - Date.now() < 60000) {
gapi.auth2.getAuthInstance().currentUser.get().reloadAuthResponse()
.then(() => {
setTimeout(refreshSession, 5000); // 5s
})
@tientp-floware
tientp-floware / get-started.html
Created October 5, 2020 10:06
Get start gmail api
<!--
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
<?php
/**
* This class is for generating a string in microformat (vCard or hCard) with supplied data.
* It currently only supports vCard format version 3.0.
*
* Available parameters (description in parentheses) and suggested format (default value in parentheses):
* - 'strict' (true = enforce strict vCard format, false = try your best) => false
* - 'acceptedPhoneNumberTypes' => 'work', 'home', 'mobile'
* - 'acceptedAddressTypes' => 'work', 'home'
*
@tientp-floware
tientp-floware / mail-attachment.go
Last active March 5, 2020 08:47
Email attachment and got body.
package main
import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"github.com/emersion/go-imap"
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)