Skip to content

Instantly share code, notes, and snippets.

@martenc
martenc / numpy_pro_tips.py
Created April 7, 2025 06:11
Numpy Pro Tips
# NumPy Pro Tips: Data Analysis & EDA Techniques
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# ======================================================================
# 1. STATISTICAL FUNCTIONS & AGGREGATION
# ======================================================================
@martenc
martenc / pandas_pro_tips.py
Created April 7, 2025 05:42
Pandas Power Tips
# Pandas Power Tips: Essential Techniques for Data Manipulation
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# ======================================================================
# 1. DATA TYPE CONVERSION & HANDLING
# ======================================================================
@martenc
martenc / mulitmodal-rag-visualize-pdf.py
Last active March 20, 2025 15:12
visualize the embeddings with UMAP for dimensionality reduction
from langchain_core.embeddings import Embeddings
import matplotlib.pyplot as plt
import pandas as pd
from typing import Dict, List, Tuple
import numpy as np
import plotly.express as px
from sklearn.manifold import Isomap
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
import umap.umap_ as umap
@martenc
martenc / extract-from-paper
Created March 20, 2025 14:28
multi-modal RAG - high_res chunking strategy
from pathlib import Path
from langchain.docstore.document import Document
from unstructured.partition.pdf import partition_pdf
from unstructured.documents.elements import Text, Image, Table, CompositeElement
class ExtractionPipeline:
def __init__(self, folder_path):
self.folder_path = folder_path
self.pdf_filenames = self.get_pdf_filenames_from_folder()
@martenc
martenc / grpo_demo.py
Created February 3, 2025 00:00 — forked from willccbb/grpo_demo.py
GRPO Llama-1B
# train_grpo.py
import re
import torch
from datasets import load_dataset, Dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig
from trl import GRPOConfig, GRPOTrainer
# Load and prep dataset
@martenc
martenc / ipfs-img-url.js
Created May 4, 2024 14:32
Parse IPFS json to get img url
/*
input to parse:
{"image":"ipfs://QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/de22e8bd5787802d7417009f647bb33b","name":"2 kilobytes low cost Token Eric #137"}
output:
https://cf-ipfs.com/ipfs/QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/72315d4fbdc4e2d96ea6777b67b5f8a8
*/
function convertIpfsUrl(ipfsUrl: string): string {
const cid = ipfsUrl.replace("ipfs://", "");
@martenc
martenc / kafka_to_fabric.js
Created March 14, 2023 20:56
This example listens for messages from the specified Kafka topic and submits a transaction to the Hyperledger Fabric network with the received message as an argument.
const { Kafka } = require('kafka-node');
const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');
const fs = require('fs');
// Load the connection profile
const ccpPath = path.resolve(__dirname, '..', 'your_connection_profile.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);
@martenc
martenc / .dockerignore
Created September 1, 2021 15:00 — forked from remarkablemark/.dockerignore
Docker Node.js Example
node_modules/
*.log
@martenc
martenc / pubsub.pubnub.js
Created August 31, 2021 14:04
PubNub class example
const PubNub = require('pubnub');
const credentials = {
publishKey: 'pub-c-...',
subscribeKey: 'sub-c-...',
secretKey: 'sec-c-...'
};
const CHANNELS = {
TEST: 'TEST',
/*
JavaScript: Higher Order Functions
Part 2, JavaScript Map Method by Example
YouTube Video: http://uzr.co/javascript-map-method
JSFiddle: https://jsfiddle.net/joeyburzynski/j2bewfe9/
Gist: https://gist.github.com/JoeyBurzynski/91e0ea5f480f5f6bfbcca5df832225b7