Skip to content

Commit

Permalink
cleaning repo, adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Feb 17, 2025
1 parent fe7c321 commit 86c173a
Show file tree
Hide file tree
Showing 25 changed files with 734 additions and 4,623 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ tests/*.html
shell_*.rye
console_*.rye
console_*.rye.enc
temp.*
*.cast
*.nogo

buildtemp/main.rye
*.bson
Expand Down
17 changes: 17 additions & 0 deletions examples/contexts/test.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


game: context {

x: 0

update: fn\par { } current {
x:: x + 1 |change! 'x
; print x
}

draw: fn\par { } current { print x }

}


loop 10 { game/update game/draw }
62 changes: 62 additions & 0 deletions examples/csv-http-demo/asciinema-demo.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
; This one will be a doozy, we will parse csv, add columns to the table,
; make a http server that uses it (in a goroutine), then call that server,
; parse it's response, and notify folks in response via email

; we will load our team's data from csv file
load\csv %blindsight.csv
|display

; we will add two more columns, generate them from existing data
|add-col! 'fullname { name surname } { name + " " + surname }
|add-col! 'status { oxygen } { either oxygen .to-integer < 150 { "danger" } { "OK" } }
|display

; we will create new table with just selected columns
|columns { 'fullname 'species 'status }
|display
:team

; we can filter just the ones in danger
|where-equal 'species "vampire" |display
; we can turn it to json
|to-json

; we will make a closure that returns endangered members
get-endangered: closure { } { team .where-equal 'status "danger" }

; and a http server handler, we could do that inline
handler: fn { r w } { .write to-json get-endangered }

; and now we create a web server, but in it's own goroutine, so we can use the shell further
go does { http-server ":8080" |handle "/danger" ?handler |serve }

; make a HTTP GET request to the server we've just made
get http://localhost:8080/danger
|parse-json :dang
|first .keys

; get fullnames out of JSON and turn them to email addresses
dang .map { -> "fullname" }
|map { .replace " " "." |concat "@refaktorlabs.com" }
:emails

; We will alert endangered members via email using Postmark API

; first we load the postmark token
token: first load %.token

; we make a function that builds our email object
build-email: fn { email subject } {
new-postmark-email
|from<- podpora@cebelca.biz
|to<- email
|subject<- subject
|text-body<- ""
}

; now we will notify the endangered team members
for emails { .build-email "OXYGEN LOW" |send open-postmark token }




6 changes: 6 additions & 0 deletions examples/csv-http-demo/blindsight.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name,surname,oxygen,species
Siri,Keeton,180,human
Amanda,Bates,230,human
Jukka,Sarasti,299,vampire
Isaac,Szpindel,45,human
Susan,James,140,human
7 changes: 7 additions & 0 deletions examples/csv-http-demo/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
first_name,last_name,oxygen,species
Siri,Keeton,120,human
Amanda,Bates,230,human
Jukka,Sarasti,299,vampire
Isaac,Szpindel,0,human
Susan,James,140,human
Robert,Cunningham,180,human
16 changes: 16 additions & 0 deletions examples/csv-http-demo/temp.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

load\csv %blindsight.csv
|add-col! 'status { oxygen } { either oxygen .to-integer < 150 { "danger" } { "OK" } }
:team

team .to-json |print

get-in-danger: fnc { } current-ctx { team .where-equal 'status "danger" }

tt: fnc { w r } current-ctx { .write to-json get-in-danger }

1 .go-with fn1 {
http-server ":8080"
|handle "/vamps" ?tt
|serve
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ term: context {
extend: fn { n c } { produce n "" { .concat c } }
line: fn1 { .extend "─" }

timely-print: fn1 { .for { .prin , sleep 50 } }
timely-print: fn1 { .for { .prn , sleep 50 } }

draw-box: fn { cols rows offset } {
right offset , "╭" |+ line cols + 3 |+ "╮" |print
Expand Down Expand Up @@ -35,14 +35,14 @@ term: context {
tui\selection ch 62
}

up: fn1 { .esc-val "[(*)A" |prin }
down: fn1 { .esc-val "[(*)B" |prin }
right: fn1 { .esc-val "[(*)C" |prin }
left: fn1 { .esc-val "[(*)D" |prin }
bold: does { esc "[1m" |prin }
reset: does { esc "[22m" |prin }
up: fn1 { .esc-val "[(*)A" |prn }
down: fn1 { .esc-val "[(*)B" |prn }
right: fn1 { .esc-val "[(*)C" |prn }
left: fn1 { .esc-val "[(*)D" |prn }
bold: does { esc "[1m" |prn }
reset: does { esc "[22m" |prn }

color\red: does { esc "[31m" |prin }
color\default: does { esc "[39m" |prin }
color\reset: does { esc "[0m" |prin }
color\red: does { esc "[31m" |prn }
color\default: does { esc "[39m" |prn }
color\reset: does { esc "[0m" |prn }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ chat-tui: context {
extend: fn { n c } { produce n "" { .concat c } }
line: fn1 { .extend "─" }

gradual-print: fn1 { .for { .prin , sleep 30 } }
gradual-print: fn1 { .for { .prn , sleep 30 } }

draw-box: fn { cols rows offset } {
right offset , "╭" |+ line cols + 3 |+ "╮" |print
Expand Down Expand Up @@ -49,21 +49,21 @@ chat-tui: context {
|pass { down 1 }
}

up: fn1 { .esc-val "[(*)A" |prin }
down: fn1 { .esc-val "[(*)B" |prin }
right: fn1 { .esc-val "[(*)C" |prin }
left: fn1 { .esc-val "[(*)D" |prin }
bold: does { esc "[1m" |prin }
reset: does { esc "[22m" |prin }
up: fn1 { .esc-val "[(*)A" |prn }
down: fn1 { .esc-val "[(*)B" |prn }
right: fn1 { .esc-val "[(*)C" |prn }
left: fn1 { .esc-val "[(*)D" |prn }
bold: does { esc "[1m" |prn }
reset: does { esc "[22m" |prn }

color\black: does { esc "[30m" |prin }
color\red: does { esc "[31m" |prin }
color\green: does { esc "[32m" |prin }
color\yellow: does { esc "[33m" |prin }
color\blue: does { esc "[34m" |prin }
color\magenta: does { esc "[35m" |prin }
color\cyan: does { esc "[36m" |prin }
color\white: does { esc "[37m" |prin }
color\default: does { esc "[39m" |prin }
color\reset: does { esc "[0m" |prin }
color\black: does { esc "[30m" |prn }
color\red: does { esc "[31m" |prn }
color\green: does { esc "[32m" |prn }
color\yellow: does { esc "[33m" |prn }
color\blue: does { esc "[34m" |prn }
color\magenta: does { esc "[35m" |prn }
color\cyan: does { esc "[36m" |prn }
color\white: does { esc "[37m" |prn }
color\default: does { esc "[39m" |prn }
color\reset: does { esc "[0m" |prn }
}
File renamed without changes.
41 changes: 41 additions & 0 deletions examples/examples-wip/shellbot/hello-rye.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

do load %chat-tui.rye

do\in chat-tui {

wiz: "Grumpy wizard"

wrap { print "" sleep 500 } {
color\red prn "## Hello Rye ##:" bold reset color\default
}

chat-lines { "This is a short Rye intro. What's your name?" }

name: input 36

chat-of "Hi " + name + ". Choose your subject:" wiz

choice { values "Rye values" hello-world "Hello world" functions "Functions" pipe-words "Pipe words" }

|switch {
hello {
chat-of "Yeeah!?" wiz
sleep 1000
chat-of "Can I help you with something?" wiz

seeking: input 36
either seeking .matches* regexp "magic" {
chat-of "And what would your name be?" wiz

name: input 36
chat-of "Yes, I can give you magic " + name + ", I'm tired of it anyway!" wiz
} {
chat-of "I only got some magic to spare, go away now ..." wiz
}
}
away {
chat-of "Yeah! ... you run back to your mommy!!" wiz
}
}
print ""
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

do load %chat-print.rye

do-in term {
do\in term {

choice { more "Izvedi več o tem" first "Prikaži prvo nalogo" }

Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/full-text-search/minimal.nogo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Go example

import "github.com/blevesearch/bleve/v2"

func main() {

mapping := bleve.NewIndexMapping()
index, err := bleve.New("example.bleve", mapping)

err = index.Index("elephant and a cat", "A mouse scared an elephant. A cat caught an mouse.")
err = index.Index("mouse and dog", "Cat was hunting for a mouse. A dog chased it away.")
err = index.Index("elephant and a dog", "Elephant looked at the dog. The dog looked at the cat.")

query := bleve.NewMatchQuery("dog")
search := bleve.NewSearchRequest(query)
searchResults, err := index.Search(search)
fmt.Println(searchResults)
}
17 changes: 17 additions & 0 deletions examples/full-text-search/minimal.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

; Rye example

rye .needs { bleve }

%minimal6.bleve :db
|open-bleve |fix { new-bleve-index-mapping .new-bleve db } :idx
;|index "elephant and a cat" "A mouse scared an elephant. A cat caught an mouse."
;|index "mouse and dog" "Cat was hunting for a mouse. A dog chased it away."
;|index "elephant and a dog" "Elephant looked at the dog. The dog looked at the cat."
|index "faq1" `{ "question": "Is cebelca.biz really free?", "answer": "Yes, it really is free", "keywords": "billing,free,expenses,newusers" }`
|index "faq2" `{ "question": "Can I fiscalize invoices with cebelca.biz?", "answer": "Yes, you can fiscalize invoices with online on mobile POS version.", "keywords": "fiscalisation,invoices" }`

bleve-search: fn { phrase idx } { new-match-query phrase |new-search-request |search idx |print }

enter-console "search"

37 changes: 37 additions & 0 deletions examples/full-text-search/with-mapping.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

; Rye example of bleve full-text-search - a simple search console

rye .needs { bleve }

private\ "console will run inside this context" {

private\ "opens or creates a bleve index and returns it" {
%demo8.bleve :db |open-bleve
|fix {
new-bleve-document-mapping :fqm
new-bleve-text-field-mapping :tfm

new-bleve-index-mapping :im
|add-document-mapping "faq" fqm
|add-field-mapping-at "question" tfm
|add-field-mapping-at "answer" tfm
|add-field-mapping-at "keywords" tfm

im .new-bleve db
}
} :idx
; we can index a JSON string
|index "presale1" ${ "q": "Is InvoiceFox really free?", "a": "Yes, our Mini plans are absolutely free.", "kw": "billing,free,plans" }$
|index "presale2" ${ "q": "Can I quit at any time?", "a": "Yes, and you can change packages at any time.", "kw": "billing,plans" }$
|index "integra1" ${ "q": "Can I integrate with Woocommerce? ", "a": "Yes, we have open source WP plugin on github.", "kw": "webshop,integration" }$
|index "integra2" ${ "q": "Can I integrate inventory and mobile POS?", "a": "Yes, mobile POS can affect and check the inventory.", "kw": "pos,integration" }$

; define two functions that we will be able to call in console
search: fn1 { .new-match-query |new-search-request :sr Search sr idx }
index: fn { id data } { Index idx id data }

; enter the Rye console
enter-console "you can index and search here"

}

36 changes: 36 additions & 0 deletions examples/full-text-search/with-mapping2.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@



; Rye example of bleve full-text-search - a simple search console

rye .needs { bleve }

private\ "console will run inside this context" {

private\ "opens or creates a bleve index and returns it" {
%demo12.bleve :db |open-bleve
|fix {
new-bleve-document-mapping :fqm
new-bleve-text-field-mapping :tfm

new-bleve-index-mapping :im
|add-document-mapping "faq" fqm
|add-field-mapping-at "q" tfm
|add-field-mapping-at "a" tfm

im .new-bleve db
}
} :idx
; we can index a JSON string
|index "qa1" `{ "q": "Where is Sevnica?", "a": "It's in Slovenia" }`
|index "qa2" `{ "q": "What is Slovenia?", "a": "It's a country" }`

; define two functions that we will be able to call in console
find: fn1 { .new-match-query |new-search-request :sr search sr idx }
index: fn { id data } { Index idx id data }

; enter the Rye console
enter-console "you can index and search here"

}

Loading

0 comments on commit 86c173a

Please sign in to comment.