Skip to content

Commit

Permalink
Make code client only
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Nov 26, 2024
1 parent c2b5081 commit b0f6784
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
44 changes: 44 additions & 0 deletions api/cmd/experiments/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"bytes"
"context"
"encoding/csv"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand All @@ -13,6 +15,10 @@ import (
"sync"
"time"

"firebase.google.com/go/auth"
"github.com/NdoleStudio/httpsms/pkg/telemetry"
"google.golang.org/api/iterator"

"github.com/palantir/stacktrace"

"github.com/NdoleStudio/httpsms/pkg/di"
Expand All @@ -33,9 +39,47 @@ func main() {
container := di.NewLiteContainer()
logger := container.Logger()

authClient := container.FirebaseAuthClient()

var users []*auth.ExportedUserRecord
iter := authClient.Users(context.Background(), "")
for {
user, err := iter.Next()
if errors.Is(err, iterator.Done) {
break
}
if err != nil {
logger.Fatal(err)
}
users = append(users, user)
}

logger.Info(fmt.Sprintf("fetched %d users", len(users)))
exportUsers(logger, users)

logger.Info("Starting experiments")
}

func exportUsers(logger telemetry.Logger, users []*auth.ExportedUserRecord) {
records := [][]string{
{"First name", "Email address", "External ID"},
}

for _, user := range users {
records = append(records, []string{user.UserInfo.DisplayName, user.UserInfo.Email, user.UserInfo.UID})
}

file, err := os.Create("result.csv")
if err != nil {
logger.Fatal(stacktrace.Propagate(err, "cannot create file"))
}

w := csv.NewWriter(file)
if err = w.WriteAll(records); err != nil {
logger.Fatal(stacktrace.Propagate(err, "cannot write csv"))
}
}

func chunkBy[T any](items []T, chunkSize int) (chunks [][]T) {
for chunkSize < len(items) {
items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
Expand Down
56 changes: 29 additions & 27 deletions web/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
<v-container>
<v-row class="mt-16 pt-8 mb-n8">
<v-col>
<v-alert
text
:icon="$vuetify.breakpoint.mdAndUp ? mdiSale : undefined"
:prominent="$vuetify.breakpoint.mdAndUp"
color="success"
>
<v-row align="center">
<v-col class="grow">
<p class="text-h6 mb-0">Black Friday Deal</p>
<p class="mb-0">
Get <b>40%</b> off all yearly plans on httpSMS until on
December 2<sup>nd</sup> by using the discount code
<b>BF2024</b> at checkout
</p>
<v-btn
v-if="!$vuetify.breakpoint.mdAndUp"
to="/billing"
block
color="pink"
>Upgrade Now</v-btn
>
</v-col>
<v-col v-if="$vuetify.breakpoint.mdAndUp" class="shrink">
<v-btn color="pink" to="/billing">Upgrade Now</v-btn>
</v-col>
</v-row>
</v-alert>
<client-only>
<v-alert
text
:icon="$vuetify.breakpoint.mdAndUp ? mdiSale : undefined"
:prominent="$vuetify.breakpoint.mdAndUp"
color="success"
>
<v-row align="center">
<v-col class="grow">
<p class="text-h6 mb-0">Black Friday Deal</p>
<p class="mb-0">
Get <b>40%</b> off all yearly plans on httpSMS until on
December 2<sup>nd</sup> by using the discount code
<b>BF2024</b> at checkout
</p>
<v-btn
v-if="!$vuetify.breakpoint.mdAndUp"
to="/billing"
block
color="pink"
>Upgrade Now</v-btn
>
</v-col>
<v-col v-if="$vuetify.breakpoint.mdAndUp" class="shrink">
<v-btn color="pink" to="/billing">Upgrade Now</v-btn>
</v-col>
</v-row>
</v-alert>
</client-only>
</v-col>
</v-row>
<v-row :class="{ 'pb-16 pt-0': $vuetify.breakpoint.lgAndUp }">
Expand Down

0 comments on commit b0f6784

Please sign in to comment.