Skip to content

Instantly share code, notes, and snippets.

@chokychou
chokychou / install.sh
Created May 9, 2024 09:18
Lazy install Bazel (bash install.sh)
sudo apt-get install build-essential autoconf libtool pkg-config
sudo apt-get install clang libc++-dev
sudo apt install apt-transport-https curl gnupg -y
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg
sudo mv bazel-archive-keyring.gpg /usr/share/keyrings
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update && sudo apt install bazel
sudo apt-get install python3-dev
sudo apt update && sudo apt full-upgrade
go install github.com/bazelbuild/buildtools/buildifier@latest
@chokychou
chokychou / BUILD
Created August 2, 2023 06:00
Skeleton codes for using Python grpc with Bazel at runtime. protos_and_services() builds protobuf at runtime, and avoid "module not found" issues when importingwith py_grpc_library().
load("@pip//:requirements.bzl", "requirement")
py_binary(
name = "server",
srcs = [":server.py"],
data = ["server.proto"],
deps = [
requirement('grpcio'),
],
)
@chokychou
chokychou / Subfolder to git repo.md
Created July 17, 2023 01:32 — forked from cruftlord/Subfolder to git repo.md
Convert subfolder into Git submodule
@chokychou
chokychou / firebase-messaging-sw.js
Last active July 17, 2023 01:33
Sample snippets for firebase messaging notification in Nextjs.
// This file goes to: public/firebase-messaging-sw.js
// Reference: https://stackoverflow.com/a/69207889/13091479
// Scripts for firebase and firebase messaging
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js");
// Initialize the Firebase app in the service worker by passing the generated config
const firebaseConfig = {
apiKey: "YOURDATA",
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)