Skip to content

Instantly share code, notes, and snippets.

View stevenhao's full-sized avatar

Steven Hao stevenhao

View GitHub Profile
@stevenhao
stevenhao / modal_llama2.py
Created July 18, 2023 20:30
modal script that creates llama2_image and defines a function that can run inference on it
from modal import Image, Stub, Secret, gpu
from pathlib import Path
import os
MODEL_PATH = "/model"
def download_models():
from transformers import AutoTokenizer, AutoModelForCausalLM
token = os.environ["HUGGINGFACE_TOKEN"]
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", use_auth_token=token)
@stevenhao
stevenhao / stevenkplus_stream_1_9_21.md
Last active January 11, 2021 01:23
Stevenkplus Stream Notes 1/9/21

Stevenkplus Stream 1/9/21

Education Codeforces Round 101

Goal: Place in top 50

Problem-solving strategy:

  • Plan out implementation ahead of time
  • Try to write all the code in one sitting; any details need to be scoped out ahead of time

A: Regular Bracket Sequence

Plan for the stream

  • Do a division 2 virtual contest
  • Monitor Chat & respond to any messages
  • For Each Problem:
    • Solve it
    • Write solution notes
    • Write implementation notes
    • Set a timer & see how fast I can write the code after having planned out the implementation
A:
Insights
- Every 7 rounds, you do 6 + 3 = 9 damage total (6 rounds of 1 damage each, 7th round you do 3 damage)
- So total number of rounds = Total health divided by 9, must be an integer
- If k = TotalHealth/9, all monsters (a, b, c) must have at least k health
- Check that this is true: a >= k && b >= k && c >= k
Just check these conditions, print YES if true, NO otherwise
[dp]: [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 3, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 4, 3, 3, 4, 2, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 5, 6, 5, 9, 5, 10, 5, 9, 4, 7, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 6, 10, 9, 16, 13, 19, 17, 19,
#include <iostream>
#include <map>
#include <vector>
#include <set>
using namespace std;
typedef pair<int, int> pii;
const int MOD = 998244353;
typedef long long ll;
const int MAXN = 1001000;
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""
import sys
from http.server import HTTPServer, SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
#include <bits/stdc++.h>
using namespace std;
int m, a, b;
typedef long long ll;
int cnt = 0;
ll ans = 0;
int mx = 0;
@stevenhao
stevenhao / script.js
Last active April 5, 2019 01:35
slack channel groups
// ==UserScript==
// @name Slack Channel Grouping
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://scaleapi.slack.com/*
// @grant none
// ==/UserScript==
@stevenhao
stevenhao / Require Lodash
Created December 25, 2018 04:47
Imports lodash (and any other npm package) via tampermonkey & requirify.
// ==UserScript==
// @name Require Lodash
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Asynchronously inject lodash into all webpages
// @author Steven Hao
// @match *://*/*
// @grant none
// ==/UserScript==