Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed May 29, 2019
2 parents 55d59b4 + c474042 commit 598abcf
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: 2
jobs:
test:
docker:
- image: circleci/golang:1.12
environment:
GO111MODULE: "on"
steps:
- checkout
- run:
name: Working Test
command: |
set -x
go build -o fakelish main/main.go
# Just print English-like words
./fakelish
build:
docker:
- image: circleci/golang:1.12
environment:
GO111MODULE: "on"
DIST: "/go/dist"
steps:
- checkout
- run:
name: Build
command: |
set -x
mkdir $DIST
# (from: https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04)
platforms=("linux/amd64" "darwin/amd64" "windows/amd64")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
export GOOS=${platform_split[0]}
export GOARCH=${platform_split[1]}
BUILD_PATH=fakelish-$GOOS-$GOARCH
mkdir $BUILD_PATH
# Build
go build -o $BUILD_PATH/fakelish main/main.go
# Create .zip
zip -r $DIST/$BUILD_PATH.zip $BUILD_PATH
# Create .tar.gz
tar zcvf $DIST/$BUILD_PATH.tar.gz $BUILD_PATH
done
- persist_to_workspace:
root: /go/dist
paths:
- .

github_release:
docker:
- image: cibuilds/github:0.10
steps:
- attach_workspace:
at: /go/dist
- run:
name: Publish Release on GitHub
command: |
VERSION=$CIRCLE_TAG
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} /go/dist
workflows:
version: 2
build:
jobs:
- test :
filters:
tags:
only: /.*/
- build :
filters:
tags:
only: /.*/
- github_release:
requires:
- test
- build
filters:
tags:
only: /.+/
branches:
ignore: /.*/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Ryo Ota

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# fakelish
[![CircleCI](https://circleci.com/gh/nwtgck/go-fakelish.svg?style=shield)](https://circleci.com/gh/nwtgck/go-fakelish)

## Install
Executable binaries are available in [GitHub Releases](https://github.com/nwtgck/go-fakelish/releases)

## Usage

```bash
$ fakelish -h
English-like word generator

Usage:
fakelish [flags]

Flags:
--capitalize capitalize the first letter (default true)
-h, --help help for fakelish
--max int max length of fake word (default 9)
--min int min length of fake word (default 6)
-n, --n-words int number of fake words (default 10)

```

## Examples

```bash
$ fakelish
Lebuffic
Caming
Unizans
Nantilien
Losychle
Deping
Subsce
Shemon
Unhyle
Reighthes
```
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
40 changes: 40 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"fmt"
"github.com/nwtgck/go-fakelish"
"github.com/spf13/cobra"
"os"
"strings"
)

var minLength int
var maxLength int
var nWords int
var enableCapitalize bool

func init() {
cobra.OnInitialize()
RootCmd.Flags().IntVar(&minLength, "min", 6, "min length of fake word")
RootCmd.Flags().IntVar(&maxLength, "max", 9, "max length of fake word")
RootCmd.Flags().IntVarP(&nWords, "n-words", "n", 10, "number of fake words")
RootCmd.Flags().BoolVar(&enableCapitalize, "capitalize", true, "capitalize the first letter")
}

var RootCmd = &cobra.Command{
Use: os.Args[0],
Short: "fakelish",
Long: "English-like word generator",
Run: func(cmd *cobra.Command, args []string) {
for i := 0; i < nWords; i++ {
// Generate a fake word
fakeWord := fakelish.GenerateFakeWord(minLength, maxLength)
if enableCapitalize {
// Capitalize the first letter
fakeWord = strings.Title(fakeWord)
}
// Print the fake word
fmt.Println(fakeWord)
}
},
}
63 changes: 63 additions & 0 deletions fakelish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fakelish

import (
"math/rand"
"strings"
"time"
)

var random = rand.New(rand.NewSource(time.Now().UnixNano()))

func GenerateFakeWordWithUnexpectedLength() string {
maxSeq := 2 // TODO: Hard code
ch := "^"
fakeWord := ""
var chrs []string
for ch != "END" {
chrs = append(chrs, ch)
if len(chrs) > maxSeq {
chrs = chrs[1:]
}
var nextAccumedProbs []AccumedProb = nil
n := 0
for {
str := strings.Join(chrs[n:], "")
nextAccumedProbs = WordProbability[str]
n += 1
if !(nextAccumedProbs == nil && n < len(chrs)) {
break
}
}
nextCh := ""
r := random.Float32()
for _, x := range nextAccumedProbs {
candidateNextCh := x.Ch
prob := x.Prob
if r <= prob {
nextCh = candidateNextCh
break
}
}
if nextCh != "END" {
fakeWord += nextCh
}
ch = nextCh
}
return fakeWord
}

func GenerateFakeWordByLength(length int) string {
fakeWord := ""
for len(fakeWord) != length {
fakeWord = GenerateFakeWordWithUnexpectedLength()
}
return fakeWord
}

func GenerateFakeWord(minLength int, maxLength int) string {
fakeWord := ""
for !(minLength <= len(fakeWord) && len(fakeWord) <= maxLength) {
fakeWord = GenerateFakeWordWithUnexpectedLength()
}
return fakeWord
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/nwtgck/go-fakelish

go 1.12

require github.com/spf13/cobra v0.0.4
32 changes: 32 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.4 h1:S0tLZ3VOKl2Te0hpq8+ke0eSJPfCnNTPiDlsfwi1/NE=
github.com/spf13/cobra v0.0.4/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
14 changes: 14 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"github.com/nwtgck/go-fakelish/cmd"
"os"
)

func main () {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}
8 changes: 8 additions & 0 deletions word_probability.go

Large diffs are not rendered by default.

0 comments on commit 598abcf

Please sign in to comment.