-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
734 additions
and
4,623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | ||
} |
2 changes: 1 addition & 1 deletion
2
examples/shellbot/main.rye → examples/examples-wip/shellbot/main.rye
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
} | ||
|
Oops, something went wrong.