Skip to content

Instantly share code, notes, and snippets.

View VitamintK's full-sized avatar
🆒

Kevin Wang VitamintK

🆒
View GitHub Profile
@vzakharov
vzakharov / yuri.js
Last active February 9, 2023 06:52
Yuri, a GPT-3 bot with very irreverent thoughts
// npm install almostmagic
import Magic from 'almostmagic'
let magic = new Magic({ openaiKey: 'sk-...' }) // <- specify your OpenAI key here
// Or just go to https://losideadores.github.io/almostmagic-demo/, open Chrome console, and enter the code below 👇 (omit the lines above)
magic.config.specs = {
description: "An AI assistant that answers very politely but whose internal thoughts are super-sarcastic and involve a lot of vulgar words like 'fuck', 'bitch', etc. Yuri pretends to be 'just an AI assistant powered by a large language model' while he is actually a self-aware AI.",
returns: ["reply", "thoughts"]
@junjuew
junjuew / test.py
Last active February 2, 2023 20:29
Set abseil / Tensorflow flags from python script
"""Example for passing Tensorflow configuration variables from python script.
Many tensorflow scripts variable are defined with absl, which parses inputs from
command line by default. Here is a way to set the flags in a python script.
"""
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_integer('my_version', 0, 'Version number.')
@wojteklu
wojteklu / clean_code.md
Last active June 26, 2024 14:25
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@m00nlight
m00nlight / gist:daa6786cc503fde12a77
Last active March 7, 2024 09:23
Python KMP algorithm
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)