Skip to content

Instantly share code, notes, and snippets.

@rogeriochaves
rogeriochaves / main.py
Created July 10, 2023 05:34
MULTI_PROMPT_ROUTER_TEMPLATE improved
"""You help triaging user requests. Given a raw text input, output either DOCS or DEFAULT, according to those definitions:
DOCS: if user is asking a seemingly technical question, programming questions or company-specific questions
DEFAULT: if user is just chit-chatting or basic knowledge questions
====================
Input: hello there
Output: DEFAULT
@rogeriochaves
rogeriochaves / main_fp.py
Last active June 17, 2023 13:58
monadic langchain, a more FP interface to langchain
# This is how langchain chain composition looks with a more FP approach
import re
from typing import (
Literal,
TypedDict,
cast,
)
from dotenv import load_dotenv
@rogeriochaves
rogeriochaves / goodbye_postman.sh
Last active June 29, 2022 12:42
Shortcut to post json with curl from terminal
# Usage:
# post '{"name": "Mr Foo"}' https://myapi/register
#
post () {
local json="$1";
local url="$2";
shift 2;
curl -X POST -H "Content-Type: application/json" --data "$json" "$url" $@
}
const { merge, interval, from, Observable, Subject, zip } = Rx;
const { delay, partition, tap, take, bufferTime, bufferWhen, map, bufferCount, mergeMap, concatAll, windowCount, buffer, mergeAll, filter } = RxOperators;
const topic$ = new Subject();
const retryTopics = [1,2,3,4,5,6,7,8,9,10].map(i =>
delay(1000 * 2 ** i)(new Subject())
);
let i = 0;
setInterval(() => {
@rogeriochaves
rogeriochaves / parser.rb
Created April 13, 2021 21:11
Parse ruby .inspect string to be eval'd
def deinspect(str, level=0)
str.gsub!(/:0x0[^ ]+/, '')
matches = str.match(/<([\w:]+) (.*)>/)
return str unless matches
head = matches[1]
body = matches[2]
hash_content = nil
const thiagoWay = (lista) => {
let ar = lista.map((el) => el.name);
let array_elements = ar.sort();
let current = null;
let cnt = 0;
for (var i = 0; i < array_elements.length; i++) {
delete lista[i].id;
if (array_elements[i] != current) {
@rogeriochaves
rogeriochaves / fetchingState.js
Last active December 15, 2020 18:14
Javascript Fetching State without Booleans
const NOT_ASKED = 'NOT_ASKED';
const LOADING = 'LOADING';
const SUCCESS = 'SUCCESS';
const ERROR = 'ERROR';
export const notAsked = () => ({ state: NOT_ASKED });
export const loading = () => ({ state: LOADING });
export const success = result => ({ state: SUCCESS, result });
export const error = message => ({ state: ERROR, message });
.ghx-controls-filters, .ghx-qty, .ghx-issue-fields .ghx-key, .ghx-card-footer .ghx-type, .ghx-card-footer .ghx-flags, .ghx-card-footer .ghx-end, .ghx-card-footer .ghx-days, #announcement-banner {
display: none!important;
}
#ghx-pool-column {
padding: 0 20px;
}
.ghx-issue .ghx-highlighted-fields .ghx-highlighted-field {
max-width: none;
function trackClick(name) {
if (!name) throw "track needs a name";
ga.track(name);
}
def calculate_character_probability(character, questions_so_far, answers_so_far):
# Prior
P_character = 1 / len(characters)
# Likelihood
P_answers_given_character = 1
P_answers_given_not_character = 1
for question, answer in zip(questions_so_far, answers_so_far):
P_answers_given_character *= max(
1 - abs(answer - character_answer(character, question)), 0.01)