Skip to content

Instantly share code, notes, and snippets.

@aliyeysides
aliyeysides / git-worktree.md
Created October 18, 2023 17:26
Git Worktree cheatsheet

Setup git bare repo

git clone --bare <repo_url> <local_repo_name>

git config remote.origin.fetch 'refs/heads/*:refs/heads/*' 

git fetch

List worktrees

@aliyeysides
aliyeysides / docker-compose.yml
Last active September 3, 2023 16:42
create local postgres database with docker compose file
# run `docker-compose up -d` to start
# verify with `docker ps` or `lsof -i :5432`
services:
db:
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
image: postgres:latest
ports:
@aliyeysides
aliyeysides / create-xlsx-file.py
Last active September 3, 2023 16:42
create spreadsheet with python
# python 3.10.3
from xlsxwriter import Workbook
def create_xlsx_file(file_path: str, headers: dict, items: list):
with Workbook(file_path) as workbook:
worksheet = workbook.add_worksheet()
worksheet.write_row(row=0, col=0, data=headers.values())
header_keys = list(headers.keys())
for index, item in enumerate(items):
row = map(lambda field_id: item.get(field_id, ''), header_keys)
@aliyeysides
aliyeysides / open-ai-content-filter.rb
Last active May 10, 2022 16:51
OpenAI Ruby content filter
require 'ruby/openai'
CLIENT = OpenAI::Client.new
def content_filter(prompt)
toxic_threshold = -0.355 # make sure required threshold hasn't changed https://beta.openai.com/docs/engines/content-filter
wrapped_prompt = "<|endoftext>#{prompt}\n--\nLabel:"
response = CLIENT.completions(engine: 'content-filter-alpha',
parameters: { prompt: wrapped_prompt,
temperature: 0, max_tokens: 1, top_p: 0, logprobs: 10 }).parsed_response
@aliyeysides
aliyeysides / open-ai-content-filter.js
Last active April 29, 2022 23:21
OpenAI JS content filter
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function contentFilter(prompt) {
const toxic_threshold = -0.355; // make sure required threshold hasn't changed https://beta.openai.com/docs/engines/content-filter
@aliyeysides
aliyeysides / rxjs-switchMap-combineLatest-specimen.ts
Last active January 5, 2024 06:47
example use of .switchMap that streams value to multiple inner observables using static .combineLatest method
this.symbolSearchService.getSymbolData('xl')
.switchMap(stock => {
this.stock = stock;
return Observable.combineLatest(
this.symbolSearchService.getResearchReportData(stock),
this.symbolSearchService.getPGRDataAndContextSummary(stock)
)})
.subscribe(
[report, summary] => {
this.researchReport = report;