Skip to content

Instantly share code, notes, and snippets.

View chrischoy's full-sized avatar

Chris Choy chrischoy

View GitHub Profile
@chrischoy
chrischoy / openai_completion.zsh
Created March 17, 2023 12:02
OpenAI API call from command line
# OpenAI call
export OPENAI_API_TOKEN=<YOUR_API_KEY from https://platform.openai.com/account/api-keys>
function openai-completion() {
# echo "\nCompleting $LBUFFER ..."
# echo '{ "model": "text-davinci-003", "prompt": "'$LBUFFER'", "max_tokens": 15, "temperature": 0.7 }\n\n'
local response=$(curl --progress-bar https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_TOKEN" \
-d '{ "model": "text-davinci-003", "prompt": "'$LBUFFER'", "max_tokens": 100, "temperature": 0.7 }')
import os
import time
import argparse
import numpy as np
from urllib.request import urlretrieve
try:
import open3d as o3d
except ImportError:
raise ImportError("Please install open3d with `pip install open3d`.")
# Copyright (c) Chris Choy (chrischoy@ai.stanford.edu).
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@chrischoy
chrischoy / task.cpp
Created March 2, 2019 04:52
task.cpp
#include <cmath>
#include <functional>
#include <future>
#include <iostream>
#include <thread>
// unique function to avoid disambiguating the std::pow overload set
int f(int x, int y) { return std::pow(x, y); }
class Functor {
@chrischoy
chrischoy / activate
Last active February 5, 2018 05:01
Python 3 virtual env setup
#!/bin/sh
ENVNAME=$1
# Directory that contains the venvs
PYV_ROOT=${HOME}
ENV_ROOT="${PYV_ROOT}/.pyv/${ENVNAME}/bin"
# Check the number of arguments
if [ "$#" -eq 1 ] && [ -d "${ENV_ROOT}" ]; then
@chrischoy
chrischoy / conn_servers.sh
Created January 2, 2018 23:50
Connect to all servers and restore tmux session
#!/bin/bash
tmux start-server
tmux new-session -d -s napoli -n monitor
SERVERS=(napoli101 napoli102 napoli103 napoli104 napoli105 napoli106 napoli107 napoli108 napoli109 napoli110 napoli111 napoli112 visionlab-dgx1)
# ${#array[@]} is the number of elements in the array
for ((i = 0; i < ${#SERVERS[@]}; ++i)); do
tabnum=$(( $i + 1 ))
tmux new-window -t napoli:$tabnum
@chrischoy
chrischoy / binvox_rw.py
Last active February 26, 2023 16:08
ShapeNet Voxelization
# Copyright (C) 2012 Daniel Maturana
# This file is part of binvox-rw-py.
#
# binvox-rw-py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# binvox-rw-py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@chrischoy
chrischoy / markdown_tips.md
Last active August 13, 2023 21:09
Markdown Tips

Rendering latex Eqs in Markdown

  • Github doesn't allow javascript in a markdown file. Try to compile equations using readme2tex presents an elegant solution for rendering latex equations.

  • grip runs a simple http server to visualize a readme file on a browser. It also tracks changes in a readme file and refresh the page whenever there is a change. However, you need to embed the following script so that the Mathjax renders eqs.

    <script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="javascript:MathJax.Hub.Queue(['Typeset', MathJax.Hub]);">
import torch
from torch.autograd import Variable, Function
class MultiplyAdd(Function):
@staticmethod
def forward(ctx, input1, scalar, input2):
ctx.scalar = scalar
ctx.test = {'test': 3}
return input1 + scalar * input2
@chrischoy
chrischoy / README.md
Last active May 10, 2017 05:30
Log all experiments in a manifest file automatically and update

No more manual logging

The template run.ch provides a wrapper for running and managing experiments. The file will

  • Log all stdout/stderr into a log file in a respective folder
  • Maintail the log of all experiments with the details in manifest.md file.
  • Update the experiments if you kill the job prematurely

Usage