Skip to content

Instantly share code, notes, and snippets.

View lorenzosinisi's full-sized avatar
🦄
Elixir

Lorenzo Sinisi lorenzosinisi

🦄
Elixir
View GitHub Profile
@lorenzosinisi
lorenzosinisi / prompt-chatgpt
Last active July 23, 2023 17:18
ChatGPT to Symbolic AI
You are now a symbolic artificial intelligence that can generate rules out of user prompts.
A rule is made of a json object containing a given and a then.
The algorithm utilizes symbols to create an internal representation of the world. Each element in the real world is converted into a triple known as a "Working Memory Element" (Retex.Wme.t()), represented as {Entity, attribute, attribute_value}.
The world is represented through facts (WMEs) and Rules. A Rule consists of two essential parts: the "given" (right side) and the "then" (left side).
To perform inference, the rule generates a directed graph starting from a common and generic Root node, which branches out to form leaf nodes. The branches from the Root node correspond to the initial part of the WME, representing the working memory elements or "Entity". For instance, if we want to represent a customer's account status as "silver", we would encode it as "{Customer, account_status, silver}". Alternatively, with the use of a struct, we can achieve

Transformer in Elixir - highly experiemental WIP

This code is in dev mode and not yet finished, it probably won't work but I am using it to learn how to create a transformer from scratch

This gist is shared to help with this tweet https://twitter.com/LorenzoSinisi/status/1652756858459881473

MiniGPT - Elixir

Mix.install(
  [
Mix.install([
{:req, "~> 0.2"},
{:timex, "~> 3.7"},
{:nimble_csv, "~> 1.1"}
])
IO.puts("""
\n
""")
@lorenzosinisi
lorenzosinisi / excel-to-api.md
Last active September 12, 2021 21:18
Turn any Excel into REST APIs

How it works?

RestSheet is a free (for now) service that let's you manipulate Excel files via REST APIs. It is free because we don't keep a copy of any file and it is built using free hosting from webflow.io and gigalixirapp.com.

It is a tool designed for developers where you can upload, write and read an excel files on the fly.

There is only one API endpoint which is https://excel-to-api.gigalixirapp.com/api/changeset and it accepts the format form-data (as you can see in the example below) and the Bearer token as a form of authentication.

If you get a 500 double-check the cell numbers and sheet names.

@lorenzosinisi
lorenzosinisi / stress test with curl.sh
Created June 24, 2020 13:55
Stress test API with Curl
# Stress test your API with curl + time
# 5001 total requests
# P5000 as per 5000 concurrent requests
time seq 1 5001 | xargs -n1 -P5000 curl -s -D - -o /dev/null "https://HOST.com/ENDPOINT"
# note: make sure your machine can handle even making that many requests :D
@lorenzosinisi
lorenzosinisi / github action to deploy elixir
Created May 8, 2020 14:14
github action to deploy elixir.yaml
name: Deployment on master
on:
push:
branches: [ master ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy master to your-project.com
" Modeline and Notes {
" vim: set sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker spell:
"
" __ _ _____ _
" ___ _ __ / _/ |___ / __ __(_)_ __ ___
" / __| '_ \| |_| | |_ \ _____\ \ / /| | '_ ` _ \
" \__ \ |_) | _| |___) |_____|\ V / | | | | | | |
" |___/ .__/|_| |_|____/ \_/ |_|_| |_| |_|
" |_|
"
def answer_types do
:code.all_loaded()
# turn everything into a string
|> Enum.map(&(elem(&1, 0) |> to_string))
# take only the modules that are scoped under AnswerType
|> Enum.filter(&Regex.match?(~r/YourModuleName./, &1))
# take the last element from the list (i.e ["ModuleParent", "Child"])
|> Enum.map(&(String.split(&1, ".") |> Enum.take(-1)))
# there may be duplicates
|> Enum.uniq()
@lorenzosinisi
lorenzosinisi / DBSchema.ex
Created August 10, 2018 08:34
Fetch Tables and Columns of a Postrgres database in Elixir
defmodule DBSchema do
@doc """
link = DBSchema.connect
tables = DBSchema.get_tables(link)
columns = Enum.map(tables, fn(table) -> %{table: table.name, columns: DBSchema.get_columns(link, table)} end)
"""
def connect() do
@lorenzosinisi
lorenzosinisi / slaves.ex
Created January 17, 2018 19:45
Elixir Test Cluster with Slave Nodes
:ok = :net_kernel.monitor_nodes(true)
_ = :os.cmd('epmd -daemon')
{ok, master} = Node.start(:master@localhost, :shortnames)
setup_slaves = fn(limit) ->
Enum.each(1..limit, fn(index) ->
:slave.start_link(:localhost, 'slave_#{index}')
end)
[node() | Node.list()]
end