Skip to content

Instantly share code, notes, and snippets.

View akshaykarnawat's full-sized avatar

Akshay Karnawat akshaykarnawat

View GitHub Profile
@akshaykarnawat
akshaykarnawat / huggingface_model.py
Created May 14, 2024 22:50
huggingface model load and run
import os
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
# set environment variable HUGGING_FACE_API_KEY=hf_************
HUGGING_FACE_API_KEY = os.environ.get("HUGGING_FACE_API_KEY")
model_id = "microsoft/Phi-3-mini-4k-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id, legacy=False)
model = AutoModelForCausalLM.from_pretrained(
model_id,
@akshaykarnawat
akshaykarnawat / dagster_docker.md
Last active February 28, 2024 19:18
Running dagster inside a docker container

Dagster Installation in Docker

Dagster provides a mechanism to create pipeline DAGs which can be executed in a reproducible way. The DAGs can be visualized and run through a UI.

Details here: https://docs.dagster.io/getting-started

In order to run dagster, we first need to make sure we run python in a docker container.

The following code will create the python env in a docker container and will be removed right after we exit.

@akshaykarnawat
akshaykarnawat / jupyter_notes.txt
Created May 22, 2021 19:25
run jupyter in local docker container
cd ~
mkdir notebooks
docker run --rm -it -p 8888:8888 -v /Users/akshaykarnawat/notebooks:/home/notebook python:3.8-slim-buster /bin/bash
pip install jupyter
cd /home/notebook
jupyter notebook . --ip 0.0.0.0 --no-browser --allow-root
# local on my host go to --> http://127.0.0.1:8888 and enter in the token
@akshaykarnawat
akshaykarnawat / local_s3_notes.txt
Last active May 22, 2021 19:26
test local s3 lke env
Running a local s3 like object storage to practice
- Docker Desktop
- MinIO
- python
- boto3
Install Docker desktop
https://docs.docker.com/desktop/#download-and-install
@akshaykarnawat
akshaykarnawat / eye_care.py
Last active October 4, 2019 04:12
Eye Care 20-20-20 rule
from os import popen, system
from time import sleep
# Note: this requires brightness package to be installed from homebrew
# https://brew.sh
# brew update; brew upgrade; brew install brightness
# #future -- rewite as shell script..no need for py
CURRENT_BRIGHTNESS = 1
@akshaykarnawat
akshaykarnawat / mcc.json
Last active April 24, 2024 20:52
List of Visa MCC (Merchant Category Classification) Codes
[{"MCC":"0742","Merchant Type":"Veterinary Services"},{"MCC":"0763","Merchant Type":"Agricultural Co-operatives"},{"MCC":"0780","Merchant Type":"Horticultural Services"},{"MCC":"0780","Merchant Type":"Landscaping Services"},{"MCC":"1520","Merchant Type":"General Contractors-Residential and Commercial"},{"MCC":"1711","Merchant Type":"Air Conditioning Contractors Sales and Installation"},{"MCC":"1711","Merchant Type":"Heating Contractors Sales, Service, Installation"},{"MCC":"1731","Merchant Type":"Electrical Contractors"},{"MCC":"1740","Merchant Type":"Insulation Contractors"},{"MCC":"1740","Merchant Type":"Masonry, Stonework Contractors"},{"MCC":"1740","Merchant Type":"Plastering Contractors"},{"MCC":"1740","Merchant Type":"Stonework and Masonry Contractors"},{"MCC":"1740","Merchant Type":"Tile Settings Contractors"},{"MCC":"1750","Merchant Type":"Carpentry Contractors"},{"MCC":"1761","Merchant Type":"Roofing-Contractors"},{"MCC":"1761","Merchant Type":"Sheet Metal Work-Contractors"},{"MCC":"1761","Merchant T
@akshaykarnawat
akshaykarnawat / leet_code_problems.py
Created March 22, 2019 03:42
Get LeetCode problems data saved locally for offline access
import requests
import json
import time
import os
LOC_TO_STORE = '/Volumes/ExPac/dev/python/leet_code_problems'
LEET_CODE_URL = 'https://leetcode.com'
LEET_CODE_GRAPHQL_URL = 'https://leetcode.com/graphql'
@akshaykarnawat
akshaykarnawat / dtcc.py
Created February 9, 2019 20:55
Getting SDR data from DTCC public repository
# the structure of the code needs to change and the script needs to be parameterized with func...
# but gets the job done for the data needed
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from datetime import datetime
import pandas as pd
import requests
import zipfile
@akshaykarnawat
akshaykarnawat / comment_block.py
Last active February 2, 2019 16:10
Comment block generator (beta)
def commentGenerator(comment, length=80):
commentList = comment.split(' ')
breakBy = int(len(commentList) / ((len(comment)+len(commentList)) / length))
body = ''.join(['# {0} \n'.format(' '.join(commentList[i: i+breakBy])) for i in range(0, len(commentList), breakBy)])
box = '#+{0}+\n'.format(''.join(['=' for i in range(length-3)]))
return box + body + box
@akshaykarnawat
akshaykarnawat / try_pyquil.py
Created March 14, 2018 05:17
pyQuil lib test
from pyquil.quil import Program
import pyquil.api as api
from pyquil.gates import *
import numpy as np
#open quantum virtual machine and establish connection
qvm = api.QVMConnection()
print("measure 0,0")
p = Program()