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
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MainApp()); | |
} | |
class MainApp extends StatelessWidget { | |
const MainApp({super.key}); |
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
String updateGuessState(String correctWord, String guessState, String guess) { | |
// Update the guess state to account for the latest guessed letter. | |
var newGuessState = ''; | |
for (var i = 0; i < correctWord.length; i++) { | |
if (correctWord[i] == guess) { | |
newGuessState += guess; | |
} else { | |
newGuessState += guessState[i]; | |
} | |
} |
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
FROM elixir:1.11.1-alpine AS build | |
# install build dependencies | |
RUN apk add --no-cache build-base npm git | |
# prepare build dir | |
WORKDIR /app | |
# install hex + rebar | |
RUN mix local.hex --force && \ |
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
func TestIndex(t *testing.T) { | |
req, err := http.NewRequest(http.MethodGet, "/", nil) | |
if err != nil { | |
t.Fatalf("TestIndex: couldn't create HTTP GET request: %v", err) | |
} | |
rec := httptest.NewRecorder() | |
index().ServeHTTP(rec, req) |
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
// public serves static assets such as CSS and JavaScript to clients. | |
func public() http.Handler { | |
return http.StripPrefix("/public/", http.FileServer(http.Dir("./public"))) | |
} |
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
{{define "base"}} | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" | |
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="shortcut icon" type="image/x-icon" href="/public/assets/images/favicon.ico"> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Work+Sans:400,500,600,700"> |
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
// templates references the specified templates and caches the parsed results | |
// to help speed up response times. | |
var templates = template.Must(template.ParseFiles("./templates/base.html", "./templates/body.html")) | |
// index is the handler responsible for rending the index page for the site. | |
func index() http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
b := struct { | |
Title template.HTML | |
BusinessName 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
// logging is middleware for wrapping any handler we want to track response | |
// times for and to see what resources are requested. | |
func logging(next http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
start := time.Now() | |
req := fmt.Sprintf("%s %s", r.Method, r.URL) | |
log.Println(req) | |
next.ServeHTTP(w, r) | |
log.Println(req, "completed in", time.Now().Sub(start)) | |
}) |
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
func main() { | |
mux := http.NewServeMux() | |
mux.Handle("/public/", logging(public())) | |
mux.Handle("/", logging(index())) | |
port, ok := os.LookupEnv("PORT") | |
if !ok { | |
port = "8080" | |
} |
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
c, err := db.Collection(collName).Find(ctx, bson.D{}) | |
if err != nil { | |
return fmt.Errorf("readTasks: couldn't list all to-dos: %v", err) | |
} | |
defer c.Close(ctx) | |
tw := tabwriter.NewWriter(os.Stdout, 24, 2, 4, ' ', tabwriter.TabIndent) | |
_, _ = fmt.Fprintln(tw, "ID\tCreated At\tModified At\tTask\t") | |
for c.Next(ctx) { | |
elem := &bson.D{} | |
if err = c.Decode(elem); err != nil { |
NewerOlder