Skip to content

Instantly share code, notes, and snippets.

View btnguyen2k's full-sized avatar

Thanh Ba Nguyen btnguyen2k

View GitHub Profile
@btnguyen2k
btnguyen2k / Program.cs
Created November 14, 2024 13:25
[C#] Chuyển số thập nhân sang cơ số 32 - http://goclaptrinh.io/cms/beginner/csharp-crockford-base32-numbers/
using System;
class GocLapTrinh
{
static int NhapSoThapPhan()
{
Console.Write("Nhap so thap phan: ");
return int.Parse(Console.ReadLine() ?? string.Empty);
}
@btnguyen2k
btnguyen2k / GocLapTrinh.java
Created November 12, 2024 14:06
[Java] Chuyển số thập nhân sang cơ số 32 - http://goclaptrinh.io/cms/beginner/java-crockford-base32-numbers/
import java.util.Scanner;
public class GocLapTrinh {
static int nhapSoThapPhan(Scanner scanner) {
System.out.print("Nhập số thập phân: ");
return scanner.nextInt();
}
static String nhapSoBase32(Scanner scanner) {
System.out.print("Nhập số ở hệ cơ số 32 (bảng mã Crockford Base32): ");
@btnguyen2k
btnguyen2k / main.c
Created November 12, 2024 05:52
[C] Chuyển số thập nhân sang cơ số 32 - http://goclaptrinh.io/cms/beginner/c-cpp-crockford-base32-numbers/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int nhapSoThapPhan() {
int n;
printf("Nhập số thập phân: ");
scanf("%d", &n);
return n;
@btnguyen2k
btnguyen2k / main.cpp
Created November 12, 2024 05:52
[C++] Chuyển số thập nhân sang cơ số 32 - http://goclaptrinh.io/cms/beginner/c-cpp-crockford-base32-numbers/
#include <iostream>
int nhapSoThapPhan() {
int n;
std::cout << "Nhập số thập phân: ";
std::cin >> n;
return n;
}
std::string nhapSoBase32() {
@btnguyen2k
btnguyen2k / OpenAINormalizeAndEmbeddings.go
Created May 15, 2023 04:54
Normalize input text for embeddings or not?
package main
import (
"fmt"
"os"
"regexp"
"strings"
"github.com/btnguyen2k/oaiaux"
)
@btnguyen2k
btnguyen2k / CountOpenAITokens.go
Created May 11, 2023 13:49
Count OpenAI tokens in different encodings
package main
import (
"fmt"
"github.com/btnguyen2k/oaiaux"
)
func CountTokens(text, lang, encoding string) {
numTokens := oaiaux.CountTokens(text, oaiaux.Option{Key: "encoding", Value: encoding})
@btnguyen2k
btnguyen2k / oai_esttokens.go
Created May 3, 2023 08:40
Estimate the number of tokens for an OpenAI prompt.
// EstimateTokens estimates the number of tokes for an input string.
func EstimateTokens(input string) int {
const re1 = `[^\w\d]+`
const re2 = `[\w\d]+`
reWords := regexp.MustCompile(re1)
words := reWords.Split(input, -1)
numWords := 0
for _, w := range words {
if w != "" {
numBytes := len([]byte(w))
@btnguyen2k
btnguyen2k / aks_change_system_reserved_resources.yaml
Last active July 9, 2020 12:27
(#AKSHack change AKS reserved memory)
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kured
rules:
# Allow kured to read spec.unschedulable
# Allow kubectl to drain/uncordon
#
# NB: These permissions are tightly coupled to the bundled version of kubectl; the ones below
import java.util.*;
/**
* A demo Java application to see how GC works.
*
* @author Thanh Nguyen
*/
public class GcMemDemo {
static Map<Long, byte[]> buffer = new HashMap<>();
#!/bin/bash
echo '=================================================='
echo '===============Install necessary tools==============='
echo '=================================================='
sudo yum update
sudo yum install git make flex bison libtool automake openssl-devel libevent libevent-devel python-devel gcc-c++ byacc java-1.7.0-openjdk ant
echo '=================================================='