Skip to content

Instantly share code, notes, and snippets.

View vzakharov's full-sized avatar
🗯️
Words are a motherfucker

Vova Zakharov vzakharov

🗯️
Words are a motherfucker
View GitHub Profile
@vzakharov
vzakharov / relative_import_converter.py
Last active September 2, 2023 11:37
Python Relative Import Converter
# Relative Import Converter
#
# This Python script is used to convert absolute imports to relative imports in a Python project.
# It recursively traverses through all the Python files in the specified directory and its subdirectories.
# For each Python file, it identifies all the import statements and modifies them from absolute to relative.
# The script only converts imports from the current directory or its descendants, it does not handle
# imports from parent directories or unrelated directories (i.e., it doesn't do the `from ....../something` conversions).
# This is particularly useful when you want to make your Python modules/packages portable or when you are
# restructuring your project and need to update the import paths.
#
@vzakharov
vzakharov / create_index.sh
Last active August 11, 2023 23:37
Create index.ts recursively for your TypeScript project
#!/bin/bash
######
# This script creates an "index.ts" file in the directory provided as its argument.
# It then goes through all .ts files and directories in this directory,
# and adds them as "export * from './[filename without .ts or directory name]'" to the "index.ts" file.
# If it encounters a subdirectory, it runs itself in that subdirectory, thus starting a recursion.
# This script is useful when working with TypeScript projects where you want to create a single entry point
// Syncs two folders together. If a file is added, updated, or deleted in the original folder, it will be added, updated, or deleted in the duplicate folder. Uses fs.watch() to watch for changes in the original folder, so make sure your OS supports it.
const fs = require('fs');
const path = require('path');
const originalFolder = process.argv[2];
const duplicateFolder = process.argv[3];
if (!originalFolder || !duplicateFolder) {
console.error('Usage: node sync.js <original_folder> <duplicate_folder>');
@vzakharov
vzakharov / logger.ts
Created March 9, 2023 10:25
Log in the moment
// The purpose of this util is to only prominently log the piece of code we're currently working on.
// This is done by keeping track of a "last log index" in a separate project file (json). Whenever we want to log something new, we first check the last log index and then create a new logging function with a higher index (the util automatically updates the json).
// So the common interface is to do:
// ```
// import { logger } from '~/utils/logger';
// const log = logger(1);
// // or logger(2), logger(3), etc. or logger('always') if we want to always log
// // or logger(1, 'green') if we want to log in green by default
// log('Hello world!');
// // or log.green('Hello world!'), where log modifiers are taken from the `ansi-colors` package
@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"]