Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
🥫

Leo tlkahn

🥫
View GitHub Profile
@tlkahn
tlkahn / a.md
Created January 30, 2025 04:08
line breaks in minibuffer of emacs

In Emacs, the minibuffer is typically used for single-line input, so pressing RET (Enter) usually submits the input. However, if you need to input a line break (newline) in the minibuffer, you can do so by using the following methods: Method 1: Use C-q C-j

Press C-q (quoted-insert), followed by C-j (newline).

This inserts a literal newline character into the minibuffer.

Method 2: Use C-o

Press C-o (open-line), which inserts a newline and moves the cursor to the new line.

@tlkahn
tlkahn / a.md
Last active January 30, 2025 01:57
reward model equation

The reward model equation represents the negative log-likelihood loss for training the reward model $r_{\phi}$:

  1. $r_{\phi}(x, y)$ is the reward model with parameters $\phi$.

  2. $(x, y_w, y_l)$ is a tuple from the dataset $\mathcal{D}$, where:

    • $x$ is the input
    • $y_w$ is the preferred output
    • $y_l$ is the less preferred output
  3. $\sigma(z) = \frac{1}{1+e^{-z}}$ is the logistic function.

@tlkahn
tlkahn / gist:b721e20b525bfb1c5971266bda3a81b8
Last active January 30, 2025 01:11
some deep RL papers
@tlkahn
tlkahn / a.md
Created January 29, 2025 21:45
RLHF prototype
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F

# Mock dataset
def create_mock_dataset(vocab_size, seq_len, num_pairs):
    preferred = torch.randint(0, vocab_size, (num_pairs, seq_len))
    non_preferred = torch.randint(0, vocab_size, (num_pairs, seq_len))
@tlkahn
tlkahn / a.md
Created January 28, 2025 05:54
Hook up Skim.app with emacs

I want to use Applescript to write Skim plugins to call emacsclient to write annotations to a pdf doc, mimicking the behavior of Highlights.app on mac.

Below is a sketch of how you might integrate Skim, AppleScript, and Emacs (via emacsclient) to mimic the idea of “annotate in an external editor,” similar to how Highlights.app can hand off text to another program.

────────────────────────────────────────────────────────────────────────────

  1. Overview of the Pieces ──────────────────────────────────────────────────────────────────────────── • Skim supports AppleScript (not traditional “plugins” but AppleScript scripts that can be triggered from the Skim menu or via keyboard shortcut).
    • You can use emacsclient to open or evaluate Elisp forms in a running Emacs session, letting you record PDF annotations in an Org file or do something custom. • Skim’s AppleScript dictionary allows you to get selected text, page numbers, note content, etc. from the current document.
@tlkahn
tlkahn / a.md
Created January 28, 2025 02:20
skimpdf link creation

Below is a working example of how to create (1) a simple AppleScript application that registers a custom URL scheme, and (2) links that open a given PDF at a given page in Skim.

────────────────────────────────────────────────────────

  1. Create the AppleScript ────────────────────────────────────────────────────────
  2. Open “Script Editor” (in /Applications/Utilities).
  3. Create a new document and paste this script:

-- This handler is called when a URL with the scheme "skimpdf://" is opened.

@tlkahn
tlkahn / main.py
Created January 18, 2025 02:08
CMU-advanced-nlp-schedule.py
from icalendar import Calendar, Event
from datetime import datetime, timedelta
cal = Calendar()
cal.add("prodid", "-//My Calendar//mxm.dk//")
cal.add("version", "2.0")
classes = [
(
1,
import random
def quirky_text_converter(text):
"""
Convert normal text to a quirky, alternating case with intermittent capitalization.
Parameters:
text (str): The text to convert.
Returns:
@tlkahn
tlkahn / diamond_depencies.py
Created October 18, 2024 05:55
I really enjoyed this kinda of design. Look nowhere else. Code is the flow.
import random
from typing import List, Tuple
import ell
@ell.simple(model="gpt-4o-mini", temperature=1.0)
def random_number() -> str:
"""You are silly robot. Only respond with a number."""
return "Come with up with a random number"
@tlkahn
tlkahn / main.py
Last active October 15, 2024 03:05
from typing import List, Tuple
class Polynomial:
def __init__(self, neg: List[float], pos: List[float]):
"""
Initialize the polynomial.
- neg: Coefficients for negative exponents, ordered from x^{-1}, x^{-2}, ...
- pos: Coefficients for non-negative exponents, ordered from x^{0}, x^{1}, ...
"""
self.neg = neg.copy() # e.g., [a1, a2, ...] for a1*x^{-1} + a2*x^{-2} + ...