Skip to content

Instantly share code, notes, and snippets.

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

Gerardo Fernández Moreno ger86

🏠
Working from home
View GitHub Profile
#!/usr/bin/env python3
from dotenv import load_dotenv
from langchain.chains import RetrievalQA
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.vectorstores import Chroma
from langchain.llms import GPT4All, LlamaCpp
import os
import argparse
@ger86
ger86 / EventDistpacher.ts
Created February 9, 2023 10:09
Fully typed Event Dispatcher for TypeScript
type SquareEvent = { type: "square", x: number, y: number };
type CircleEvent = { type: "circle", radius: number };
type EventType = SquareEvent | CircleEvent;
type Events = {
square: SquareEvent;
circle: CircleEvent;
}
type ListenersMap = {
@ger86
ger86 / eslint-plugin-import.config.js
Last active February 14, 2021 10:31
eslint-plugin-import.config.js
{
"import/order": ['warn', {
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling'],
'alphabetize': {
order: 'asc'
},
"pathGroups": [
{
"pattern": "react",
"group": "builtin",
/************************************************************
*
* 💪🏼💪🏼💪🏼 Javascript Proxy 💪🏼💪🏼💪🏼
*
************************************************************/
// 1️⃣ Performing an action when accesing a property
const person = { name: "Gerardo", email: "gerardo@latteandcode.com" };
const personProxy = new Proxy(person, {
/********************************************************************************
*
* 🗺️🗺️🗺️ Map 🗺️🗺️🗺️
* Performs better in scenarios involving frequent additions and
* removals of key-value pairs.
*
********************************************************************************/
// 1️⃣ Main methods
/****************************************************************
*
* 🍰🍰🍰 Array slice 🍰🍰🍰
*
****************************************************************/
const animals = ['🐶', '🐱', '🐭', '🐻', '🦁'];
// Remove first element
console.log(animals.slice(1));
/****************************************************************
*
* 🤹🏻‍♂️🤹🏻‍♂️🤹🏻‍♂️ Object & Entries 🤹🏻‍♂️🤹🏻‍♂️🤹🏻‍♂️
*
****************************************************************/
/**
* 1️⃣ Object.entries
*/
/**************************************************************************
*
* 🐖🐂🐄🐓 George Orwell explaining Javascript Prototype 🐖🐂🐄🐓
*
**************************************************************************/
function Animal(name, type) {
this.name = name;
this.type = type;
}
/************************************************
*
* 📩📩📩 window.postMessage() 📩📩📩
*
* The window.postMessage() method safely enables cross-origin communication
* between Window objects; e.g., between a page and a pop-up that it spawned,
* or between a page and an iframe embedded within it.
*
************************************************/
@ger86
ger86 / variable-hoisting.js
Created February 5, 2020 11:07
Variable hoisting in Javascript
/******************************************************************************************************
*
* 🆙🆙🆙🆙 Variable hoisting 🆙🆙🆙🆙
*
* Característica del lenguaje que de forma automática la declaración de las variables
* a la parte superior del bloque funcional / global
*
*******************************************************************************************************/
console.log(user); // "undefined" pero no da error