Skip to content

Instantly share code, notes, and snippets.

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)
@lgmoneda
lgmoneda / README.md
Last active June 26, 2019 23:12
Minimalistic firefox: browse without address and bookmarks toolbar

One of the things I like the most about my Firefox config is this tricky to hide bars and maximize content. Putting together the sources [1] [2] [3]:

  • Go to ~/.mozilla/firefox/<profile> on Linux, ~/Library/Application Support/Firefox/Profiles/<profile folder> or ~/Library/Mozilla/Firefox/Profiles/<profile folder> on OSX, %appdata%\Mozilla\Firefox\Profiles\<profile folder> on Windows
  • Create directory chrome if it doesn't exist
  • Create file userChrome.css inside if it doesn't exist.
  • Add this text to the file:
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
def build_submission(preds,
score,
score_name="auc",
file_title="sub",
sample_sub_file="../data/sample_submission.csv",
submissions_path="../submissions/"):
timestamp = int(time())
submission = pd.read_csv(sample_sub_file)
submission[TARGET] = preds
@lgmoneda
lgmoneda / variance.py
Created June 25, 2017 03:28
Variance with Neural Network
import numpy as np
import random
import pandas as pd
import keras
from keras.models import Sequential
from keras.layers import Dense
from sklearn.cross_validation import train_test_split
def gen_variance_dataset(n_elements, n_features):
n_rows = int(n_elements / n_features)