Skip to content

Instantly share code, notes, and snippets.

@ahallora
ahallora / decimalStringToCento.ts
Created March 24, 2024 12:08
Decimal string to cento number
export const decimalStringToCento = (decimalString: string): number => {
// Replace comma with dot to make it a valid float
const cleanedString = decimalString.replace(",", ".");
// Parse the string as a floating-point number
const floatValue = parseFloat(cleanedString);
// Multiply by 100 to get the cento number
const centoNumber = Math.round(floatValue * 100);
@ahallora
ahallora / ABTest.tsx
Last active March 27, 2024 08:06
Basic React ABTesting Component - POC
import React, { ReactNode, useState } from "react";
type Experiment = {
exposure: number;
render: ({ success }: { success: any }) => any;
name?: string;
};
enum TestEvent {
"VIEW" = "View",
@ahallora
ahallora / gemini.js
Created December 18, 2024 07:56
Using Gemini AI With Typescript / Node.js / Next.js etc. (POC)
import { GoogleGenerativeAI, SchemaType } from "@google/generative-ai";
const GEMINI_API_KEY = ""; // process.env.GEMINI_API_KEY
export const gemini = {
createEmbedding: async (content: string) => {
const genAI = new GoogleGenerativeAI(GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "text-embedding-004" });
try {