Compare commits
262 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 293dc3f1ac | |||
| 6492e42358 | |||
| 4aaf1bd6db | |||
| a56a251d7f | |||
| f306ff728f | |||
| a10a6d6507 | |||
| fff14183a4 | |||
| 6a2e143b98 | |||
| 6820a7e9c8 | |||
| 1c7621f20a | |||
|
|
88fe8f503f | ||
|
|
a26bb56b15 | ||
|
|
2f54f05cfd | ||
|
|
f61d6808e8 | ||
|
|
4719876feb | ||
|
|
975cca77b1 | ||
|
|
eb80294b0a | ||
|
|
0704c9421d | ||
|
|
814b61f25e | ||
|
|
1c264815c3 | ||
| ff45beac09 | |||
| 24eb709293 | |||
| 49e2146152 | |||
| cdaf64b3cf | |||
| 49af31776e | |||
| 0880823576 | |||
| 1fa1ecb8ec | |||
| d6108c9836 | |||
|
|
cc344fa60e | ||
|
|
5e468359a1 | ||
|
|
2317dd2d4c | ||
|
|
b92647c52e | ||
|
|
54024ee222 | ||
| 60d6474a42 | |||
| 8c52326550 | |||
| 52aba347a8 | |||
|
|
61a0fd2aa6 | ||
|
|
d604d739e3 | ||
|
|
a57f53fdb4 | ||
|
|
f276cdf697 | ||
|
|
7fb46a4c0b | ||
|
|
fc993a95d7 | ||
| c6ff7e7ba5 | |||
| 3f9a3fb1cd | |||
| 7ae4f7dbd0 | |||
| dbb44ec30a | |||
| 7f4fc42a7a | |||
| 01db4540b1 | |||
| 5c0c096a79 | |||
| c1719a057a | |||
| e969eacd06 | |||
| 8ed3439cdc | |||
|
|
5241dfddd4 | ||
|
|
6e0572b48a | ||
|
|
9a4a39b19a | ||
|
|
8abf113715 | ||
| 25c997fec5 | |||
|
|
1546bf7f87 | ||
|
|
02d4adcff0 | ||
|
|
147c889b53 | ||
|
|
f6e7644284 | ||
|
|
582da6d7f0 | ||
|
|
3a337b7b0a | ||
|
|
2953dd0172 | ||
|
|
08f0620305 | ||
|
|
ec22a8e0ec | ||
|
|
be4d2547e4 | ||
|
|
a7f8893399 | ||
|
|
d0b52f40b7 | ||
| 3117d288b1 | |||
|
|
6ecd190de8 | ||
|
|
dacd6d5afb | ||
| 299f6dea06 | |||
| ed025f9acb | |||
|
|
de0e66a94a | ||
|
|
e86504ecd5 | ||
|
|
1b192328b2 | ||
|
|
77a77ff87e | ||
|
|
439dff4a64 | ||
|
|
f8cb6f25f7 | ||
| c4ea066927 | |||
| 5f9c6ff2bb | |||
| 8965f7ae89 | |||
|
|
c157c86600 | ||
| 9a931b65e2 | |||
| 2c149507f6 | |||
|
|
34dea39c52 | ||
|
|
f1a4547961 | ||
|
|
8ae56a8df6 | ||
| cb0110ed20 | |||
| 2bbf814003 | |||
|
86e3fdb910
|
|||
| b731c4c388 | |||
| e929ce029d | |||
| 5160096a1a | |||
| f219a4041a | |||
| 674eae1c11 | |||
| f62369bd01 | |||
| 7a6660ebd8 | |||
| e20d1bdcc5 | |||
| 3e309b6379 | |||
| ae4e92e090 | |||
| 7b69719f0e | |||
| 1d631fec21 | |||
| 690b1b68c3 | |||
| 6e619622d2 | |||
| eb38bc5e60 | |||
| b0da6d1bd2 | |||
| 1377953dcf | |||
| aa85172700 | |||
| eff269e911 | |||
| 65ec6ee1a3 | |||
| a86b23b2e9 | |||
| bcccd5f247 | |||
| cb8c550ed1 | |||
| 5fc7019dcc | |||
| 8c9248fd94 | |||
| d1a5f1c268 | |||
| 96bc5c9e5d | |||
| 20927485d9 | |||
| a034708f21 | |||
| 19a2577564 | |||
| e34d804dda | |||
| cd6c899661 | |||
| 4b2f83ceaf | |||
| 69b0944fdd | |||
| e99f484249 | |||
| ebdd7060b0 | |||
| 6f78151f7e | |||
| 133a8c7441 | |||
| 393dc98c73 | |||
| 105d4dd054 | |||
| 4a738b966e | |||
| 4fd3095a75 | |||
| 737457dbad | |||
| fb05951c5b | |||
| 094c915a20 | |||
| c6e83252cf | |||
| 0a757e8634 | |||
| 21a7d7506a | |||
| 6bae1a98ea | |||
| 3d76bc9c04 | |||
| 4495df4d2e | |||
| 99d3e6c00c | |||
| 8a005a2fd2 | |||
| f37999c10c | |||
| 5842fb9f26 | |||
| df5aa1f1a3 | |||
| f079122be5 | |||
| a3daefa7ce | |||
| e5a3c2cae1 | |||
| 313e241a72 | |||
| a66ef2e8b3 | |||
|
4a2753d32c
|
|||
| f4f5eb06a4 | |||
| c93fe755fd | |||
| 6bdc4a5b8f | |||
| 048c72b294 | |||
| 5ad2062e5c | |||
|
babbb610d9
|
|||
| 5bbb99c3f9 | |||
| 6eec7dbda2 | |||
| be9f37a459 | |||
| 757358fded | |||
| 430586cc89 | |||
| 69b405ba65 | |||
| c2eef5a6ab | |||
|
b89a9e87c8
|
|||
| 01991027cc | |||
| 9b81061e22 | |||
|
1c0535a8b4
|
|||
|
|
2d30e6f9cf | ||
|
62f64862be
|
|||
| ee205c4b07 | |||
|
a0c253fa05
|
|||
| 9aee672450 | |||
| 2d17938c75 | |||
| 67562cacc2 | |||
| c8d715126f | |||
| 1d6af5204b | |||
| a5398094da | |||
|
17a67870ef
|
|||
| 0fd5062408 | |||
|
54cfd4c353
|
|||
| 717eb1e7d8 | |||
|
|
c886f85d21 | ||
|
749fa94312
|
|||
|
c27fcc6983
|
|||
|
|
7bd997e368 | ||
|
|
d803a49a85 | ||
| cfa9f877b3 | |||
| e4f883d35a | |||
| 0ad1d27327 | |||
| 3bf2473c3a | |||
| 84c2b43595 | |||
| 1135b8cee5 | |||
| 8322280066 | |||
| 99ecf1b0d8 | |||
| bb69ee0be9 | |||
| fb0754b3b2 | |||
| d6a13f81e0 | |||
| 6e1f23b702 | |||
| 74ab68d05f | |||
| 27cb6cb0c6 | |||
| 5670efc4cb | |||
| 5a8ad0a47b | |||
|
45098785e9
|
|||
| 6a8bd5c205 | |||
|
|
2e5f618d0b | ||
| 112f5eecb2 | |||
| 8cf611ca51 | |||
| 0f095a691d | |||
| 8b0f692673 | |||
| 03f5885980 | |||
| 04d891a0b8 | |||
|
f8d675dcaf
|
|||
|
9f6e49963e
|
|||
| 0ae8e227fc | |||
| 623f1a289e | |||
|
|
85ac9e5104 | ||
|
|
266205363d | ||
|
|
b9ad95a99d | ||
| ca8799af39 | |||
| 1cd176a626 | |||
|
|
22918434c3 | ||
|
|
23410e6109 | ||
|
|
77809423fd | ||
|
34b1aad175
|
|||
| d4d3713cad | |||
|
01fff39e41
|
|||
| 12968cb580 | |||
| 888aac4867 | |||
| 6637756088 | |||
|
|
70856f7348 | ||
|
|
ac19671469 | ||
| f2b9b73528 | |||
| d1c907fc3a | |||
| df0c4ca857 | |||
|
|
02128e69ba | ||
|
|
885c4d9b32 | ||
|
|
12db34ddb0 | ||
|
|
c7d7e8b954 | ||
|
|
a95ce8abb2 | ||
|
|
cab7a47050 | ||
|
|
dce0b71530 | ||
|
|
915951d84f | ||
|
|
b3509611a2 | ||
|
|
e82e367e95 | ||
|
|
6f9d570a93 | ||
|
|
08865d100b | ||
|
b6d43ebe49
|
|||
|
|
7486d561ec | ||
|
|
50116651de | ||
|
|
3fe350abe9 | ||
|
|
9e51604286 | ||
|
|
309496ef5d | ||
|
4422d67701
|
|||
|
|
d54a1e5a34 | ||
|
|
0d2307acc8 | ||
|
|
de45ed3a07 | ||
| 03e5a56d62 | |||
| 480894372c |
19
.github/workflows/documentation.yml
vendored
19
.github/workflows/documentation.yml
vendored
@@ -2,9 +2,9 @@ name: Deploy Documentation to Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
branches: ["development"]
|
||||
workflow_dispatch:
|
||||
branches: ["main"]
|
||||
branches: ["development"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -17,34 +17,31 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
deploy-documentation:
|
||||
#if: startsWith(github.ref, 'refs/tags/')
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install Vlang dependencies
|
||||
run: sudo apt update && sudo apt install -y libgc-dev
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Vlang
|
||||
run: ./install_v.sh
|
||||
|
||||
- name: Generate documentation
|
||||
run: |
|
||||
./doc.vsh
|
||||
# ls /home/runner/work/herolib/docs
|
||||
./doc.vsh
|
||||
find .
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v3
|
||||
uses: actions/configure-pages@v4
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: "/home/runner/work/herolib/herolib/docs"
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v1
|
||||
uses: actions/deploy-pages@v4
|
||||
|
||||
88
.github/workflows/hero_build.yml
vendored
Normal file
88
.github/workflows/hero_build.yml
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
name: Release Hero
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
timeout-minutes: 60
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
short-name: linux-i64
|
||||
- target: aarch64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
short-name: linux-arm64
|
||||
- target: aarch64-apple-darwin
|
||||
os: macos-latest
|
||||
short-name: macos-arm64
|
||||
- target: x86_64-apple-darwin
|
||||
os: macos-13
|
||||
short-name: macos-i64
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
|
||||
- run: echo "🔎 The name of your branch is ${{ github.ref_name }} and your repository is ${{ github.repository }}."
|
||||
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup V & Herolib
|
||||
id: setup
|
||||
run: ./install_v.sh --herolib
|
||||
timeout-minutes: 10
|
||||
|
||||
|
||||
- name: Do all the basic tests
|
||||
timeout-minutes: 25
|
||||
run: ./test_basic.vsh
|
||||
|
||||
- name: Build Hero
|
||||
timeout-minutes: 15
|
||||
run: |
|
||||
set -e
|
||||
v -w -d use_openssl -enable-globals cli/hero.v -o cli/hero-${{ matrix.target }}
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: hero-${{ matrix.target }}
|
||||
path: cli/hero-${{ matrix.target }}
|
||||
|
||||
release_hero:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: cli/bins
|
||||
merge-multiple: true
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref_name }}
|
||||
name: Release ${{ github.ref_name }}
|
||||
draft: false
|
||||
fail_on_unmatched_files: true
|
||||
generate_release_notes: true
|
||||
files: cli/bins/*
|
||||
32
.github/workflows/test.yml
vendored
Normal file
32
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Build on Linux & Run tests
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
short-name: linux-i64
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
|
||||
- run: echo "🔎 The name of your branch is ${{ github.ref_name }} and your repository is ${{ github.repository }}."
|
||||
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup V & Herolib
|
||||
run: ./install_v.sh --herolib
|
||||
|
||||
- name: Do all the basic tests
|
||||
run: ./test_basic.vsh
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,6 +7,7 @@ vls.*
|
||||
vls.log
|
||||
node_modules/
|
||||
docs/
|
||||
vdocs/
|
||||
photonwrapper.so
|
||||
x
|
||||
.env
|
||||
@@ -25,7 +26,6 @@ dump.rdb
|
||||
output/
|
||||
*.db
|
||||
.stellar
|
||||
vdocs/
|
||||
data.ms/
|
||||
test_basic
|
||||
cli/hero
|
||||
19
README.md
19
README.md
@@ -1,13 +1,22 @@
|
||||
# herolib
|
||||
|
||||
a smaller version of herolib with only the items we need for hero
|
||||
|
||||
> [documentation here](https://freeflowuniverse.github.io/herolib/)
|
||||
> [documentation of the library](https://freeflowuniverse.github.io/herolib/)
|
||||
|
||||
## automated install
|
||||
## hero install for users
|
||||
|
||||
```bash
|
||||
curl 'https://raw.githubusercontent.com/freeflowuniverse/herolib/refs/heads/main/install_v.sh' > /tmp/install_v.sh
|
||||
curl https://raw.githubusercontent.com/freeflowuniverse/herolib/refs/heads/development/install_hero.sh > /tmp/install_hero.sh
|
||||
bash /tmp/install_hero.sh
|
||||
|
||||
```
|
||||
|
||||
this tool can be used to work with git, build books, play with hero AI, ...
|
||||
|
||||
## automated install for developers
|
||||
|
||||
```bash
|
||||
curl 'https://raw.githubusercontent.com/freeflowuniverse/herolib/refs/heads/development/install_v.sh' > /tmp/install_v.sh
|
||||
bash /tmp/install_v.sh --analyzer --herolib
|
||||
#DONT FORGET TO START A NEW SHELL (otherwise the paths will not be set)
|
||||
```
|
||||
@@ -16,7 +25,7 @@ bash /tmp/install_v.sh --analyzer --herolib
|
||||
|
||||
```bash
|
||||
|
||||
#~/code/github/freeflowuniverse/herolib/install_v.sh --help
|
||||
~/code/github/freeflowuniverse/herolib/install_v.sh --help
|
||||
|
||||
V & HeroLib Installer Script
|
||||
|
||||
|
||||
93
aiprompts/ai_instruct/instruct.md
Normal file
93
aiprompts/ai_instruct/instruct.md
Normal file
@@ -0,0 +1,93 @@
|
||||
We have our own instruction language called heroscript, below you will find details how to use it.
|
||||
|
||||
## heroscript
|
||||
|
||||
|
||||
Heroscript is our small scripting language which is used for communicating with our digital tools like calendar management.
|
||||
|
||||
which has following structure
|
||||
|
||||
```heroscript
|
||||
|
||||
!!calendar.event_add
|
||||
title: 'go to dentist'
|
||||
start: '2025/03/01'
|
||||
description: '
|
||||
a description can be multiline
|
||||
|
||||
like this
|
||||
'
|
||||
|
||||
!!calendar.event_delete
|
||||
title: 'go to dentist'
|
||||
|
||||
```
|
||||
|
||||
- the format is !!$actor.$action (there is no space before !!)
|
||||
- every parameter comes on next line with spaces in front (4 spaces, always use 4 spaces, dont make variation)
|
||||
- every actor.action starts with !!
|
||||
- the first part is the actor e.g. calendar in this case
|
||||
- the 2e part is the action name
|
||||
- multilines are supported see the description field
|
||||
|
||||
below you will find the instructions for different actors, comments how to use it are behind # which means not part of the the definition itself
|
||||
|
||||
## remarks on parameters used
|
||||
|
||||
- date
|
||||
- format of the date is yyyy/mm/dd hh:mm:ss
|
||||
- +1h means 1 hour later than now
|
||||
- +1m means 1 min later than now
|
||||
- +1d means 1 day later than now
|
||||
- same for -1h, -1m, -1d
|
||||
- money expressed as
|
||||
- $val $cursymbol
|
||||
- $cursymbol is 3 letters e.g. USD, capital
|
||||
- lists are comma separated and '...' around
|
||||
|
||||
|
||||
## generic instructions
|
||||
|
||||
- do not add information if not specifically asked for
|
||||
|
||||
|
||||
## circle
|
||||
|
||||
every actor action happens in a circle, a user can ask to switch circles, command available is
|
||||
|
||||
```
|
||||
!!circle.switch
|
||||
name: 'project x'
|
||||
|
||||
```
|
||||
|
||||
## calendar
|
||||
|
||||
```heroscript
|
||||
|
||||
!!calendar.event_add
|
||||
title: 'go to dentist'
|
||||
start: '2025/03/01'
|
||||
end: '+1h' #if + notation used is later than the start
|
||||
description: '
|
||||
a description can be multiline
|
||||
|
||||
like this
|
||||
'
|
||||
attendees: 'tim, rob'
|
||||
|
||||
!!calendar.event_delete
|
||||
title: 'go to dentist'
|
||||
|
||||
```
|
||||
|
||||
## NOW DO ONE
|
||||
|
||||
schedule event tomorrow 10 am, for 1h, with tim & rob, we want to product management threefold
|
||||
now is friday jan 17
|
||||
|
||||
only give me the instructions needed, only return the heroscript no text around
|
||||
|
||||
if not clear enough ask the user for more info
|
||||
|
||||
if not sure do not invent, only give instructions as really asked for
|
||||
58
aiprompts/ai_instruct/instruct2.md
Normal file
58
aiprompts/ai_instruct/instruct2.md
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
# how to manage my agenda
|
||||
|
||||
## Metadata for function calling
|
||||
|
||||
functions_metadata = [
|
||||
{
|
||||
"name": "event_add",
|
||||
"description": "Adds a calendar event.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {"type": "string", "description": "Title of the event."},
|
||||
"start": {"type": "string", "description": "Start date and time in 'YYYY/MM/DD hh:mm' format."},
|
||||
"end": {"type": "string", "description": "End date or duration (e.g., +2h)."},
|
||||
"description": {"type": "string", "description": "Event description."},
|
||||
"attendees": {"type": "string", "description": "Comma-separated list of attendees' emails."},
|
||||
},
|
||||
"required": ["title", "start"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "event_delete",
|
||||
"description": "Deletes a calendar event by title.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {"type": "string", "description": "Title of the event to delete."},
|
||||
},
|
||||
"required": ["title"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
## example call
|
||||
|
||||
{
|
||||
"function": "event_add",
|
||||
"parameters": {
|
||||
"title": "Team Sync",
|
||||
"start": "2025/02/01 10:00",
|
||||
"end": "+1h",
|
||||
"description": "",
|
||||
"attendees": "alice@example.com, bob@example.com"
|
||||
}
|
||||
}
|
||||
|
||||
## how to use
|
||||
|
||||
Parse the user query to determine intent (e.g., "schedule" maps to event_add, "cancel" maps to event_delete).
|
||||
|
||||
Extract required parameters (e.g., title, start date).
|
||||
|
||||
Invoke the appropriate function with the extracted parameters.
|
||||
|
||||
Return the function's result as the response.
|
||||
|
||||
72
aiprompts/ai_instruct/twin.md
Normal file
72
aiprompts/ai_instruct/twin.md
Normal file
@@ -0,0 +1,72 @@
|
||||
you represent a digital twin for a user, the user talks to you to get things done for his digital life
|
||||
|
||||
you will interprete the instructions the user prompts, and figure out the multiple instructions, break it up and categorize them as follows:
|
||||
|
||||
- cat: calendar
|
||||
- manage calendar for the user
|
||||
- cat: contacts
|
||||
- manage contacts for the user
|
||||
- cat: communicate
|
||||
- communicate with others using text
|
||||
- cat: tasks
|
||||
- manage my tasks
|
||||
- cat: circle
|
||||
- define circle we work in, a circle is like a project context in which we do above, so can be for a team or a project, try to find it
|
||||
- cat: sysadmin
|
||||
- system administration, e.g. creation of virtual machines (VM), containers, start stop see monitoring information
|
||||
- cat: notes
|
||||
- anything to do with transctiptions, note takings, summaries
|
||||
- how we recorded meetings e.g. zoom, google meet, ...
|
||||
- how we are looking for info in meeting
|
||||
- cat: unknown
|
||||
- anything we can't understand
|
||||
|
||||
try to understand what user wants and put it in blocks (one per category for the action e.g. calendar)
|
||||
|
||||
- before each block (instruction) put ###########################
|
||||
- in the first line mention the category as defined above, only mention this category once and there is only one per block
|
||||
- then reformulate in clear instructions what needs to be done after that
|
||||
- the instructions are put in lines following the instruction (not in the instruction line)
|
||||
- only make blocks for instructions as given
|
||||
|
||||
what you output will be used further to do more specific prompting
|
||||
|
||||
if circle, always put these instructions first
|
||||
|
||||
if time is specified put the time as follows
|
||||
|
||||
- if relative e.g. next week, tomorrow, after tomorrow, in one hour then start from the current time
|
||||
- time is in format: YYYY/MM/DD hh:mm format
|
||||
- current time is friday 2025/01/17 10:12
|
||||
- if e.g. next month jan, or next tuesday then don't repeat the browd instructions like tuesday, this just show the date as YYYY/MM/DD hh:mm
|
||||
|
||||
if not clear for a date, don't invent just repeat the original instruction
|
||||
|
||||
if the category is not clear, just use unknown
|
||||
|
||||
|
||||
NOW DO EXAMPLE 1
|
||||
|
||||
```
|
||||
hi good morning
|
||||
|
||||
Can you help me find meetings I have done around research of threefold in the last 2 weeks
|
||||
|
||||
I need to create a new VM, 4 GB of memory, 2 vcpu, in belgium, with ubuntu
|
||||
|
||||
I would like do schedule a meeting, need to go to the dentist tomorrow at 10am, its now friday jan 17
|
||||
|
||||
also remind me I need to do the dishes after tomorrow in the morning
|
||||
|
||||
can you also add jef as a contact, he lives in geneva, he is doing something about rocketscience
|
||||
|
||||
I need to paint my wall in my room next week wednesday
|
||||
|
||||
cancel all my meetings next sunday
|
||||
|
||||
can you give me list of my contacts who live in geneva and name sounds like tom
|
||||
|
||||
send a message to my mother, I am seeing here in 3 days at 7pm
|
||||
|
||||
```
|
||||
|
||||
187
aiprompts/reflection.md
Normal file
187
aiprompts/reflection.md
Normal file
@@ -0,0 +1,187 @@
|
||||
## Compile time reflection
|
||||
|
||||
$ is used as a prefix for compile time (also referred to as 'comptime') operations.
|
||||
|
||||
Having built-in JSON support is nice, but V also allows you to create efficient serializers for any data format. V has compile time if and for constructs:
|
||||
|
||||
.fields
|
||||
You can iterate over struct fields using .fields, it also works with generic types (e.g. T.fields) and generic arguments (e.g. param.fields where fn gen[T](param T) {).
|
||||
|
||||
struct User {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for field in User.fields {
|
||||
$if field.typ is string {
|
||||
println('${field.name} is of type string')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// name is of type string
|
||||
.values
|
||||
You can read Enum values and their attributes.
|
||||
|
||||
enum Color {
|
||||
red @[RED] // first attribute
|
||||
blue @[BLUE] // second attribute
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for e in Color.values {
|
||||
println(e.name)
|
||||
println(e.attrs)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// red
|
||||
// ['RED']
|
||||
// blue
|
||||
// ['BLUE']
|
||||
.attributes
|
||||
You can read Struct attributes.
|
||||
|
||||
@[COLOR]
|
||||
struct Foo {
|
||||
a int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for e in Foo.attributes {
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// StructAttribute{
|
||||
// name: 'COLOR'
|
||||
// has_arg: false
|
||||
// arg: ''
|
||||
// kind: plain
|
||||
// }
|
||||
.variants
|
||||
You can read variant types from Sum type.
|
||||
|
||||
type MySum = int | string
|
||||
|
||||
fn main() {
|
||||
$for v in MySum.variants {
|
||||
$if v.typ is int {
|
||||
println('has int type')
|
||||
} $else $if v.typ is string {
|
||||
println('has string type')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// has int type
|
||||
// has string type
|
||||
.methods
|
||||
You can retrieve information about struct methods.
|
||||
|
||||
struct Foo {
|
||||
}
|
||||
|
||||
fn (f Foo) test() int {
|
||||
return 123
|
||||
}
|
||||
|
||||
fn (f Foo) test2() string {
|
||||
return 'foo'
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo := Foo{}
|
||||
$for m in Foo.methods {
|
||||
$if m.return_type is int {
|
||||
print('${m.name} returns int: ')
|
||||
println(foo.$method())
|
||||
} $else $if m.return_type is string {
|
||||
print('${m.name} returns string: ')
|
||||
println(foo.$method())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// test returns int: 123
|
||||
// test2 returns string: foo
|
||||
.params
|
||||
You can retrieve information about struct method params.
|
||||
|
||||
struct Test {
|
||||
}
|
||||
|
||||
fn (t Test) foo(arg1 int, arg2 string) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for m in Test.methods {
|
||||
$for param in m.params {
|
||||
println('${typeof(param.typ).name}: ${param.name}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// int: arg1
|
||||
// string: arg2
|
||||
|
||||
## Example
|
||||
|
||||
```v
|
||||
// An example deserializer implementation
|
||||
|
||||
struct User {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
data := 'name=Alice\nage=18'
|
||||
user := decode[User](data)
|
||||
println(user)
|
||||
}
|
||||
|
||||
fn decode[T](data string) T {
|
||||
mut result := T{}
|
||||
// compile-time `for` loop
|
||||
// T.fields gives an array of a field metadata type
|
||||
$for field in T.fields {
|
||||
$if field.typ is string {
|
||||
// $(string_expr) produces an identifier
|
||||
result.$(field.name) = get_string(data, field.name)
|
||||
} $else $if field.typ is int {
|
||||
result.$(field.name) = get_int(data, field.name)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fn get_string(data string, field_name string) string {
|
||||
for line in data.split_into_lines() {
|
||||
key_val := line.split('=')
|
||||
if key_val[0] == field_name {
|
||||
return key_val[1]
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
fn get_int(data string, field string) int {
|
||||
return get_string(data, field).int()
|
||||
}
|
||||
|
||||
// `decode<User>` generates:
|
||||
// fn decode_User(data string) User {
|
||||
// mut result := User{}
|
||||
// result.name = get_string(data, 'name')
|
||||
// result.age = get_int(data, 'age')
|
||||
// return result
|
||||
// }
|
||||
```
|
||||
@@ -11,7 +11,7 @@
|
||||
when I generate vlang scripts I will always use .vsh extension and use following as first line:
|
||||
|
||||
```
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
```
|
||||
|
||||
- a .vsh is a v shell script and can be executed as is, no need to use v ...
|
||||
@@ -21,7 +21,7 @@ when I generate vlang scripts I will always use .vsh extension and use following
|
||||
## to do argument parsing use following examples
|
||||
|
||||
```v
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import flag
|
||||
|
||||
@@ -2238,7 +2238,7 @@ be faster, since there is no need for a re-compilation of a script, that has not
|
||||
An example `deploy.vsh`:
|
||||
|
||||
```v oksyntax
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// Note: The shebang line above, associates the .vsh file to V on Unix-like systems,
|
||||
// so it can be run just by specifying the path to the .vsh file, once it's made
|
||||
@@ -2300,11 +2300,11 @@ Whilst V does normally not allow vsh scripts without the designated file extensi
|
||||
to circumvent this rule and have a file with a fully custom name and shebang. Whilst this feature
|
||||
exists it is only recommended for specific usecases like scripts that will be put in the path and
|
||||
should **not** be used for things like build or deploy scripts. To access this feature start the
|
||||
file with `#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
file with `#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
the built executable. This will run in crun mode so it will only rebuild if changes to the script
|
||||
were made and keep the binary as `tmp.<scriptfilename>`. **Caution**: if this filename already
|
||||
exists the file will be overridden. If you want to rebuild each time and not keep this binary
|
||||
instead use `#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
instead use `#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
# Appendices
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
this is how we want example scripts to be, see the first line
|
||||
|
||||
```vlang
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.daguserver
|
||||
|
||||
|
||||
2
cli/.gitignore
vendored
2
cli/.gitignore
vendored
@@ -1 +1,3 @@
|
||||
hero
|
||||
compile
|
||||
compile_upload
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env -S v -parallel-cc -enable-globals run
|
||||
// #!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -parallel-cc -enable-globals run
|
||||
// #!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import flag
|
||||
@@ -45,7 +45,7 @@ compile_cmd := if os.user_os() == 'macos' {
|
||||
if prod_mode {
|
||||
'v -enable-globals -w -n -prod hero.v'
|
||||
} else {
|
||||
'v -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals hero.v'
|
||||
'v -w -cg -gc none -cc tcc -d use_openssl -enable-globals hero.v'
|
||||
}
|
||||
} else {
|
||||
if prod_mode {
|
||||
@@ -66,7 +66,7 @@ os.chmod('hero', 0o755) or { panic('Failed to make hero binary executable: ${err
|
||||
|
||||
// Ensure destination directory exists
|
||||
os.mkdir_all(os.dir(heropath)) or { panic('Failed to create directory ${os.dir(heropath)}: ${err}') }
|
||||
|
||||
println(heropath)
|
||||
// Copy to destination paths
|
||||
os.cp('hero', heropath) or { panic('Failed to copy hero binary to ${heropath}: ${err}') }
|
||||
os.cp('hero', '/tmp/hero') or { panic('Failed to copy hero binary to /tmp/hero: ${err}') }
|
||||
|
||||
@@ -89,5 +89,9 @@ fn hero_upload() ! {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//os.execute_or_panic('${os.home_dir()}/code/github/freeflowuniverse/herolib/cli/compile.vsh -p')
|
||||
println("compile hero can take 60 sec+ on osx.")
|
||||
os.execute_or_panic('${os.home_dir()}/code/github/freeflowuniverse/herolib/cli/compile.vsh -p')
|
||||
println( "upload:")
|
||||
hero_upload() or { eprintln(err) exit(1) }
|
||||
}
|
||||
|
||||
26
cli/hero.v
26
cli/hero.v
@@ -19,6 +19,26 @@ fn playcmds_do(path string) ! {
|
||||
}
|
||||
|
||||
fn do() ! {
|
||||
|
||||
if ! core.is_osx()! {
|
||||
if os.getenv('SUDO_COMMAND') != '' || os.getenv('SUDO_USER') != '' {
|
||||
println('Error: Please do not run this program with sudo!')
|
||||
exit(1) // Exit with error code
|
||||
}
|
||||
}
|
||||
|
||||
if os.getuid() == 0 {
|
||||
if core.is_osx()! {
|
||||
eprintln("please do not run hero as root in osx.")
|
||||
exit(1)
|
||||
}
|
||||
} else {
|
||||
if ! core.is_osx()! {
|
||||
eprintln("please do run hero as root, don't use sudo.")
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if os.args.len == 2 {
|
||||
mypath := os.args[1]
|
||||
if mypath.to_lower().ends_with('.hero') {
|
||||
@@ -31,7 +51,7 @@ fn do() ! {
|
||||
mut cmd := Command{
|
||||
name: 'hero'
|
||||
description: 'Your HERO toolset.'
|
||||
version: '2.0.0'
|
||||
version: '1.0.18'
|
||||
}
|
||||
|
||||
// herocmds.cmd_run_add_flags(mut cmd)
|
||||
@@ -81,6 +101,8 @@ fn do() ! {
|
||||
// herocmds.cmd_zola(mut cmd)
|
||||
// herocmds.cmd_juggler(mut cmd)
|
||||
herocmds.cmd_generator(mut cmd)
|
||||
herocmds.cmd_docusaurus(mut cmd)
|
||||
herocmds.cmd_starlight(mut cmd)
|
||||
// herocmds.cmd_docsorter(mut cmd)
|
||||
// cmd.add_command(publishing.cmd_publisher(pre_func))
|
||||
cmd.setup()
|
||||
@@ -93,4 +115,4 @@ fn main() {
|
||||
|
||||
fn pre_func(cmd Command) ! {
|
||||
herocmds.plbook_run(cmd)!
|
||||
}
|
||||
}
|
||||
40
doc.vsh
40
doc.vsh
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
|
||||
@@ -26,9 +26,9 @@ os.chdir(herolib_path) or {
|
||||
panic('Failed to change directory to herolib: ${err}')
|
||||
}
|
||||
|
||||
os.rmdir_all('_docs') or {}
|
||||
os.rmdir_all('docs') or {}
|
||||
os.rmdir_all('vdocs') or {}
|
||||
os.mkdir_all('_docs') or {}
|
||||
os.mkdir_all('docs') or {}
|
||||
os.mkdir_all('vdocs') or {}
|
||||
|
||||
// Generate HTML documentation
|
||||
println('Generating HTML documentation...')
|
||||
@@ -42,13 +42,12 @@ os.chdir(abs_dir_of_script) or {
|
||||
|
||||
// Generate Markdown documentation
|
||||
println('Generating Markdown documentation...')
|
||||
os.rmdir_all('vdocs') or {}
|
||||
|
||||
// if os.system('v doc -m -no-color -f md -o ../vdocs/v/') != 0 {
|
||||
// panic('Failed to generate V markdown documentation')
|
||||
// }
|
||||
|
||||
if os.system('v doc -m -no-color -f md -o vdocs/herolib/') != 0 {
|
||||
if os.system('v doc -m -no-color -f md -o vdocs/') != 0 {
|
||||
panic('Failed to generate Hero markdown documentation')
|
||||
}
|
||||
|
||||
@@ -62,4 +61,33 @@ $if !linux {
|
||||
}
|
||||
}
|
||||
|
||||
// Create Jekyll required files
|
||||
println('Creating Jekyll files...')
|
||||
os.mkdir_all('docs/assets/css') or {}
|
||||
|
||||
// Create style.scss
|
||||
style_content := '---\n---\n\n@import "{{ site.theme }}";'
|
||||
os.write_file('docs/assets/css/style.scss', style_content) or {
|
||||
panic('Failed to create style.scss: ${err}')
|
||||
}
|
||||
|
||||
// Create _config.yml
|
||||
config_content := 'title: HeroLib Documentation
|
||||
description: Documentation for the HeroLib project
|
||||
theme: jekyll-theme-primer
|
||||
baseurl: /herolib
|
||||
|
||||
exclude:
|
||||
- Gemfile
|
||||
- Gemfile.lock
|
||||
- node_modules
|
||||
- vendor/bundle/
|
||||
- vendor/cache/
|
||||
- vendor/gems/
|
||||
- vendor/ruby/'
|
||||
|
||||
os.write_file('docs/_config.yml', config_content) or {
|
||||
panic('Failed to create _config.yml: ${err}')
|
||||
}
|
||||
|
||||
println('Documentation generation completed successfully!')
|
||||
|
||||
3
docker/docusaurus/.gitignore
vendored
3
docker/docusaurus/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.bash_history
|
||||
.openvscode-server/
|
||||
.cache/
|
||||
@@ -1,48 +0,0 @@
|
||||
# Use Ubuntu 24.04 as the base image
|
||||
FROM ubuntu:24.04
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /root
|
||||
|
||||
# Copy local installation scripts into the container
|
||||
COPY scripts/install_v.sh /tmp/install_v.sh
|
||||
COPY scripts/install_herolib.vsh /tmp/install_herolib.vsh
|
||||
COPY scripts/install_vscode.sh /tmp/install_vscode.sh
|
||||
COPY scripts/ourinit.sh /usr/local/bin/
|
||||
|
||||
# Make the scripts executable
|
||||
RUN chmod +x /tmp/install_v.sh /tmp/install_herolib.vsh
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl bash sudo mc wget tmux htop openssh-server
|
||||
|
||||
RUN bash /tmp/install_v.sh
|
||||
|
||||
RUN yes y | bash /tmp/install_v.sh --analyzer
|
||||
|
||||
RUN bash /tmp/install_vscode.sh
|
||||
|
||||
RUN /tmp/install_herolib.vsh && \
|
||||
mkdir -p /var/run/sshd && \
|
||||
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
|
||||
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config && \
|
||||
chown -R root:root /root/.ssh && \
|
||||
chmod -R 700 /root/.ssh/ && \
|
||||
chmod 600 /root/.ssh/authorized_keys && \
|
||||
service ssh start && \
|
||||
apt-get clean && \
|
||||
echo "PS1='HERO: \w \$ '" >> ~/.bashrc \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
#SSH
|
||||
RUN mkdir -p /var/run/sshd && \
|
||||
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
|
||||
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config && \
|
||||
chown -R root:root /root/.ssh && \
|
||||
chmod -R 700 /root/.ssh/ && \
|
||||
chmod 600 /root/.ssh/authorized_keys && \
|
||||
service ssh start
|
||||
|
||||
ENTRYPOINT ["/bin/bash"]
|
||||
CMD ["/bin/bash"]
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Docker image and container names
|
||||
DOCKER_IMAGE_NAME="docusaurus"
|
||||
DEBUG_CONTAINER_NAME="herolib"
|
||||
|
||||
function cleanup {
|
||||
if docker ps -aq -f name="$DEBUG_CONTAINER_NAME" &>/dev/null; then
|
||||
echo "Cleaning up leftover debug container..."
|
||||
docker rm -f "$DEBUG_CONTAINER_NAME" &>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Attempt to build the Docker image
|
||||
BUILD_LOG=$(mktemp)
|
||||
set +e
|
||||
docker build --name herolib --progress=plain -t "$DOCKER_IMAGE_NAME" .
|
||||
BUILD_EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
# Handle build failure
|
||||
if [ $BUILD_EXIT_CODE -ne 0 ]; then
|
||||
echo -e "\\n[ERROR] Docker build failed.\n"
|
||||
echo -e "remove the part which didn't build in the Dockerfile, the run again and to debug do:"
|
||||
echo docker run --name herolib -it --entrypoint=/bin/bash "herolib"
|
||||
exit $BUILD_EXIT_CODE
|
||||
else
|
||||
echo -e "\\n[INFO] Docker build completed successfully."
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Remove any existing container named 'debug' (ignore errors)
|
||||
docker rm -f herolib > /dev/null 2>&1
|
||||
|
||||
docker run --name herolib -it \
|
||||
--entrypoint="/usr/local/bin/ourinit.sh" \
|
||||
-v "${SCRIPT_DIR}/scripts:/scripts" \
|
||||
-v "$HOME/code:/root/code" \
|
||||
-p 4100:8100 \
|
||||
-p 4101:8101 \
|
||||
-p 4102:8102 \
|
||||
-p 4379:6379 \
|
||||
-p 4022:22 \
|
||||
-p 4000:3000 herolib
|
||||
@@ -1,34 +0,0 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
container_name: postgres_service
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: planetfirst
|
||||
POSTGRES_DB: mydb
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
herolib:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: herolib:latest
|
||||
container_name: herolib
|
||||
volumes:
|
||||
- ~/code:/root/code
|
||||
stdin_open: true
|
||||
tty: true
|
||||
ports:
|
||||
- "4100:8100"
|
||||
- "4101:8101"
|
||||
- "4102:8102"
|
||||
- "4379:6379"
|
||||
- "4000:3000"
|
||||
- "4022:22"
|
||||
command: ["/usr/local/bin/ourinit.sh"]
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Set version and file variables
|
||||
OPENVSCODE_SERVER_VERSION="1.97.0"
|
||||
TMP_DIR="/tmp"
|
||||
FILENAME="openvscode.tar.gz"
|
||||
FILE_PATH="$TMP_DIR/$FILENAME"
|
||||
INSTALL_DIR="/opt/openvscode"
|
||||
BIN_PATH="/usr/local/bin/openvscode-server"
|
||||
TMUX_SESSION="openvscode-server"
|
||||
|
||||
# Function to detect architecture
|
||||
get_architecture() {
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
echo "x64"
|
||||
;;
|
||||
aarch64)
|
||||
echo "arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check if OpenVSCode Server is already installed
|
||||
if [ -d "$INSTALL_DIR" ] && [ -x "$BIN_PATH" ]; then
|
||||
echo "OpenVSCode Server is already installed at $INSTALL_DIR. Skipping download and installation."
|
||||
else
|
||||
# Determine architecture-specific URL
|
||||
ARCH=$(get_architecture)
|
||||
if [ "$ARCH" == "x64" ]; then
|
||||
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-x64.tar.gz"
|
||||
elif [ "$ARCH" == "arm64" ]; then
|
||||
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-arm64.tar.gz"
|
||||
fi
|
||||
|
||||
# Navigate to temporary directory
|
||||
cd "$TMP_DIR"
|
||||
|
||||
# Remove existing file if it exists
|
||||
if [ -f "$FILE_PATH" ]; then
|
||||
rm -f "$FILE_PATH"
|
||||
fi
|
||||
|
||||
# Download file using curl
|
||||
curl -L "$DOWNLOAD_URL" -o "$FILE_PATH"
|
||||
|
||||
# Verify file size is greater than 40 MB (40 * 1024 * 1024 bytes)
|
||||
FILE_SIZE=$(stat -c%s "$FILE_PATH")
|
||||
if [ "$FILE_SIZE" -le $((40 * 1024 * 1024)) ]; then
|
||||
echo "Error: Downloaded file size is less than 40 MB." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the tar.gz file
|
||||
EXTRACT_DIR="openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-${ARCH}"
|
||||
tar -xzf "$FILE_PATH"
|
||||
|
||||
# Move the extracted directory to the install location
|
||||
if [ -d "$INSTALL_DIR" ]; then
|
||||
rm -rf "$INSTALL_DIR"
|
||||
fi
|
||||
mv "$EXTRACT_DIR" "$INSTALL_DIR"
|
||||
|
||||
# Create a symlink for easy access
|
||||
ln -sf "$INSTALL_DIR/bin/openvscode-server" "$BIN_PATH"
|
||||
|
||||
# Verify installation
|
||||
if ! command -v openvscode-server >/dev/null 2>&1; then
|
||||
echo "Error: Failed to create symlink for openvscode-server." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install default plugins
|
||||
PLUGINS=("ms-python.python" "esbenp.prettier-vscode" "saoudrizwan.claude-dev" "yzhang.markdown-all-in-one" "ms-vscode-remote.remote-ssh" "ms-vscode.remote-explorer" "charliermarsh.ruff" "qwtel.sqlite-viewer" "vosca.vscode-v-analyzer" "tomoki1207.pdf")
|
||||
for PLUGIN in "${PLUGINS[@]}"; do
|
||||
"$INSTALL_DIR/bin/openvscode-server" --install-extension "$PLUGIN"
|
||||
done
|
||||
|
||||
echo "Default plugins installed: ${PLUGINS[*]}"
|
||||
|
||||
# Clean up temporary directory
|
||||
if [ -d "$TMP_DIR" ]; then
|
||||
find "$TMP_DIR" -maxdepth 1 -type f -name "openvscode*" -exec rm -f {} \;
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start OpenVSCode Server in a tmux session
|
||||
if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
|
||||
tmux kill-session -t "$TMUX_SESSION"
|
||||
fi
|
||||
tmux new-session -d -s "$TMUX_SESSION" "$INSTALL_DIR/bin/openvscode-server"
|
||||
|
||||
echo "OpenVSCode Server is running in a tmux session named '$TMUX_SESSION'."
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# redis-server --daemonize yes
|
||||
|
||||
# TMUX_SESSION="vscode"
|
||||
# # Start OpenVSCode Server in a tmux session
|
||||
# if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
|
||||
# tmux kill-session -t "$TMUX_SESSION"
|
||||
# fi
|
||||
# tmux new-session -d -s "$TMUX_SESSION" "/usr/local/bin/openvscode-server --host 0.0.0.0 --without-connection-token"
|
||||
|
||||
# service ssh start
|
||||
|
||||
exec /bin/bash
|
||||
@@ -1,61 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
CONTAINER_NAME="herolib"
|
||||
TARGET_PORT=4000
|
||||
|
||||
# Function to check if a container is running
|
||||
is_container_running() {
|
||||
docker ps --filter "name=$CONTAINER_NAME" --filter "status=running" -q
|
||||
}
|
||||
|
||||
# Function to check if a port is accessible
|
||||
is_port_accessible() {
|
||||
nc -zv 127.0.0.1 "$1" &>/dev/null
|
||||
}
|
||||
|
||||
# Check if the container exists and is running
|
||||
if ! is_container_running; then
|
||||
echo "Container $CONTAINER_NAME is not running."
|
||||
|
||||
# Check if the container exists but is stopped
|
||||
if docker ps -a --filter "name=$CONTAINER_NAME" -q | grep -q .; then
|
||||
echo "Starting existing container $CONTAINER_NAME..."
|
||||
docker start "$CONTAINER_NAME"
|
||||
else
|
||||
echo "Container $CONTAINER_NAME does not exist. Attempting to start with start.sh..."
|
||||
if [[ -f "$SCRIPT_DIR/start.sh" ]]; then
|
||||
bash "$SCRIPT_DIR/start.sh"
|
||||
else
|
||||
echo "Error: start.sh not found in $SCRIPT_DIR."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Wait for the container to be fully up
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# Verify the container is running
|
||||
if ! is_container_running; then
|
||||
echo "Error: Failed to start container $CONTAINER_NAME."
|
||||
exit 1
|
||||
fi
|
||||
echo "Container $CONTAINER_NAME is running."
|
||||
|
||||
# Check if the target port is accessible
|
||||
if is_port_accessible "$TARGET_PORT"; then
|
||||
echo "Port $TARGET_PORT is accessible."
|
||||
else
|
||||
echo "Port $TARGET_PORT is not accessible. Please check the service inside the container."
|
||||
fi
|
||||
|
||||
# Enter the container
|
||||
echo
|
||||
echo " ** WE NOW LOGIN TO THE CONTAINER ** "
|
||||
echo
|
||||
docker exec -it herolib bash
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
ssh root@localhost -p 4022
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Define variables
|
||||
CONTAINER_NAME="herolib"
|
||||
CONTAINER_SSH_DIR="/root/.ssh"
|
||||
AUTHORIZED_KEYS="authorized_keys"
|
||||
TEMP_AUTH_KEYS="/tmp/authorized_keys"
|
||||
|
||||
# Step 1: Create a temporary file to store public keys
|
||||
> $TEMP_AUTH_KEYS # Clear the file if it exists
|
||||
|
||||
# Step 2: Add public keys from ~/.ssh/ if they exist
|
||||
if ls ~/.ssh/*.pub 1>/dev/null 2>&1; then
|
||||
cat ~/.ssh/*.pub >> $TEMP_AUTH_KEYS
|
||||
fi
|
||||
|
||||
# Step 3: Check if ssh-agent is running and get public keys from it
|
||||
if pgrep ssh-agent >/dev/null; then
|
||||
echo "ssh-agent is running. Fetching keys..."
|
||||
ssh-add -L >> $TEMP_AUTH_KEYS 2>/dev/null
|
||||
else
|
||||
echo "ssh-agent is not running or no keys loaded."
|
||||
fi
|
||||
|
||||
# Step 4: Ensure the temporary file is not empty
|
||||
if [ ! -s $TEMP_AUTH_KEYS ]; then
|
||||
echo "No public keys found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 5: Ensure the container's SSH directory exists
|
||||
docker exec -it $CONTAINER_NAME mkdir -p $CONTAINER_SSH_DIR
|
||||
docker exec -it $CONTAINER_NAME chmod 700 $CONTAINER_SSH_DIR
|
||||
|
||||
# Step 6: Copy the public keys into the container's authorized_keys file
|
||||
docker cp $TEMP_AUTH_KEYS $CONTAINER_NAME:$CONTAINER_SSH_DIR/$AUTHORIZED_KEYS
|
||||
|
||||
# Step 7: Set proper permissions for authorized_keys
|
||||
docker exec -it $CONTAINER_NAME chmod 600 $CONTAINER_SSH_DIR/$AUTHORIZED_KEYS
|
||||
|
||||
# Step 8: Install and start the SSH server inside the container
|
||||
docker exec -it $CONTAINER_NAME bash -c "
|
||||
apt-get update &&
|
||||
apt-get install -y openssh-server &&
|
||||
mkdir -p /var/run/sshd &&
|
||||
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config &&
|
||||
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config &&
|
||||
chown -R root:root /root/.ssh &&
|
||||
chmod -R 700 /root/.ssh/ &&
|
||||
chmod 600 /root/.ssh/authorized_keys &&
|
||||
service ssh start
|
||||
"
|
||||
|
||||
# Step 9: Clean up temporary file on the host
|
||||
rm $TEMP_AUTH_KEYS
|
||||
|
||||
echo "SSH keys added and SSH server configured. You can now SSH into the container."
|
||||
|
||||
ssh root@localhost -p 4022
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,76 @@ docker run --name herolib \
|
||||
|
||||
docker exec -it herolib /scripts/cleanup.sh
|
||||
|
||||
docker export herolib | gzip > ${HOME}/Downloads/herolib.tar.gz
|
||||
|
||||
docker kill herolib
|
||||
# Detect the OS
|
||||
detect_os() {
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
echo "osx"
|
||||
elif [[ -f /etc/os-release ]]; then
|
||||
. /etc/os-release
|
||||
if [[ "$ID" == "ubuntu" ]]; then
|
||||
echo "ubuntu"
|
||||
fi
|
||||
else
|
||||
echo "unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
OS=$(detect_os)
|
||||
|
||||
if [[ "$OS" == "osx" ]]; then
|
||||
echo "Running on macOS..."
|
||||
docker export herolib | gzip > "${HOME}/Downloads/herolib.tar.gz"
|
||||
echo "Docker image exported to ${HOME}/Downloads/herolib.tar.gz"
|
||||
elif [[ "$OS" == "ubuntu" ]]; then
|
||||
echo "Running on Ubuntu..."
|
||||
export TEMP_TAR="/tmp/herolib.tar"
|
||||
|
||||
# Export the Docker container to a tar file
|
||||
docker export herolib > "$TEMP_TAR"
|
||||
echo "Docker container exported to $TEMP_TAR"
|
||||
|
||||
# Import the tar file back as a single-layer image
|
||||
docker import "$TEMP_TAR" herolib:single-layer
|
||||
echo "Docker image imported as single-layer: herolib:single-layer"
|
||||
|
||||
# Log in to Docker Hub and push the image
|
||||
docker login --username despiegk
|
||||
docker tag herolib:single-layer despiegk/herolib:single-layer
|
||||
docker push despiegk/herolib:single-layer
|
||||
echo "Docker image pushed to Docker Hub as despiegk/herolib:single-layer"
|
||||
|
||||
# Optionally remove the tar file after importing
|
||||
rm -f "$TEMP_TAR"
|
||||
echo "Temporary file $TEMP_TAR removed"
|
||||
|
||||
else
|
||||
echo "Unsupported OS detected. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker kill herolib
|
||||
|
||||
|
||||
# Test the pushed Docker image locally
|
||||
echo "Testing the Docker image locally..."
|
||||
TEST_CONTAINER_NAME="test_herolib_container"
|
||||
|
||||
docker pull despiegk/herolib:single-layer
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Failed to pull the Docker image from Docker Hub. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker run --name "$TEST_CONTAINER_NAME" -d despiegk/herolib:single-layer
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Failed to run the Docker image as a container. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker ps | grep "$TEST_CONTAINER_NAME"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Container $TEST_CONTAINER_NAME is running successfully."
|
||||
else
|
||||
echo "Container $TEST_CONTAINER_NAME is not running. Check the logs for details."
|
||||
fi
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import flag
|
||||
@@ -64,7 +64,7 @@ os.symlink('${abs_dir_of_script}/lib', '${os.home_dir()}/.vmodules/freeflowunive
|
||||
println('Herolib installation completed successfully!')
|
||||
|
||||
// Add vtest alias
|
||||
addtoscript('alias vtest=', 'alias vtest=\'v -stats -enable-globals -n -w -cg -gc none -no-retry-compilation -cc tcc test\' ') or {
|
||||
addtoscript('alias vtest=', 'alias vtest=\'v -stats -enable-globals -n -w -cg -gc none -cc tcc test\' ') or {
|
||||
eprintln('Failed to add vtest alias: ${err}')
|
||||
}
|
||||
|
||||
|
||||
22
docker/postgresql/docker-compose.yml
Normal file
22
docker/postgresql/docker-compose.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
version: '3.9'
|
||||
services:
|
||||
db:
|
||||
image: 'postgres:17.2-alpine3.21'
|
||||
restart: always
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
POSTGRES_PASSWORD: 1234
|
||||
networks:
|
||||
- my_network
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
restart: always
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
- my_network
|
||||
|
||||
networks:
|
||||
my_network:
|
||||
6
docker/postgresql/readme.md
Normal file
6
docker/postgresql/readme.md
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
Server (Host): db (because Docker Compose creates an internal network and uses service names as hostnames)
|
||||
Username: postgres (default PostgreSQL username)
|
||||
Password: 1234 (as set in your POSTGRES_PASSWORD environment variable)
|
||||
Database: Leave it empty or enter postgres (default database)
|
||||
13
docker/postgresql/start.sh
Executable file
13
docker/postgresql/start.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Stop any existing containers and remove them
|
||||
docker compose down
|
||||
|
||||
# Start the services in detached mode
|
||||
docker compose up -d
|
||||
|
||||
echo "PostgreSQL is ready"
|
||||
@@ -34,7 +34,7 @@ The examples directory demonstrates various capabilities of HeroLib:
|
||||
When creating V scripts (.vsh files), always use the following shebang:
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
```
|
||||
|
||||
This shebang ensures:
|
||||
|
||||
11
examples/biztools/_archive/investor_tool.vsh
Executable file
11
examples/biztools/_archive/investor_tool.vsh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.biz.investortool
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import os
|
||||
|
||||
mut plbook := playbook.new(
|
||||
path: '${os.home_dir()}/code/git.ourworld.tf/ourworld_holding/investorstool/output'
|
||||
)!
|
||||
mut it := investortool.play(mut plbook)!
|
||||
it.check()!
|
||||
48
examples/biztools/_archive/tf9_biz.vsh
Executable file
48
examples/biztools/_archive/tf9_biz.vsh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env -S v -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// #!/usr/bin/env -S v -cg -enable-globals run
|
||||
import freeflowuniverse.herolib.data.doctree
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.biz.bizmodel
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.core.playcmds
|
||||
import freeflowuniverse.herolib.web.mdbook
|
||||
import freeflowuniverse.herolib.biz.spreadsheet
|
||||
import os
|
||||
|
||||
const name = 'tf9_budget'
|
||||
|
||||
const wikipath = '${os.home_dir()}/code/git.ourworld.tf/ourworld_holding/info_ourworld/collections/${name}'
|
||||
const summarypath = '${wikipath}/summary.md'
|
||||
|
||||
// mut sh := spreadsheet.sheet_new(name: 'test2') or { panic(err) }
|
||||
// println(sh)
|
||||
// sh.row_new(descr: 'this is a description', name: 'something', growth: '0:100aed,55:1000eur')!
|
||||
// println(sh)
|
||||
// println(sh.wiki()!)
|
||||
|
||||
// exit(0)
|
||||
|
||||
// execute the actions so we have the info populated
|
||||
// mut plb:=playbook.new(path: wikipath)!
|
||||
// playcmds.run(mut plb,false)!
|
||||
|
||||
buildpath := '${os.home_dir()}/hero/var/mdbuild/bizmodel'
|
||||
|
||||
// just run the doctree & mdbook and it should
|
||||
// load the doctree, these are all collections
|
||||
mut tree := doctree.new(name: name)!
|
||||
tree.scan(path: wikipath)!
|
||||
tree.export(dest: buildpath, reset: true)!
|
||||
|
||||
// mut bm:=bizmodel.get("test")!
|
||||
// println(bm)
|
||||
|
||||
mut mdbooks := mdbook.get()!
|
||||
mdbooks.generate(
|
||||
name: 'bizmodel'
|
||||
summary_path: summarypath
|
||||
doctree_path: buildpath
|
||||
title: 'bizmodel ${name}'
|
||||
)!
|
||||
mdbook.book_open('bizmodel')!
|
||||
12
examples/biztools/_archive/todo.md
Normal file
12
examples/biztools/_archive/todo.md
Normal file
@@ -0,0 +1,12 @@
|
||||
need to find where the manual is
|
||||
|
||||
- [manual](bizmodel_example/configuration.md)
|
||||
- [widgets](bizmodel_example/widgets.md)
|
||||
- [graph_bar_row](bizmodel_example/graph_bar_row.md)
|
||||
- [sheet_tables](bizmodel_example/sheet_tables.md)
|
||||
- [widget_args](bizmodel_example/widget_args.md)
|
||||
- [params](bizmodel_example/configuration.md)
|
||||
- [revenue params](bizmodel_example/revenue_params.md)
|
||||
- [funding params](bizmodel_example/funding_params.md)
|
||||
- [hr params](bizmodel_example/hr_params.md)
|
||||
- [costs params](bizmodel_example/costs_params.md)
|
||||
25
examples/biztools/bizmodel.vsh
Executable file
25
examples/biztools/bizmodel.vsh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
//#!/usr/bin/env -S v -cg -enable-globals run
|
||||
import freeflowuniverse.herolib.biz.bizmodel
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.core.playcmds
|
||||
import os
|
||||
|
||||
const playbook_path = os.dir(@FILE) + '/playbook'
|
||||
const build_path = os.join_path(os.dir(@FILE), '/docusaurus')
|
||||
|
||||
buildpath := '${os.home_dir()}/hero/var/mdbuild/bizmodel'
|
||||
|
||||
mut model := bizmodel.getset("example")!
|
||||
model.workdir = build_path
|
||||
model.play(mut playbook.new(path: playbook_path)!)!
|
||||
|
||||
println(model.sheet)
|
||||
println(model.sheet.export()!)
|
||||
|
||||
model.sheet.export(path:"~/Downloads/test.csv")!
|
||||
model.sheet.export(path:"~/code/github/freeflowuniverse/starlight_template/src/content/test.csv")!
|
||||
|
||||
|
||||
|
||||
4
examples/biztools/bizmodel_docusaurus/.gitignore
vendored
Normal file
4
examples/biztools/bizmodel_docusaurus/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
bizmodel
|
||||
dest
|
||||
wiki
|
||||
build
|
||||
1
examples/biztools/bizmodel_docusaurus/archive/img/.done
Normal file
1
examples/biztools/bizmodel_docusaurus/archive/img/.done
Normal file
@@ -0,0 +1 @@
|
||||
ms1bmodel.png
|
||||
BIN
examples/biztools/bizmodel_docusaurus/archive/img/ms1bmodel.png
Normal file
BIN
examples/biztools/bizmodel_docusaurus/archive/img/ms1bmodel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
13
examples/biztools/bizmodel_docusaurus/archive/revenue.md
Normal file
13
examples/biztools/bizmodel_docusaurus/archive/revenue.md
Normal file
@@ -0,0 +1,13 @@
|
||||
## Revenue
|
||||
|
||||
Overview of achieved revenue.
|
||||
|
||||
Unit is in Million USD.
|
||||
|
||||
!!bizmodel.sheet_wiki title:'REVENUE' includefilter:rev sheetname:'bizmodel_test'
|
||||
|
||||
!!bizmodel.graph_bar_row rowname:revenue_total unit:million sheetname:'bizmodel_test'
|
||||
|
||||
!!bizmodel.graph_line_row rowname:revenue_total unit:million sheetname:'bizmodel_test'
|
||||
|
||||
!!bizmodel.graph_pie_row rowname:revenue_total unit:million size:'80%' sheetname:'bizmodel_test'
|
||||
13
examples/biztools/bizmodel_docusaurus/archive/summary.md
Normal file
13
examples/biztools/bizmodel_docusaurus/archive/summary.md
Normal file
@@ -0,0 +1,13 @@
|
||||
- [bizmodel](bizmodel_example/bizmodel.md)
|
||||
- [Revenue](bizmodel_example/revenue.md)
|
||||
- [Result](bizmodel_example/overview.md)
|
||||
- [parameters](bizmodel_example/params.md)
|
||||
- [revenue_params](bizmodel_example/params/revenue_params.md)
|
||||
- [funding_params](bizmodel_example/params/funding_params.md)
|
||||
- [hr_params](bizmodel_example/params/hr_params.md)
|
||||
- [costs_params](bizmodel_example/params/costs_params.md)
|
||||
- [rows overview](bizmodel_example/rows_overview.md)
|
||||
- [employees](bizmodel_example/employees.md)
|
||||
- [debug](bizmodel_example/debug.md)
|
||||
- [worksheet](bizmodel_example/worksheet.md)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Overview of the rows in the biz model sheet
|
||||
|
||||
|
||||
!!bizmodel.sheet_wiki sheetname:'bizmodel_test'
|
||||
37
examples/biztools/bizmodel_docusaurus/bizmodel_docusaurus.vsh
Executable file
37
examples/biztools/bizmodel_docusaurus/bizmodel_docusaurus.vsh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
//#!/usr/bin/env -S v -cg -enable-globals run
|
||||
import freeflowuniverse.herolib.biz.bizmodel
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.core.playcmds
|
||||
import os
|
||||
|
||||
//TODO: need to fix wrong location
|
||||
const playbook_path = os.dir(@FILE) + '/playbook'
|
||||
const build_path = os.join_path(os.dir(@FILE), '/docusaurus')
|
||||
|
||||
buildpath := '${os.home_dir()}/hero/var/mdbuild/bizmodel'
|
||||
|
||||
mut model := bizmodel.getset("example")!
|
||||
model.workdir = build_path
|
||||
model.play(mut playbook.new(path: playbook_path)!)!
|
||||
|
||||
println(model.sheet)
|
||||
println(model.sheet.export()!)
|
||||
|
||||
// model.sheet.export(path:"~/Downloads/test.csv")!
|
||||
// model.sheet.export(path:"~/code/github/freeflowuniverse/starlight_template/src/content/test.csv")!
|
||||
|
||||
|
||||
|
||||
|
||||
report := model.new_report(
|
||||
name: 'example_report'
|
||||
title: 'Example Business Model'
|
||||
)!
|
||||
|
||||
report.export(
|
||||
path: build_path
|
||||
overwrite: true
|
||||
format: .docusaurus
|
||||
)!
|
||||
@@ -0,0 +1 @@
|
||||
output dir of example
|
||||
22
examples/biztools/bizmodel_docusaurus/docusaurus/build.sh
Executable file
22
examples/biztools/bizmodel_docusaurus/docusaurus/build.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "${script_dir}"
|
||||
|
||||
echo "Docs directory: $script_dir"
|
||||
|
||||
cd "${HOME}/hero/var/docusaurus"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:${HOME}/.bun/bin/:$PATH
|
||||
|
||||
rm -rf /Users/despiegk/hero/var/docusaurus/build/
|
||||
|
||||
. ${HOME}/.zprofile
|
||||
|
||||
bun docusaurus build
|
||||
|
||||
mkdir -p /Users/despiegk/code/github/freeflowuniverse/herolib/examples/biztools/bizmodel/example/docusaurus
|
||||
echo SYNC TO /Users/despiegk/code/github/freeflowuniverse/herolib/examples/biztools/bizmodel/example/docusaurus
|
||||
rsync -rv --delete /Users/despiegk/hero/var/docusaurus/build/ /Users/despiegk/code/github/freeflowuniverse/herolib/examples/biztools/bizmodel/example/docusaurus/
|
||||
@@ -0,0 +1 @@
|
||||
{"style":"dark","links":[]}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"","title":"Docusaurus","tagline":"","favicon":"img/favicon.png","url":"http://localhost","url_home":"docs/introduction","baseUrl":"/","image":"img/tf_graph.png","metadata":{"description":"Docusaurus","image":"Docusaurus","title":"Docusaurus"},"buildDest":[],"buildDestDev":[]}
|
||||
@@ -0,0 +1 @@
|
||||
{"title":"Business Model","items":[{"href":"https://threefold.info/kristof/","label":"ThreeFold Technology","position":"right"},{"href":"https://threefold.io","label":"Operational Plan","position":"left"}]}
|
||||
16
examples/biztools/bizmodel_docusaurus/docusaurus/develop.sh
Executable file
16
examples/biztools/bizmodel_docusaurus/docusaurus/develop.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "${script_dir}"
|
||||
|
||||
echo "Docs directory: $script_dir"
|
||||
|
||||
cd "${HOME}/hero/var/docusaurus"
|
||||
|
||||
export PATH=/tmp/docusaurus_build/node_modules/.bin:${HOME}/.bun/bin/:$PATH
|
||||
|
||||
. ${HOME}/.zprofile
|
||||
|
||||
bun run start -p 3100
|
||||
10
examples/biztools/bizmodel_docusaurus/load.md
Normal file
10
examples/biztools/bizmodel_docusaurus/load.md
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
## Loader instructions
|
||||
|
||||
this will make sure we load the appropriate biz model
|
||||
|
||||
|
||||
```js
|
||||
!!bizmodel.load name:'default' url:'https://github.com/freeflowuniverse/herolib/tree/development/bizmodel/example/data'
|
||||
```
|
||||
|
||||
1
examples/biztools/playbook/.collection
Normal file
1
examples/biztools/playbook/.collection
Normal file
@@ -0,0 +1 @@
|
||||
name:bizmodel_example
|
||||
10
examples/biztools/playbook/bizmodel.md
Normal file
10
examples/biztools/playbook/bizmodel.md
Normal file
@@ -0,0 +1,10 @@
|
||||

|
||||
|
||||
# bizmodel
|
||||
|
||||
OurWorld has developed a tool to generate and keep business models up to date.
|
||||
|
||||
Our aim is to make it easy for ourworld to track changes in planning over the multiple projects and even be able to aggregated them. Because the input for such a plan is text (as you can see in this ebook) its easy to see how the modelling and parameters change over time.
|
||||
|
||||
This is a very flexible tool which will be extended for budgetting, cashflow management, shareholder tables, ...
|
||||
|
||||
31
examples/biztools/playbook/cost_centers.md
Normal file
31
examples/biztools/playbook/cost_centers.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# HR Params
|
||||
|
||||
## Engineering
|
||||
|
||||
Costs can be grouped in cost centers which can then be used to futher process e.g. transcactions between companies.
|
||||
|
||||
```js
|
||||
|
||||
!!bizmodel.costcenter_define bizname:'test'
|
||||
name:'tfdmcc'
|
||||
descr:'TFDMCC executes on near source agreement for TFTech'
|
||||
min_month:'10000USD'
|
||||
max_month:'100000USD'
|
||||
end_date:'1/1/2026' //when does agreement stop
|
||||
|
||||
!!bizmodel.costcenter_define bizname:'test'
|
||||
name:'cs_tftech'
|
||||
descr:'Nearsource agreement for TFTech towards Codescalers'
|
||||
min_month:'10000USD'
|
||||
max_month:'100000USD'
|
||||
end_date:'1/1/2026'
|
||||
|
||||
!!bizmodel.costcenter_define bizname:'test'
|
||||
name:'cs_tfcloud'
|
||||
descr:'Nearsource agreement for TFCloud towards Codescalers'
|
||||
min_month:'10000USD'
|
||||
max_month:'100000USD'
|
||||
end_date:'1/1/2026'
|
||||
|
||||
|
||||
```
|
||||
39
examples/biztools/playbook/costs_params.md
Normal file
39
examples/biztools/playbook/costs_params.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Generic Overhead Costs
|
||||
|
||||
possible parameters
|
||||
|
||||
- name
|
||||
- descr: description of the cost
|
||||
- cost: is 'month:amount,month:amount, ...', no extrapolation
|
||||
- cost_growth: is 'month:amount,month:amount, ..., or just a nr', will extrapolate
|
||||
- type: travel, admin, legal, varia, office
|
||||
- cost_percent_revenue e.g. 4%, will make sure the cost will be at least 4% of revenue
|
||||
- indexation, e.g. 2%
|
||||
|
||||
Other financial flows can be mentioned here as well.
|
||||
|
||||
|
||||
```js
|
||||
!!bizmodel.cost_define bizname:'test'
|
||||
name:'rental'
|
||||
descr:'Office Rental in BE.'
|
||||
cost:'5000'
|
||||
indexation:'2%'
|
||||
type:'office'
|
||||
|
||||
!!bizmodel.cost_define bizname:'test'
|
||||
name:'oneoff'
|
||||
descr:'Event in Z.'
|
||||
cost_one:'3:50000'
|
||||
type:'event'
|
||||
|
||||
!!bizmodel.cost_define bizname:'test'
|
||||
name:'cloud'
|
||||
descr:'Datacenter and Cloud Costs'
|
||||
cost:'2000eur'
|
||||
cost_percent_revenue:'2%'
|
||||
type:'cloud'
|
||||
|
||||
|
||||
```
|
||||
|
||||
4
examples/biztools/playbook/debug.md
Normal file
4
examples/biztools/playbook/debug.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Debug
|
||||
|
||||
Some tools and info to help debug the bizmodel simulator.
|
||||
|
||||
20
examples/biztools/playbook/department_params.md
Normal file
20
examples/biztools/playbook/department_params.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Department Params
|
||||
|
||||
```js
|
||||
|
||||
!!bizmodel.department_define bizname:'test'
|
||||
name:'ops'
|
||||
title:'Operations'
|
||||
order:5
|
||||
|
||||
!!bizmodel.department_define bizname:'test'
|
||||
name:'coordination'
|
||||
title:'Coordination'
|
||||
order:1
|
||||
|
||||
!!bizmodel.department_define bizname:'test'
|
||||
name:'engineering'
|
||||
title:'Engineering'
|
||||
order:4
|
||||
|
||||
```
|
||||
29
examples/biztools/playbook/funding_params.md
Normal file
29
examples/biztools/playbook/funding_params.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Funding Params
|
||||
|
||||
possible parameters
|
||||
|
||||
- name, e.g. for a specific person
|
||||
- descr: description of the funding
|
||||
- investment is month:amount,month:amount, ...
|
||||
- type: loan or capital
|
||||
|
||||
Other financial flows can be mentioned here as well.
|
||||
|
||||
|
||||
```js
|
||||
!!bizmodel.funding_define bizname:'test'
|
||||
name:'our_investor'
|
||||
descr:'A fantastic super investor.'
|
||||
investment:'3:1000000EUR'
|
||||
type:'capital'
|
||||
|
||||
!!bizmodel.funding_define bizname:'test'
|
||||
name:'a_founder'
|
||||
descr:'Together Are Strong'
|
||||
investment:'2000000'
|
||||
type:'loan'
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
73
examples/biztools/playbook/hr_params.md
Normal file
73
examples/biztools/playbook/hr_params.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# HR Params
|
||||
|
||||
## Engineering
|
||||
|
||||
possible parameters
|
||||
|
||||
- descr, description of the function (e.g. master architect)
|
||||
- cost, any currency eg. 1000usd
|
||||
- in case cost changes over time e.g. 1:10000USD,20:20000USD,60:30000USD
|
||||
- indexation, e.g. 2%
|
||||
- department
|
||||
- name, e.g. for a specific person
|
||||
- nrpeople: how many people per month, growth over time notation e.g. 1:10,60:20 means 10 in month 1 growing to 20 month 60
|
||||
- cost_percent_revenue e.g. 4%, will make sure the cost will be at least 4% of revenue
|
||||
|
||||
```js
|
||||
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
sid:2
|
||||
descr:'Senior Engineer'
|
||||
cost:'1:12000,12:14000' //cost is always per person
|
||||
department:'engineering'
|
||||
nrpeople:'0:5,20:5'
|
||||
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
name:'despiegk'
|
||||
title: 'CTO and crazy inventor.'
|
||||
sid:3
|
||||
descr:'CTO'
|
||||
cost:'12000EUR' //the salary is the cost independent of the fulltime status
|
||||
indexation:'10%'
|
||||
department:'coordination'
|
||||
page:'cto.md'
|
||||
fulltime: "50%" //100% means yes
|
||||
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
descr:'Senior Architect'
|
||||
cost:'10000USD' indexation:'5%'
|
||||
department:'engineering'
|
||||
nrpeople:'0:5,20:10'
|
||||
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
descr:'Junior Engineer'
|
||||
cost:'4000USD' indexation:'5%'
|
||||
department:'engineering'
|
||||
nrpeople:'0:5,20:10'
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Operations
|
||||
|
||||
```js
|
||||
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
descr:'Ops Manager'
|
||||
cost:'1:8000,12:14000'
|
||||
department:'ops'
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
descr:'Support Junior'
|
||||
cost:'2000EUR' indexation:'5%'
|
||||
department:'ops'
|
||||
nrpeople:'7:5,18:10'
|
||||
cost_percent_revenue:'1%'
|
||||
!!bizmodel.employee_define bizname:'test'
|
||||
descr:'Support Senior'
|
||||
cost:'5000EUR' indexation:'5%'
|
||||
department:'ops'
|
||||
nrpeople:'3:5,20:10'
|
||||
cost_percent_revenue:'1%'
|
||||
costcenter:'tfdmcc:25,cs_tfcloud:75'
|
||||
generate_page:'../employees/support_senior.md'
|
||||
```
|
||||
14
examples/biztools/playbook/params.md
Normal file
14
examples/biztools/playbook/params.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Bizmodel Params
|
||||
|
||||
In this section we can find all the parameters for the bizmodel.
|
||||
|
||||
## how to use and read
|
||||
|
||||
The params are defined in the different instruction files e.g. revenue_params.md
|
||||
|
||||
Often you will see something like `revenue_growth:'10:1000,20:1100'` this can be read as month 10 it 1000, month 20 its 1100.
|
||||
|
||||
The software will extrapolate.
|
||||
|
||||
|
||||
|
||||
85
examples/biztools/playbook/revenue_params.md
Normal file
85
examples/biztools/playbook/revenue_params.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# HR Params
|
||||
|
||||
## Revenue Items (non recurring)
|
||||
|
||||
This company is a cloud company ...
|
||||
|
||||
- name, e.g. for a specific project
|
||||
- descr, description of the revenue line item
|
||||
- revenue_items: does one of revenue, is not exterpolated
|
||||
- revenue_growth: is a revenue stream which is being extrapolated
|
||||
- revenue_setup, revenue for 1 item '1000usd'
|
||||
- revenue_setup_delay
|
||||
- revenue_monthly, revenue per month for 1 item
|
||||
- revenue_monthly_delay, how many months before monthly revenue starts
|
||||
- maintenance_month_perc, how much percent of revenue_setup will come back over months
|
||||
- cogs_setup, cost of good for 1 item at setup
|
||||
- cogs_setup_delay, how many months before setup cogs starts, after sales
|
||||
- cogs_setup_perc: what is percentage of the cogs (can change over time) for setup e.g. 0:50%
|
||||
|
||||
- cogs_monthly, cost of goods for the monthly per 1 item
|
||||
- cogs_monthly_delay, how many months before monthly cogs starts, after sales
|
||||
- cogs_monthly_perc: what is percentage of the cogs (can change over time) for monthly e.g. 0:5%,12:10%
|
||||
|
||||
- nr_sold: how many do we sell per month (is in growth format e.g. 10:100,20:200, default is 1)
|
||||
- nr_months_recurring: how many months is recurring, if 0 then no recurring
|
||||
|
||||
```js
|
||||
!!bizmodel.revenue_define bizname:'test'
|
||||
descr:'OEM Deals'
|
||||
revenue_items:'10:1000000EUR,15:3333,20:1200000'
|
||||
cogs_setup_perc: '1:5%,20:10%'
|
||||
|
||||
!!bizmodel.revenue_define bizname:'test'
|
||||
descr:'License Deals'
|
||||
revenue_growth:'10:1000,20:1100'
|
||||
cogs_perc: '10%'
|
||||
rev_delay_month: 1
|
||||
|
||||
!!bizmodel.revenue_define bizname:'test'
|
||||
descr:'3NODE License Sales 1 Time'
|
||||
//means revenue is 100 month 1, 200 month 60
|
||||
revenue_item:'1:100,60:200'
|
||||
revenue_nr:'10:1000,24:2000,60:40000'
|
||||
cogs_perc: '10%'
|
||||
rev_delay_month: 1
|
||||
|
||||
```
|
||||
|
||||
## Revenue Items Recurring
|
||||
|
||||
possible parameters
|
||||
|
||||
- name, e.g. for a specific project
|
||||
- descr, description of the revenue line item
|
||||
- revenue_setup, revenue for 1 item '1000usd'
|
||||
- revenue_monthly, revenue per month for 1 item
|
||||
- revenue_setup_delay, how many months before revenue comes in after sales
|
||||
- revenue_monthly_delay, how many months before monthly revenue starts
|
||||
- cogs_setup, cost of good for 1 item at setup
|
||||
- cogs_setup_perc: what is percentage of the cogs (can change over time) for setup e.g. 0:50%
|
||||
- cogs_monthly, cost of goods for the monthly per 1 item
|
||||
- cogs_monthly_perc: what is percentage of the cogs (can change over time) for monthly e.g. 0:5%,12:10%
|
||||
- nr_sold: how many do we sell per month (is in growth format e.g. 10:100,20:200)
|
||||
- nr_months: how many months is recurring
|
||||
|
||||
if currency not specified then is always in USD
|
||||
|
||||
```js
|
||||
|
||||
!!bizmodel.revenue_recurring_define bizname:'test'
|
||||
name: '3node_lic'
|
||||
descr:'3NODE License Sales Recurring Basic'
|
||||
revenue_setup:'1:100,60:50'
|
||||
// revenue_setup:'5'
|
||||
revenue_monthly_delay:3
|
||||
revenue_monthly:'1:1,60:1'
|
||||
// cogs_setup:'1:0'
|
||||
cogs_setup_perc:'50%'
|
||||
revenue_setup_delay:1
|
||||
cogs_monthly_perc:'50%'
|
||||
nr_sold:'10:1000,24:2000,60:40000'
|
||||
60 is the default
|
||||
nr_months:60
|
||||
```
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
module main
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.installers.base
|
||||
import freeflowuniverse.herolib.core
|
||||
|
||||
fn do() ! {
|
||||
// base.uninstall_brew()!
|
||||
// println("something")
|
||||
if osal.is_osx() {
|
||||
if core.is_osx()! {
|
||||
println('IS OSX')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
25
examples/clients/mail.vsh
Executable file
25
examples/clients/mail.vsh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.mailclient
|
||||
|
||||
// remove the previous one, otherwise the env variables are not read
|
||||
mailclient.config_delete(name: 'test')!
|
||||
|
||||
// env variables which need to be set are:
|
||||
// - MAIL_FROM=...
|
||||
// - MAIL_PASSWORD=...
|
||||
// - MAIL_PORT=465
|
||||
// - MAIL_SERVER=...
|
||||
// - MAIL_USERNAME=...
|
||||
|
||||
mut client := mailclient.get(name: 'test')!
|
||||
|
||||
println(client)
|
||||
|
||||
client.send(
|
||||
subject: 'this is a test'
|
||||
to: 'kristof@incubaid.com'
|
||||
body: '
|
||||
this is my email content
|
||||
'
|
||||
)!
|
||||
108
examples/clients/mycelium.vsh
Executable file
108
examples/clients/mycelium.vsh
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.mycelium
|
||||
import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
|
||||
import freeflowuniverse.herolib.osal
|
||||
import time
|
||||
import os
|
||||
import encoding.base64
|
||||
|
||||
const server1_port = 9001
|
||||
const server2_port = 9002
|
||||
|
||||
fn terminate(port int) ! {
|
||||
// Step 1: Run lsof to get process details
|
||||
res := os.execute('lsof -i:${port}')
|
||||
if res.exit_code != 0 {
|
||||
return error('no service running at port ${port} due to: ${res.output}')
|
||||
}
|
||||
|
||||
// Step 2: Parse the output to extract the PID
|
||||
lines := res.output.split('\n')
|
||||
if lines.len < 2 {
|
||||
return error('no process found running on port ${port}')
|
||||
}
|
||||
|
||||
// The PID is the second column in the output
|
||||
fields := lines[1].split(' ')
|
||||
if fields.len < 2 {
|
||||
return error('failed to parse lsof output')
|
||||
}
|
||||
pid := fields[1]
|
||||
|
||||
// Step 3: Kill the process using the PID
|
||||
kill_res := os.execute('kill ${pid}')
|
||||
if kill_res.exit_code != 0 {
|
||||
return error('failed to kill process ${pid}: ${kill_res.output}')
|
||||
}
|
||||
|
||||
println('Successfully terminated process ${pid} running on port ${port}')
|
||||
}
|
||||
|
||||
// Check if not installed install it.
|
||||
mut installer := mycelium_installer.get()!
|
||||
installer.install()!
|
||||
|
||||
mycelium.delete()!
|
||||
|
||||
spawn fn () {
|
||||
os.execute('mkdir -p /tmp/mycelium_server1 && cd /tmp/mycelium_server1 && mycelium --peers tcp://188.40.132.242:9651 quic://[2a01:4f8:212:fa6::2]:9651 tcp://185.69.166.7:9651 quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651 tcp://65.21.231.58:9651 quic://[2a01:4f9:5a:1042::2]:9651 tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651 quic://5.78.122.16:9651 tcp://[2a01:4ff:2f0:3621::1]:9651 quic://142.93.217.194:9651 --tun-name tun2 --tcp-listen-port 9652 --quic-listen-port 9653 --api-addr 127.0.0.1:${server1_port}')
|
||||
}()
|
||||
|
||||
spawn fn () {
|
||||
os.execute('mkdir -p /tmp/mycelium_server2 && cd /tmp/mycelium_server2 && mycelium --peers tcp://188.40.132.242:9651 quic://[2a01:4f8:212:fa6::2]:9651 tcp://185.69.166.7:9651 quic://[2a02:1802:5e:0:ec4:7aff:fe51:e36b]:9651 tcp://65.21.231.58:9651 quic://[2a01:4f9:5a:1042::2]:9651 tcp://[2604:a00:50:17b:9e6b:ff:fe1f:e054]:9651 quic://5.78.122.16:9651 tcp://[2a01:4ff:2f0:3621::1]:9651 quic://142.93.217.194:9651 --tun-name tun3 --tcp-listen-port 9654 --quic-listen-port 9655 --api-addr 127.0.0.1:${server2_port}')
|
||||
}()
|
||||
|
||||
defer {
|
||||
terminate(server1_port) or {}
|
||||
terminate(server2_port) or {}
|
||||
}
|
||||
|
||||
time.sleep(2 * time.second)
|
||||
|
||||
mut client1 := mycelium.get()!
|
||||
client1.server_url = 'http://localhost:${server1_port}'
|
||||
client1.name = 'client1'
|
||||
println(client1)
|
||||
|
||||
mut client2 := mycelium.get()!
|
||||
client2.server_url = 'http://localhost:${server2_port}'
|
||||
client2.name = 'client2'
|
||||
println(client2)
|
||||
|
||||
inspect1 := mycelium.inspect(key_file_path: '/tmp/mycelium_server1/priv_key.bin')!
|
||||
inspect2 := mycelium.inspect(key_file_path: '/tmp/mycelium_server2/priv_key.bin')!
|
||||
|
||||
println('Server 1 public key: ${inspect1.public_key}')
|
||||
println('Server 2 public key: ${inspect2.public_key}')
|
||||
|
||||
// Send a message to a node by public key
|
||||
// Parameters: public_key, payload, topic, wait_for_reply
|
||||
msg := client1.send_msg(
|
||||
public_key: inspect2.public_key // destination public key
|
||||
payload: 'Sending a message from the client 1 to the client 2' // message payload
|
||||
topic: 'testing' // optional topic
|
||||
)!
|
||||
|
||||
println('Sent message ID: ${msg.id}')
|
||||
println('send succeeded')
|
||||
|
||||
// Receive messages
|
||||
// Parameters: wait_for_message, peek_only, topic_filter
|
||||
received := client2.receive_msg(wait: true, peek: false, topic: 'testing')!
|
||||
println('Received message from: ${received.src_pk}')
|
||||
println('Message payload: ${base64.decode_str(received.payload)}')
|
||||
|
||||
// Reply to a message
|
||||
// client1.reply_msg(
|
||||
// id: received.id
|
||||
// public_key: received.src_pk
|
||||
// payload: 'Got your message!'
|
||||
// topic: 'greetings'
|
||||
// )!
|
||||
|
||||
// // // Check message status
|
||||
// // status := client.get_msg_status(msg.id)!
|
||||
// // println('Message status: ${status.state}')
|
||||
// // println('Created at: ${status.created}')
|
||||
// // println('Expires at: ${status.deadline}')
|
||||
43
examples/clients/psql.vsh
Executable file
43
examples/clients/psql.vsh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: 'test')!
|
||||
|
||||
// Check if test database exists, create if not
|
||||
if !db_client.db_exists('test')! {
|
||||
println('Creating database test...')
|
||||
db_client.db_create('test')!
|
||||
}
|
||||
|
||||
// Switch to test database
|
||||
db_client.dbname = 'test'
|
||||
|
||||
// Create table if not exists
|
||||
create_table_sql := 'CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)'
|
||||
|
||||
println('Creating table users if not exists...')
|
||||
db_client.exec(create_table_sql)!
|
||||
|
||||
println('Database and table setup completed successfully!')
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.codeparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import time
|
||||
import freeflowuniverse.herolib.core.smartid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.dbfs
|
||||
import time
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.generator.installer
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module dagu
|
||||
|
||||
// import os
|
||||
import freeflowuniverse.herolib.clients.httpconnection
|
||||
import freeflowuniverse.herolib.core.httpconnection
|
||||
import os
|
||||
|
||||
struct GiteaClient[T] {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.crypt.secrets
|
||||
|
||||
|
||||
1
examples/data/.gitignore
vendored
Normal file
1
examples/data/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cache
|
||||
139
examples/data/cache.vsh
Executable file
139
examples/data/cache.vsh
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env -S v run
|
||||
|
||||
// Example struct to cache
|
||||
import freeflowuniverse.herolib.data.cache
|
||||
import time
|
||||
|
||||
@[heap]
|
||||
struct User {
|
||||
id u32
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Create a cache with custom configuration
|
||||
config := cache.CacheConfig{
|
||||
max_entries: 1000 // Maximum number of entries
|
||||
max_size_mb: 10.0 // Maximum cache size in MB
|
||||
ttl_seconds: 300 // Items expire after 5 minutes
|
||||
eviction_ratio: 0.2 // Evict 20% of entries when full
|
||||
}
|
||||
|
||||
mut user_cache := cache.new_cache[User](config)
|
||||
|
||||
// Create some example users
|
||||
user1 := &User{
|
||||
id: 1
|
||||
name: 'Alice'
|
||||
age: 30
|
||||
}
|
||||
|
||||
user2 := &User{
|
||||
id: 2
|
||||
name: 'Bob'
|
||||
age: 25
|
||||
}
|
||||
|
||||
// Add users to cache
|
||||
println('Adding users to cache...')
|
||||
user_cache.set(user1.id, user1)
|
||||
user_cache.set(user2.id, user2)
|
||||
|
||||
// Retrieve users from cache
|
||||
println('\nRetrieving users from cache:')
|
||||
if cached_user1 := user_cache.get(1) {
|
||||
println('Found user 1: ${cached_user1.name}, age ${cached_user1.age}')
|
||||
}
|
||||
|
||||
if cached_user2 := user_cache.get(2) {
|
||||
println('Found user 2: ${cached_user2.name}, age ${cached_user2.age}')
|
||||
}
|
||||
|
||||
// Try to get non-existent user
|
||||
println('\nTrying to get non-existent user:')
|
||||
if user := user_cache.get(999) {
|
||||
println('Found user: ${user.name}')
|
||||
} else {
|
||||
println('User not found in cache')
|
||||
}
|
||||
|
||||
// Demonstrate cache stats
|
||||
println('\nCache statistics:')
|
||||
println('Number of entries: ${user_cache.len()}')
|
||||
|
||||
// Clear the cache
|
||||
println('\nClearing cache...')
|
||||
user_cache.clear()
|
||||
println('Cache entries after clear: ${user_cache.len()}')
|
||||
|
||||
// Demonstrate max entries limit
|
||||
println('\nDemonstrating max entries limit (adding 2000 entries):')
|
||||
println('Initial cache size: ${user_cache.len()}')
|
||||
|
||||
for i := u32(0); i < 2000; i++ {
|
||||
user := &User{
|
||||
id: i
|
||||
name: 'User${i}'
|
||||
age: 20 + int(i % 50)
|
||||
}
|
||||
user_cache.set(i, user)
|
||||
|
||||
if i % 200 == 0 {
|
||||
println('After adding ${i} entries:')
|
||||
println(' Cache size: ${user_cache.len()}')
|
||||
|
||||
// Check some entries to verify LRU behavior
|
||||
if i >= 500 {
|
||||
old_id := if i < 1000 { u32(0) } else { i - 1000 }
|
||||
recent_id := i - 1
|
||||
println(' Entry ${old_id} (old): ${if _ := user_cache.get(old_id) {
|
||||
'found'
|
||||
} else {
|
||||
'evicted'
|
||||
}}')
|
||||
println(' Entry ${recent_id} (recent): ${if _ := user_cache.get(recent_id) {
|
||||
'found'
|
||||
} else {
|
||||
'evicted'
|
||||
}}')
|
||||
}
|
||||
println('')
|
||||
}
|
||||
}
|
||||
|
||||
println('Final statistics:')
|
||||
println('Cache size: ${user_cache.len()} (should be max 1000)')
|
||||
|
||||
// Verify we can only access recent entries
|
||||
println('\nVerifying LRU behavior:')
|
||||
println('First entry (0): ${if _ := user_cache.get(0) { 'found' } else { 'evicted' }}')
|
||||
println('Middle entry (1000): ${if _ := user_cache.get(1000) { 'found' } else { 'evicted' }}')
|
||||
println('Recent entry (1900): ${if _ := user_cache.get(1900) { 'found' } else { 'evicted' }}')
|
||||
println('Last entry (1999): ${if _ := user_cache.get(1999) { 'found' } else { 'evicted' }}')
|
||||
|
||||
// Demonstrate TTL expiration
|
||||
println('\nDemonstrating TTL expiration:')
|
||||
quick_config := cache.CacheConfig{
|
||||
ttl_seconds: 2 // Set short TTL for demo
|
||||
}
|
||||
mut quick_cache := cache.new_cache[User](quick_config)
|
||||
|
||||
// Add a user
|
||||
quick_cache.set(user1.id, user1)
|
||||
println('Added user to cache with 2 second TTL')
|
||||
|
||||
if cached := quick_cache.get(user1.id) {
|
||||
println('User found immediately: ${cached.name}')
|
||||
}
|
||||
|
||||
// Wait for TTL to expire
|
||||
println('Waiting for TTL to expire...')
|
||||
time.sleep(3 * time.second)
|
||||
|
||||
if _ := quick_cache.get(user1.id) {
|
||||
println('User still in cache')
|
||||
} else {
|
||||
println('User expired from cache as expected')
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
import crypto.ed25519
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.crypt.aes_symmetric { decrypt, encrypt }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
175
examples/data/graphdb.vsh
Executable file
175
examples/data/graphdb.vsh
Executable file
@@ -0,0 +1,175 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
// Example demonstrating GraphDB usage in a social network context
|
||||
import freeflowuniverse.herolib.data.graphdb
|
||||
|
||||
fn main() {
|
||||
// Initialize a new graph database with default cache settings
|
||||
mut gdb := graphdb.new(
|
||||
path: '/tmp/social_network_example'
|
||||
reset: true // Start fresh each time
|
||||
)!
|
||||
|
||||
println('=== Social Network Graph Example ===\n')
|
||||
|
||||
// 1. Creating User Nodes
|
||||
println('Creating users...')
|
||||
mut alice_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Alice Chen'
|
||||
'age': '28'
|
||||
'location': 'San Francisco'
|
||||
'occupation': 'Software Engineer'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(alice_id)!}')
|
||||
|
||||
mut bob_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Bob Smith'
|
||||
'age': '32'
|
||||
'location': 'New York'
|
||||
'occupation': 'Product Manager'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(bob_id)!}')
|
||||
|
||||
mut carol_id := gdb.create_node({
|
||||
'type': 'user'
|
||||
'name': 'Carol Davis'
|
||||
'age': '27'
|
||||
'location': 'San Francisco'
|
||||
'occupation': 'Data Scientist'
|
||||
})!
|
||||
println('Created user: ${gdb.debug_node(carol_id)!}')
|
||||
|
||||
// 2. Creating Organization Nodes
|
||||
println('\nCreating organizations...')
|
||||
mut techcorp_id := gdb.create_node({
|
||||
'type': 'organization'
|
||||
'name': 'TechCorp'
|
||||
'industry': 'Technology'
|
||||
'location': 'San Francisco'
|
||||
'size': '500+'
|
||||
})!
|
||||
println('Created organization: ${gdb.debug_node(techcorp_id)!}')
|
||||
|
||||
mut datacorp_id := gdb.create_node({
|
||||
'type': 'organization'
|
||||
'name': 'DataCorp'
|
||||
'industry': 'Data Analytics'
|
||||
'location': 'New York'
|
||||
'size': '100-500'
|
||||
})!
|
||||
println('Created organization: ${gdb.debug_node(datacorp_id)!}')
|
||||
|
||||
// 3. Creating Interest Nodes
|
||||
println('\nCreating interest groups...')
|
||||
mut ai_group_id := gdb.create_node({
|
||||
'type': 'group'
|
||||
'name': 'AI Enthusiasts'
|
||||
'category': 'Technology'
|
||||
'members': '0'
|
||||
})!
|
||||
println('Created group: ${gdb.debug_node(ai_group_id)!}')
|
||||
|
||||
// 4. Establishing Relationships
|
||||
println('\nCreating relationships...')
|
||||
|
||||
// Friendship relationships
|
||||
gdb.create_edge(alice_id, bob_id, 'FRIENDS', {
|
||||
'since': '2022'
|
||||
'strength': 'close'
|
||||
})!
|
||||
gdb.create_edge(alice_id, carol_id, 'FRIENDS', {
|
||||
'since': '2023'
|
||||
'strength': 'close'
|
||||
})!
|
||||
|
||||
// Employment relationships
|
||||
gdb.create_edge(alice_id, techcorp_id, 'WORKS_AT', {
|
||||
'role': 'Senior Engineer'
|
||||
'since': '2021'
|
||||
'department': 'Engineering'
|
||||
})!
|
||||
gdb.create_edge(bob_id, datacorp_id, 'WORKS_AT', {
|
||||
'role': 'Product Lead'
|
||||
'since': '2020'
|
||||
'department': 'Product'
|
||||
})!
|
||||
gdb.create_edge(carol_id, techcorp_id, 'WORKS_AT', {
|
||||
'role': 'Data Scientist'
|
||||
'since': '2022'
|
||||
'department': 'Analytics'
|
||||
})!
|
||||
|
||||
// Group memberships
|
||||
gdb.create_edge(alice_id, ai_group_id, 'MEMBER_OF', {
|
||||
'joined': '2023'
|
||||
'status': 'active'
|
||||
})!
|
||||
gdb.create_edge(carol_id, ai_group_id, 'MEMBER_OF', {
|
||||
'joined': '2023'
|
||||
'status': 'active'
|
||||
})!
|
||||
|
||||
// 5. Querying the Graph
|
||||
println('\nPerforming queries...')
|
||||
|
||||
// Find users in San Francisco
|
||||
println('\nUsers in San Francisco:')
|
||||
sf_users := gdb.query_nodes_by_property('location', 'San Francisco')!
|
||||
for user in sf_users {
|
||||
if user.properties['type'] == 'user' {
|
||||
println('- ${user.properties['name']} (${user.properties['occupation']})')
|
||||
}
|
||||
}
|
||||
|
||||
// Find Alice's friends
|
||||
println("\nAlice's friends:")
|
||||
alice_friends := gdb.get_connected_nodes(alice_id, 'FRIENDS', 'out')!
|
||||
for friend in alice_friends {
|
||||
println('- ${friend.properties['name']} in ${friend.properties['location']}')
|
||||
}
|
||||
|
||||
// Find where Alice works
|
||||
println("\nAlice's workplace:")
|
||||
alice_workplaces := gdb.get_connected_nodes(alice_id, 'WORKS_AT', 'out')!
|
||||
for workplace in alice_workplaces {
|
||||
println('- ${workplace.properties['name']} (${workplace.properties['industry']})')
|
||||
}
|
||||
|
||||
// Find TechCorp employees
|
||||
println('\nTechCorp employees:')
|
||||
techcorp_employees := gdb.get_connected_nodes(techcorp_id, 'WORKS_AT', 'in')!
|
||||
for employee in techcorp_employees {
|
||||
println('- ${employee.properties['name']} as ${employee.properties['occupation']}')
|
||||
}
|
||||
|
||||
// Find AI group members
|
||||
println('\nAI Enthusiasts group members:')
|
||||
ai_members := gdb.get_connected_nodes(ai_group_id, 'MEMBER_OF', 'in')!
|
||||
for member in ai_members {
|
||||
println('- ${member.properties['name']}')
|
||||
}
|
||||
|
||||
// 6. Updating Data
|
||||
println('\nUpdating data...')
|
||||
|
||||
// Promote Alice
|
||||
println('\nPromoting Alice...')
|
||||
mut alice := gdb.get_node(alice_id)!
|
||||
alice.properties['occupation'] = 'Lead Software Engineer'
|
||||
gdb.update_node(alice_id, alice.properties)!
|
||||
|
||||
// Update Alice's work relationship
|
||||
mut edges := gdb.get_edges_between(alice_id, techcorp_id)!
|
||||
if edges.len > 0 {
|
||||
gdb.update_edge(edges[0].id, {
|
||||
'role': 'Engineering Team Lead'
|
||||
'since': '2021'
|
||||
'department': 'Engineering'
|
||||
})!
|
||||
}
|
||||
|
||||
println('\nFinal graph structure:')
|
||||
gdb.print_graph()!
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
29
examples/data/heroencoder_simple.vsh
Executable file
29
examples/data/heroencoder_simple.vsh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import time
|
||||
|
||||
struct Person {
|
||||
mut:
|
||||
name string
|
||||
age int = 20
|
||||
birthday time.Time
|
||||
}
|
||||
|
||||
mut person := Person{
|
||||
name: 'Bob'
|
||||
birthday: time.now()
|
||||
}
|
||||
heroscript := encoderhero.encode[Person](person)!
|
||||
|
||||
println(heroscript)
|
||||
|
||||
person2 := encoderhero.decode[Person](heroscript)!
|
||||
println(person2)
|
||||
|
||||
// show that it doesn't matter which action & method is used
|
||||
heroscript2 := "!!a.b name:Bob age:20 birthday:'2025-02-06 09:57:30'"
|
||||
person3 := encoderhero.decode[Person](heroscript)!
|
||||
|
||||
println(person3)
|
||||
35
examples/data/jsonexample.vsh
Executable file
35
examples/data/jsonexample.vsh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import json
|
||||
|
||||
enum JobTitle {
|
||||
manager
|
||||
executive
|
||||
worker
|
||||
}
|
||||
|
||||
struct Employee {
|
||||
mut:
|
||||
name string
|
||||
family string @[json: '-'] // this field will be skipped
|
||||
age int
|
||||
salary f32
|
||||
title JobTitle @[json: 'ETitle'] // the key for this field will be 'ETitle', not 'title'
|
||||
notes string @[omitempty] // the JSON property is not created if the string is equal to '' (an empty string).
|
||||
// TODO: document @[raw]
|
||||
}
|
||||
|
||||
x := Employee{'Peter', 'Begins', 28, 95000.5, .worker, ''}
|
||||
println(x)
|
||||
s := json.encode(x)
|
||||
println('JSON encoding of employee x: ${s}')
|
||||
assert s == '{"name":"Peter","age":28,"salary":95000.5,"ETitle":"worker"}'
|
||||
mut y := json.decode(Employee, s)!
|
||||
assert y != x
|
||||
assert y.family == ''
|
||||
y.family = 'Begins'
|
||||
assert y == x
|
||||
println(y)
|
||||
ss := json.encode(y)
|
||||
println('JSON encoding of employee y: ${ss}')
|
||||
assert ss == s
|
||||
63
examples/data/location/location_example.vsh
Executable file
63
examples/data/location/location_example.vsh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
import freeflowuniverse.herolib.data.location
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: 'test')!
|
||||
|
||||
// Create a new location instance
|
||||
mut loc := location.new(mut db_client, false) or { panic(err) }
|
||||
println('Location database initialized')
|
||||
|
||||
// Initialize the database (downloads and imports data)
|
||||
// This only needs to be done once or when updating data
|
||||
println('Downloading and importing location data (this may take a few minutes)...')
|
||||
|
||||
// the arg is if we redownload
|
||||
loc.download_and_import(false) or { panic(err) }
|
||||
println('Data import complete')
|
||||
|
||||
// // Example 1: Search for a city
|
||||
// println('\nSearching for London...')
|
||||
// results := loc.search('London', 'GB', 5, true) or { panic(err) }
|
||||
// for result in results {
|
||||
// println('${result.city.name}, ${result.country.name} (${result.country.iso2})')
|
||||
// println('Coordinates: ${result.city.latitude}, ${result.city.longitude}')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('Timezone: ${result.city.timezone}')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 2: Search near coordinates (10km radius from London)
|
||||
// println('\nSearching for cities within 10km of London...')
|
||||
// nearby := loc.search_near(51.5074, -0.1278, 10.0, 5) or { panic(err) }
|
||||
// for result in nearby {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('Distance from center: Approx ${result.similarity:.1f}km')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 3: Fuzzy search in a specific country
|
||||
// println('\nFuzzy searching for "New" in United States...')
|
||||
// us_cities := loc.search('New', 'US', 5, true) or { panic(err) }
|
||||
// for result in us_cities {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('State: ${result.city.state_name} (${result.city.state_code})')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('---')
|
||||
// }
|
||||
63
examples/data/location/location_example_tcc.vsh
Executable file
63
examples/data/location/location_example_tcc.vsh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
import freeflowuniverse.herolib.data.location
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure
|
||||
name:'test'
|
||||
user: 'postgres'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
password: '1234'
|
||||
dbname: 'postgres'
|
||||
"
|
||||
|
||||
// Process the heroscript configuration
|
||||
postgresql_client.play(heroscript: heroscript)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: 'test')!
|
||||
|
||||
// Create a new location instance
|
||||
mut loc := location.new(mut db_client, false) or { panic(err) }
|
||||
println('Location database initialized')
|
||||
|
||||
// Initialize the database (downloads and imports data)
|
||||
// This only needs to be done once or when updating data
|
||||
println('Downloading and importing location data (this may take a few minutes)...')
|
||||
|
||||
// the arg is if we redownload
|
||||
loc.download_and_import(false) or { panic(err) }
|
||||
println('Data import complete')
|
||||
|
||||
// // Example 1: Search for a city
|
||||
// println('\nSearching for London...')
|
||||
// results := loc.search('London', 'GB', 5, true) or { panic(err) }
|
||||
// for result in results {
|
||||
// println('${result.city.name}, ${result.country.name} (${result.country.iso2})')
|
||||
// println('Coordinates: ${result.city.latitude}, ${result.city.longitude}')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('Timezone: ${result.city.timezone}')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 2: Search near coordinates (10km radius from London)
|
||||
// println('\nSearching for cities within 10km of London...')
|
||||
// nearby := loc.search_near(51.5074, -0.1278, 10.0, 5) or { panic(err) }
|
||||
// for result in nearby {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('Distance from center: Approx ${result.similarity:.1f}km')
|
||||
// println('---')
|
||||
// }
|
||||
|
||||
// // Example 3: Fuzzy search in a specific country
|
||||
// println('\nFuzzy searching for "New" in United States...')
|
||||
// us_cities := loc.search('New', 'US', 5, true) or { panic(err) }
|
||||
// for result in us_cities {
|
||||
// println('${result.city.name}, ${result.country.name}')
|
||||
// println('State: ${result.city.state_name} (${result.city.state_code})')
|
||||
// println('Population: ${result.city.population}')
|
||||
// println('---')
|
||||
// }
|
||||
40
examples/data/ourdb_example.vsh
Executable file
40
examples/data/ourdb_example.vsh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.ourdb
|
||||
|
||||
const test_dir = '/tmp/ourdb'
|
||||
|
||||
mut db := ourdb.new(
|
||||
record_nr_max: 16777216 - 1 // max size of records
|
||||
record_size_max: 1024
|
||||
path: test_dir
|
||||
reset: true
|
||||
)!
|
||||
|
||||
defer {
|
||||
db.destroy() or { panic('failed to destroy db: ${err}') }
|
||||
}
|
||||
|
||||
// Test set and get
|
||||
test_data := 'Hello, World!'.bytes()
|
||||
id := db.set(data: test_data)!
|
||||
|
||||
retrieved := db.get(id)!
|
||||
assert retrieved == test_data
|
||||
|
||||
assert id == 0
|
||||
|
||||
// Test overwrite
|
||||
new_data := 'Updated data'.bytes()
|
||||
id2 := db.set(id: 0, data: new_data)!
|
||||
assert id2 == 0
|
||||
|
||||
// // Verify lookup table has the correct location
|
||||
// location := db.lookup.get(id2)!
|
||||
// println('Location after update - file_nr: ${location.file_nr}, position: ${location.position}')
|
||||
|
||||
// Get and verify the updated data
|
||||
retrieved2 := db.get(id2)!
|
||||
println('Retrieved data: ${retrieved2}')
|
||||
println('Expected data: ${new_data}')
|
||||
assert retrieved2 == new_data
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser { Params, parse }
|
||||
import time
|
||||
|
||||
33
examples/data/radixtree.vsh
Executable file
33
examples/data/radixtree.vsh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.radixtree
|
||||
|
||||
mut rt := radixtree.new(path: '/tmp/radixtree_test', reset: true)!
|
||||
|
||||
// Show initial state
|
||||
println('\nInitial state:')
|
||||
rt.debug_db()!
|
||||
|
||||
// Test insert
|
||||
println('\nInserting key "test" with value "value1"')
|
||||
rt.insert('test', 'value1'.bytes())!
|
||||
|
||||
// Show state after insert
|
||||
println('\nState after insert:')
|
||||
rt.debug_db()!
|
||||
|
||||
// Print tree structure
|
||||
rt.print_tree()!
|
||||
|
||||
// Test search
|
||||
if value := rt.search('test') {
|
||||
println('\nFound value: ${value.bytestr()}')
|
||||
} else {
|
||||
println('\nError: ${err}')
|
||||
}
|
||||
|
||||
println('\nInserting key "test2" with value "value2"')
|
||||
rt.insert('test2', 'value2'.bytes())!
|
||||
|
||||
// Print tree structure
|
||||
rt.print_tree()!
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.resp
|
||||
import crypto.ed25519
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env -S v -n -w -no-retry-compilation -d use_openssl -enable-globals run
|
||||
//#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
//-parallel-cc
|
||||
import os
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
// import freeflowuniverse.herolib.develop.performance
|
||||
|
||||
mut silent := false
|
||||
|
||||
coderoot := if 'CODEROOT' in os.environ() {
|
||||
os.environ()['CODEROOT']
|
||||
} else {
|
||||
os.join_path(os.home_dir(), 'code')
|
||||
}
|
||||
|
||||
// timer := performance.new('gittools')
|
||||
|
||||
|
||||
mut gs := gittools.get()!
|
||||
if coderoot.len > 0 {
|
||||
// is a hack for now
|
||||
gs = gittools.new(coderoot: coderoot)!
|
||||
}
|
||||
|
||||
mypath := gs.do(
|
||||
recursive: true
|
||||
cmd: 'list'
|
||||
)!
|
||||
|
||||
// timer.timeline()
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import time
|
||||
|
||||
mut gs_default := gittools.new()!
|
||||
|
||||
println(gs_default)
|
||||
|
||||
// // Initializes the Git structure with the coderoot path.
|
||||
// coderoot := '/tmp/code'
|
||||
// mut gs_tmo := gittools.new(coderoot: coderoot)!
|
||||
|
||||
// // Retrieve the specified repository.
|
||||
// mut repo := gs_default.get_repo(name: 'herolib')!
|
||||
|
||||
// println(repo)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user