Skip to content

Instantly share code, notes, and snippets.

@zacharysyoung
Last active May 27, 2019 08:47
Show Gist options
  • Save zacharysyoung/c4cbbad2af58133ddd190ea59aabcc83 to your computer and use it in GitHub Desktop.
Save zacharysyoung/c4cbbad2af58133ddd190ea59aabcc83 to your computer and use it in GitHub Desktop.
Permutate punctuation (dots) for test email name
package main
/*
Got the idea from https://learn.lytics.com/understanding/product-docs/lytics-javascript-tag/testing-and-verification#testing-audiences
Given an input of "test", makes:
t.e.s.t.@gmail.com
t.e.s.t@gmail.com
t.e.st.@gmail.com
t.e.st@gmail.com
t.es.t.@gmail.com
t.es.t@gmail.com
t.est.@gmail.com
t.est@gmail.com
te.s.t.@gmail.com
te.s.t@gmail.com
te.st.@gmail.com
te.st@gmail.com
tes.t.@gmail.com
tes.t@gmail.com
test.@gmail.com
test@gmail.com
This list gets exponentially big--7 letters in the name = 128 versions of the
name--so make sure to redirect to a file (I picked a CSV extension so
the list can be loaded and tracked in Excel):
./make_test_gmails test > test_gmails.csv
*/
import (
"fmt"
"os"
"strings"
)
func permutatePuncs(s string, _len int, puncs []string) []string {
if len(s) == _len {
puncs = append(puncs, s)
return puncs
}
puncs = permutatePuncs(s+".", _len, puncs)
// Encode a space (" ") as a place-holder for "not-punctuated", e.g.,
// ['.. .', '. . ', ' . .']
puncs = permutatePuncs(s+" ", _len, puncs)
return puncs
}
func main() {
name := os.Args[1]
_len := len(name)
puncSets := permutatePuncs("", _len, make([]string, 0))
letters := strings.Split(name, "")
punctuatedNames := make([]string, 0)
for _, puncSet := range puncSets {
puncFields := strings.Split(puncSet, "")
puncNameFields := make([]string, 0)
for i := 0; i < _len; i++ {
puncLetter := strings.TrimSpace(letters[i] + puncFields[i])
puncNameFields = append(puncNameFields, puncLetter)
}
punctuatedNames = append(
punctuatedNames, strings.Join(puncNameFields, "")+"@gmail.com")
}
for _, punctuatedName := range punctuatedNames {
fmt.Println(punctuatedName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment