Skip to content

Instantly share code, notes, and snippets.

@lgmoneda
lgmoneda / discourse_segmentation.py
Last active February 18, 2025 08:52
Segmenting text using the proportion of overlapping documents retrieved from a knowledge base to merge sentences
import json
import urllib.parse
import spacy
import requests
import re
from http.server import BaseHTTPRequestHandler, HTTPServer
from multi_language_utils import is_en_text, translate_to_english, load_language_detection_model
from urllib.parse import parse_qs, urlparse
@lgmoneda
lgmoneda / publishing-jekyll.el
Last active January 21, 2025 11:11
Publishing from org-roam to jekyll blog
;; Blogging
;; The following function helps me to write in a single file in org-roam to produce my personal blog posts.
;; It avoids copying and pasting to the markdown file for jekyll.
(defun lgm/publish-org-roam-to-jekyll-html (github-repo-dir output-dir branch)
"Export current Org Roam file to Jekyll-compatible HTML5 with YAML front matter.
GITHUB-REPO-DIR: Path to your GitHub Pages repository.
OUTPUT-DIR: Directory inside the repository where the HTML file will be placed.
BRANCH: Branch to which changes should be committed (e.g., 'master')."
@lgmoneda
lgmoneda / textual-topography.el
Created January 4, 2025 15:43
Textual Topography
;; Textual topography
(defun textual-topography ()
"Prompt for domain, characteristic/anti-characteristic pair, and selected text.
Save selected text to a file and call a Python script with the arguments."
(interactive)
;; Define the domains and their associated characteristic/anti-characteristic pairs
(setq domain-characteristics
'(("Mood" . (("Happy" . "Unhappy") ("Calm" . "Agitated") ("Optimistic" . "Pessimist")))
("Style" . (("Complex" . "Simple")))
import numpy as np
import pandas as pd
import itertools
import seaborn as sns
import matplotlib.pyplot as plt
import openai
import os
import time
from dotenv import load_dotenv
@lgmoneda
lgmoneda / prompt_templates.py
Last active April 13, 2023 12:01
Prompts for a Q&A with Org roam
from datetime import date
today = date.today()
# Minor modification from langchain library example
PROMPT_PRE = """
My name is Luis Moneda. You are my personal assistant. Given the following extracted parts of long documents from my personal notes and a question, create a final answer with references ("SOURCES").
The content of the document will be preceeded by the title hierarchy it was taken from inside brackets, which you should use to get context about it.
If you don't know the answer, just say that you don't know. Don't try to make up an answer.
ALWAYS return a "SOURCES" part in your answer that only contains numbers. Today is {}.
@lgmoneda
lgmoneda / sentence_transformer_embeddings.py
Created April 10, 2023 23:29
Averaging embeddings of a document with many sentences
import os
import re
import numpy as np
import pandas as pd
import torch
import warnings
from adjustText import adjust_text
from sentence_transformers import SentenceTransformer
from sklearn.manifold import TSNE
@lgmoneda
lgmoneda / org-yank-link.el
Last active April 10, 2023 23:24
Copy Slack behavior of automatically creating link when pasting url with text selected
@lgmoneda
lgmoneda / README.md
Last active May 2, 2020 14:40
Adding Processing colors to rainbow-mode

Adding Processing "color"

Add the rainbow-mode package to your init.el and the proper config to add it to the processing mode and recognize the color:

(use-package rainbow-mode
  :ensure t
  :config
  (add-to-list 'rainbow-html-colors-major-mode-list 'processing-mode)
 (add-to-list 'rainbow-html-rgb-colors-font-lock-keywords
@lgmoneda
lgmoneda / userChrome.css
Created March 1, 2020 12:43
My Firefox CSS
#TabsToolbar > * {
visibility: collapse;
}
#titlebar{ margin-bottom: -22px}
/* hide navigation bar when it is not focused; use Ctrl+L to get focus */
#main-window:not([customizing]) #navigator-toolbox:not(:focus-within):not(:hover) {
margin-top: -105px; /**/
}
@lgmoneda
lgmoneda / named_aggregation.py
Created November 14, 2019 17:19
Using named aggregation in Pandas
import pandas as pd
import numpy as np
data = [[1, 5, 2], [2, 3, 1], [3, 1, 1], [1, 3, 2]]
df = pd.DataFrame(data, columns=["values_1", "values_2", "age"])
agg_columns = ["values_1", "values_2"]
agg_functions = [np.mean, np.std]
agg_dict = {col + "_" + f.__name__: (col, f) for col in agg_columns for f in agg_functions}
agg = df.groupby("age").agg(**agg_dict)