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 / ffmpeg_scripts.sh
Last active April 23, 2023 10:59
ffmpeg useful scripts
# Convert video to gif
ffmpeg -i input.mp4 -filter_complex "[0]fps=10" output.gif
ffmpeg -ss 00:00:00.000 -i newtab.mov -pix_fmt rgb24 -r 10 output.gif
convert -verbose -dither none -matte -depth 8 -deconstruct -layers optimizePlus -colors 32 output.gif optimized.gif
# Convert mkv to mp4
ffmpeg -i input.mkv -codec copy output.mp4
@rogeriochaves
rogeriochaves / links.md
Last active July 14, 2022 01:55
Pt-BR Data Science Links Scrapping
@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" $@
}
@rogeriochaves
rogeriochaves / nfc_vcard.ino
Created November 6, 2014 12:44
Using Arduino Elechouse's NFC to create vCard
#if 0
#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);
#else
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 });