Skip to content

Instantly share code, notes, and snippets.

View TranBaVinhSon's full-sized avatar
🎯
Focusing

Tran B. V. Son TranBaVinhSon

🎯
Focusing
View GitHub Profile
@TranBaVinhSon
TranBaVinhSon / openai_function_calling.ts
Created June 25, 2023 14:50
Experiment of OpenAI Function Calling
import { ChatCompletionRequestMessage, Configuration, OpenAIApi } from "openai";
var prompt = require("prompt-sync")();
require("dotenv").config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function getWeather(location: string, unit = "fahrenheit") {
@TranBaVinhSon
TranBaVinhSon / cheatsheet-elasticsearch.md
Created July 18, 2021 10:44 — forked from ruanbekker/cheatsheet-elasticsearch.md
Elasticsearch Cheatsheet : Example API usage of using Elasticsearch with curl
@TranBaVinhSon
TranBaVinhSon / nginx_deployment.yaml
Created October 27, 2020 23:20 — forked from petitviolet/nginx_deployment.yaml
sample Nginx configuration on Kubernetes using ConfigMap to configure nginx.
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 3;
error_log /var/log/nginx/error.log;
events {
@TranBaVinhSon
TranBaVinhSon / xls2pdf.py
Created November 17, 2019 12:20 — forked from mprihoda/xls2pdf.py
Convert XLS to PDF using Iron Python and MS Office
import clr
import sys
import os.path
clr.AddReference("Microsoft.Office.Interop.Excel")
from Microsoft.Office.Interop import Excel
from System import Type, GC
# See http://msdn.microsoft.com/en-us/library/bb407651.aspx for
@TranBaVinhSon
TranBaVinhSon / semaphore.js
Created November 15, 2019 06:38 — forked from gregkorossy/semaphore.js
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}
@TranBaVinhSon
TranBaVinhSon / CONCURRENCY.md
Created August 26, 2019 03:04 — forked from montanaflynn/CONCURRENCY.md
Examples of sequential, concurrent and parallel requests in node.js

Concurrency in JavaScript

Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.

@TranBaVinhSon
TranBaVinhSon / token.rb
Created July 4, 2019 01:41 — forked from GregBaugues/token.rb
Google API OAuth 2.0 refresh token (Ruby on Rails)
# The OAuth access token provided by the Google API expires in 60 minutes. After expiration,
# you must exchange a refresh token for a new access token. Unfortunately, the the Google API
# ruby gem does not include a method for refreshing access tokens.
# You can read up on how to refresh an access token here:
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
# This Token model implements that process. It's based off of a Token model that can be created
# by running:
# rails g model Token token:text refresh_token:string expires_at:datetime
@TranBaVinhSon
TranBaVinhSon / worker_pool.go
Created June 24, 2019 07:36 — forked from manhdaovan/worker_pool.go
Worker pool in Go
package workerpool
import (
"context"
)
/*
* Worker Pool for executing heavy tasks to avoid OOM error from OS
* Usage example:
* pool := workerpool.NewPool(3) // Number of workers should be adjusted appropriately to your services
@TranBaVinhSon
TranBaVinhSon / importS3Csv.gs
Created May 28, 2019 08:48 — forked from katylava/importS3Csv.gs
Google Apps Script to import a CSV, stored securely on S3, to a Google Spreadsheet
var AWS_KEY = '<your key>';
var AWS_SECRET = '<your secret>';
function generateS3Url(bucket, path) {
var expiresDt = Math.floor(Date.now() / 1000) + (60 * 60 * 24); // can be up to 7 days from now
var stringToSign = 'GET\n\n\n' + expiresDt + '\n/' + bucket + '/' + encodeURIComponent(path);
var hmac = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1, stringToSign, AWS_SECRET, Utilities.Charset.UTF_8);
var signed = encodeURIComponent(Utilities.base64Encode(hmac));
@TranBaVinhSon
TranBaVinhSon / Code.gs
Created May 22, 2019 10:15 — forked from primaryobjects/Code.gs
Export a Google Drive spreadsheet to PDF in Google Drive in the same folder.
// Simple function to add a menu option to the spreadsheet "Export", for saving a PDF of the spreadsheet directly to Google Drive.
// The exported file will be named: SheetName and saved in the same folder as the spreadsheet.
// To change the filename, just set pdfName inside generatePdf() to something else.
// Running this, sends the currently open sheet, as a PDF attachment
function onOpen() {
var submenu = [{name:"Save PDF", functionName:"generatePdf"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu('Export', submenu);
}