-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 4e85ed2
Showing
6 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## OS stuff | ||
.DS_Store | ||
|
||
## IDE stuff | ||
.idea | ||
|
||
## Output | ||
out/ |
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,44 @@ | ||
# SPoNgEBoB | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fcalini%2Fspongebob.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fcalini%2Fspongebob?ref=badge_shield) | ||
|
||
Simple project for converting normal text to sPonGeBOb tExT | ||
|
||
It uses _CUTTING EDGE™_ technology like *MARKOV CHAINS* to generate REALISTICⓇ SPonGeBoB text.️ | ||
|
||
## Getting it | ||
```sh | ||
go get -u github.com/calini/spongebob | ||
``` | ||
|
||
## Using the CLI | ||
|
||
```sh | ||
spongebob "hello world" | ||
> hELlO wOrlD | ||
``` | ||
|
||
## Building it manually | ||
```sh | ||
go build -o ./spongebob | ||
|
||
./spongebob "hello world" | ||
> hELlO wOrlD | ||
``` | ||
|
||
## Using it as a library | ||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/calini/spongebob" | ||
) | ||
|
||
func main() { | ||
fmt.Println(spongebob.Text("Hello world!")) | ||
} | ||
``` | ||
|
||
|
||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fcalini%2Fspongebob.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fcalini%2Fspongebob?ref=badge_large) |
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,3 @@ | ||
module github.com/calini/spongebob | ||
|
||
go 1.13 |
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,26 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"github.com/calini/spongebob/spongebob" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
// if string passed as param, return them | ||
if len(os.Args) >= 2 { | ||
for i := range os.Args { | ||
os.Args[i] = spongebob.Text(os.Args[i]) | ||
} | ||
print(strings.Join(os.Args[1:], " ")) | ||
os.Exit(0) | ||
} | ||
|
||
// else, get stdin | ||
scanner := bufio.NewScanner(os.Stdin) | ||
for scanner.Scan() { | ||
fmt.Println(spongebob.Text(scanner.Text())) | ||
} | ||
} |
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 @@ | ||
package spongebob | ||
|
||
import ( | ||
"bytes" | ||
"math/rand" | ||
"time" | ||
"unicode" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
} | ||
|
||
// Text transforms a normal string into A spOnGEbOb sTrINg | ||
func Text(str string) string { | ||
var result bytes.Buffer | ||
upper := false | ||
|
||
for _, c := range str { | ||
if unicode.IsLetter(rune(c)) { | ||
// instead of flipping a coin every time, | ||
// we create a poor man's Markov chain | ||
if rand.Float32() < 0.6 { | ||
upper = !upper | ||
} | ||
|
||
if upper { | ||
c = unicode.ToUpper(rune(c)) | ||
} else { | ||
c = unicode.ToLower(rune(c)) | ||
} | ||
} | ||
result.WriteRune(c) | ||
} | ||
|
||
return result.String() | ||
} |
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 @@ | ||
package spongebob | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// TestText checks that transformation is happening without ruining context | ||
func TestText(t *testing.T) { | ||
input := "Hello world!" | ||
result := Text(input) | ||
|
||
if !strings.EqualFold(input, result) { | ||
t.Errorf("Should have same content except capitalisation: \"%s\" - \"%s\"", input, result) | ||
} | ||
} |