Skip to content

Instantly share code, notes, and snippets.

View vhxs's full-sized avatar
💻
somewhere deep in code

Vikram Saraph vhxs

💻
somewhere deep in code
View GitHub Profile
@vhxs
vhxs / popcnt.c
Created June 14, 2024 01:48
messing with popcnt
#include <stdio.h>
int main(void) {
int input;
scanf("%d", &input);
printf("%s", __builtin_popcount(input));
}
@vhxs
vhxs / Dockerfile
Created June 8, 2024 14:46
Offline tiktoken
FROM python:3.10-slim
WORKDIR /app
COPY poetry.lock /app/poetry.lock
COPY pyproject.toml /app/pyproject.toml
COPY example.py /app/example.py
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc curl gnupg2 wget && \

This writeup outlines a solution for Locking Mechanism and also my thought process in solving it. This was my first time doing a CTF and my very first solve ever.

We're given a Dockerized Rust application, but I decided to build the code directly on my machine since I already had Cargo installed and up to date. I'm not that well-versed in Rust yet (I solved a few Advent of Code problems in it), but I know enough to poke around. The first thing I tried was to just cargo build and cargo run the application and see what happens. It didn't halt, so upon looking at the code it looked like it was expecting an input of comma-separated integers.

In the file I noticed that there was a list of 104 integers, particularly this:

#include <Arduino.h>
struct BCD {
int eights;
int fours;
int twos;
int ones;
};
struct BCD decimal_to_BCD(int value) {
@vhxs
vhxs / mst.py
Created December 26, 2023 01:07
Testing edge order is all that matters to make MSTs
import random
import networkx as nx
def random_graph() -> nx.Graph:
num_nodes = 20
probability = 0.2
return nx.erdos_renyi_graph(num_nodes, probability)
@vhxs
vhxs / t5_translate.py
Created September 12, 2023 01:03
T5 translation example
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("t5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")
example_input = "This sentence is false"
input_ids = tokenizer("translate English to German: "+example_input, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
@vhxs
vhxs / bluesky_post.py
Created September 10, 2023 18:08
Minimal example of using Bluesky's API to post
import requests
import os
from datetime import datetime, timezone
# Fetch the current time
# Using a trailing "Z" is preferred over the "+00:00" format
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
# Required fields that each post must include
post = {
@vhxs
vhxs / fine_tune_resnet18_on_dogs_and_cats.py
Created August 13, 2023 23:17
ChatGPT-suggested fine-tuning example
import os
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.models as models
import torchvision.transforms as transforms
import torchvision.datasets as datasets
# Load pre-trained ResNet-18
model = models.resnet18(pretrained=True)
@vhxs
vhxs / move_triangles.py
Created August 12, 2023 19:12
ChatGPT-generated code to animate a coupla triangles
import pygame
# Initialize Pygame
pygame.init()
# Set up display
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame Glide Transformation Animation")
@vhxs
vhxs / langchain_arxiv.py
Created August 12, 2023 17:35
Using LangChain to ask about one of my papers.
from langchain.document_loaders import OnlinePDFLoader
from langchain.indexes import VectorstoreIndexCreator
loader = OnlinePDFLoader("https://arxiv.org/pdf/1606.06353.pdf")
documents = loader.load()
index = VectorstoreIndexCreator().from_documents(documents)
print(index.query("What are the main results of this paper?"))