Commit graph

1264 commits

Author SHA1 Message Date
William Carroll
7e2dcc97cc Drop support for wpc/find-file
Cleaning things up...
2020-08-20 11:26:31 +01:00
William Carroll
56b503c573 Prefer direnv's use_nix to shell.nix
I find it bothersome to share the list of Haskell dependencies between my
default.nix and shell.nix files. A few days ago, I created a THIRD file,
shared.nix, that defined the shared code b/w default.nix and shell.nix. This
DRY'd things up, but it also added a new file, which I didn't like.

Today I learned that direnv integrates with Nix using a function called
`use_nix`. Voila! I typically already have .envrc files per-project, so this
doesn't add any unnecessary files, and it allows me to delete my shell.nix
files.

I would use `lorri`, except that I encountered issues using Lorri on my work
computer, which I'm not interested in attempting to resolve now.
2020-08-20 11:26:31 +01:00
William Carroll
b984a2d1e0 Change GET /mimi to GET /hello
Timing myself to see how long it takes me to publish a change.
2020-08-20 11:26:31 +01:00
William Carroll
d903afeb54 Define the monoserver as a systemd service
Much better than manually running:

```shell
$ cd ~/briefcase && git pull --rebase origin master
$ nix-rebuild switch
$ nix-build -A zoo
$ pkill zoo
$ ./result/zoo &
$ job -l
$ disown %<job-number>
```
2020-08-20 11:26:31 +01:00
William Carroll
ace08853e0 Add GET /mimi to zoo
Proving to my girlfriend that the zoo works.
2020-08-20 11:26:31 +01:00
William Carroll
309c5452e1 Add host field for nginx JSON logs
I'd like to filter logs from {blog,git,zoo}.wpcarro.dev, etc.
2020-08-20 11:26:31 +01:00
William Carroll
979cbda33c Remove logging prefix from Nginx logs
Problem: The JSON that Nginx outputs cannot be successfully parsed by
journaldriver because Nginx prefixes it with "socrates nginx:". Adding
`nohostname` to `access_log` should solve this problem.

I borrow this from @tazjin's most recent definition of `commonHttpConfig`.
2020-08-20 11:26:31 +01:00
William Carroll
2eb52379b6 Use journaldriver to view journald logs from Socrates
Attempting to use @tazjin's delightful simple logging library!
2020-08-20 11:26:31 +01:00
William Carroll
4a836f363b Disabling the monzo-token-server
I haven't used this since I wrote it... and now the .tokens attribute is missing
and it's screwing up my other deployment... *sigh*
2020-08-20 11:26:31 +01:00
William Carroll
0b34482b6d Forward zoo.wpcarro.dev connections to :8000
Right now the 8000 port is hard-coded into the zoo server, which isn't ideal,
but "it works" (TM).
2020-08-20 11:26:31 +01:00
William Carroll
f895cb417a Move shift-time into top-level //zoo
I'm still unsure whether or not this is a good idea, but experimenting is a good
way to find out!
2020-08-20 11:26:31 +01:00
William Carroll
3fdfa14355 Support parsing and shifting time
TL;DR:
- Adds string-conversions library
- Adds tests for remaining units and repeating requests
- Adds a REPL in main
2020-08-20 11:26:31 +01:00
William Carroll
5fd79ce0ff Support parsing second shifts
Parse inputs like -10s into 10 second shifts back in time.
2020-08-20 11:26:30 +01:00
William Carroll
81aa32fe71 Support POST /create-payment-intent
Interact with Stripe's payment_intents API endpoint.

I'm not committing the index.html that contains client-side code that interacts
with the /create-payment-intent endpoint, but it contains sensitive information,
so I'm omitting it for now.

TL;DR:
- Define POST /create-payment-intent endpoint
- Include envStripeAPIKey in Context record
- Define a top-level Stripe module for making API calls
- Define types and instances that align with Stripes request and response types
- Depend on the Req library: a higher-level library than http-client
2020-08-20 11:26:30 +01:00
William Carroll
de723c142b Prefer project.el to projectile
Today @tazjin told me about Emacs's built-in project.el library, which he
recommended that I extend to support monorepo-specific tooling. It worked like a
charm!

Now when I press "<leader>f", it will resolve to either the nearest file named
default.nix or directory name .git.
2020-08-13 18:05:45 +01:00
William Carroll
994a632ac3 Set Emacs current-project to ~/briefcase
I don't rely on this often, so it's best to leave it as the top-level directory
for briefcase.
2020-08-13 18:04:54 +01:00
William Carroll
a4caaba901 Document ghcExtensions argument
Missed documenting this the first time...
2020-08-13 18:04:33 +01:00
William Carroll
2da4b12266 Consume buildHaskell functions
Use the newly defined `buildHaskell` function for a few of my existing Haskell
projects. So far, it works as intended!
2020-08-12 16:28:39 +01:00
William Carroll
4ea55dd013 Support buildHaskell
Use Nix and Briefcase to easily create Haskell executables.

I'd eventually like to support something like: briefcase.buildHaskell.project
that let me define a few top-level values (e.g. ghcExtensions) and would give me
a ghci environment with the proper `.ghci` settings so that my development
environment mirrored my build environment... baby steps, though.
2020-08-12 16:26:17 +01:00
William Carroll
869a20f482 Define alias for cd-ing to ~/briefcase
Small but useful alias.
2020-08-12 14:24:24 +01:00
William Carroll
bba3f16c43 Prefer snake-shift instead of a row-by-row shift
Per the assignment's instructions, the `Shift n` operation should treat
the *entire keyboard* like a cycle and shift that. I was erroneously
treating *each row* like a cycle and shifting those one-by-one.

This change fixes that. In addition, it also:
- Updates README.md with expected inputs and outputs
- Updates test suite
- Adds `split` dependency to {default,shell}.nix
2020-08-12 12:03:35 +01:00
William Carroll
f11b91c985 Adds property tests to generically test keyboard transformations
Tests:
- HorizontalFlip
- VerticalFlip
- Shift n
2020-08-12 11:27:06 +01:00
William Carroll
f3ddd89302 Prefer literal, not computed, examples in the unit tests
TL:DR:
- Remove unused imports: Test.QuickCheck and Control.Exception
- Remove calls to `reverse` and `Utils.rotate` with their results
2020-08-12 11:07:37 +01:00
William Carroll
3d6130c7cf Provide more useful instructions for building this project
TL;DR:
- include a default.nix to allow users to build an named executable
- emphasize in the README that the user needs Nix to build this project
- pin nixpkgs to a specific commit and fetch it from GitHub
2020-08-12 10:28:04 +01:00
William Carroll
17e1764ef8 Generate coords function from existing qwerty keyboard
Per my take-home assignment's reviewer's comments, with which for the record I
agree, I should generate the character->coordinate table from my existing qwerty
keyboard definition.

The best part is: by doing this I found a bug: Notice how the original '0'
character was mapped to the Coordinate (0,0)... thus every subsequent digit
key (i.e. the first row) is off-by-one.
2020-08-12 09:46:36 +01:00
William Carroll
4ff1ea291c Drop support for ServantT transformer type for server
After burning a few hours wrestling with the type system, I decided to revert to
the simpler `Server API` type instead of the `ServantT` transformer type.

The problem is that I couldn't write a MonadError instance for `RIO Context`,
which is my `AppM` (i.e. application monad). Using `throwIO` in the server
handlers results in 500 errors, which is not what I wanted. I'm still pretty
fuzzy about what's happening; I now know that exception handling in Haskell is
pretty gnaryly. I may revisit this at a later time when my knowledge is more
extensive. For now: time to fry bigger fish.

An easier abstract is for me to pass `T.Context` into `server` as an argument,
which after all is what a Reader does.

TL;DR:
- Read server, client ports from .envrc
- Define a top-level Failure type (empty for now)
- Define a top-level Success type
- Define App as RIO Context (Either Failure Success)
2020-08-10 15:02:05 +01:00
William Carroll
f61ed25755 Prefer ServantT for server to consume App context
Long story -> short: I'd like to access my App monad from within my Servant
handlers.

While this code type-checks, I'm not sure it's working as intended. Needing to
change throwError to throwIO fails the "smell test". I expect to refactor this
code, but I'm calling it a night for now.
2020-08-09 23:15:12 +01:00
William Carroll
bbcd0bf27d Replace Prelude with RIO
I believe RIO stands for: "ReaderT <something-something> IO", which is a nod to
the top-level application data type:

```haskell
-- This is a simplification
newtype RIO env a = RIO { runRIO :: ReaderT env a () }
```

I read about RIO from an FP-Complete blog post a few months ago, and now I'm
excited to try it out for a real project. Bon voyage!
2020-08-09 22:17:19 +01:00
William Carroll
7d85ba559d Move Haskell-related shell.nix code into its own shell.nix
I'm getting tired of:

```shell
$ cd <project-root>
$ nix-shell
$ cd src/server
$ ghci Main.hs
```

Instead:

```shell
$ cd <project-root>/src/server
$ ghci Main.hs
```
2020-08-09 22:11:39 +01:00
William Carroll
26b7237aab Sketch database schema
Defining a few tables in init.sql to sketch a few records that I need to
persist.
2020-08-09 10:22:12 +01:00
William Carroll
9df2b49afd Initialize a default.nix for nix-build
As the previous commit mentions, I'm attempting to build and deploy this project
with `nix-shell` and `nix-build` instead of `cabal` and `stack`.

I'm in the Hamburg airport right now, and my internet connection isn't stable
enough to test this, so I'm committing it until I can more robustly test it.
2020-08-09 10:19:36 +01:00
William Carroll
119c8e9df9 Add common language extensions to .ghci
I'd like to see if I can avoid using `cabal` and `stack` and build and deploy
this application using `nix-shell` and `nix-build` only. Let's see how that
goes.
2020-08-09 10:18:46 +01:00
William Carroll
e8f35f0d10 Consume GoogleSignIn.validateJWT
TL;DR:
- Consume GoogleSignIn.validateJWT in the Handler for /verify
- Rename validation fn to validateJWT
- Prefer Text to String type
2020-08-08 17:57:11 +01:00
William Carroll
8a7a3b29a9 Add tests for "exp" field of the JWT
Assert that the exp field of the JWT is "fresh".
2020-08-08 14:47:39 +01:00
William Carroll
f1883b2790 Test that the JWT's iss field meets our expectations
The JWT should match "accounts.google.com" or "https://accounts.google.com". If
it doesn't, we produce a validation error.

TL;DR:
- Group all failed stringOrURI function calls as StringOrURIParseFailure errors
2020-08-08 14:08:11 +01:00
William Carroll
526728eb89 Test that an improperly encoded JWT returns a DecodeError
The subject of this commit message says it all.
2020-08-08 13:46:57 +01:00
William Carroll
d34b146702 Tests valid and invalid JWTs for the "aud" field
Test that when the JWT contains the client ID for my Google app, the JWT is
valid, and when it doesn't, it's invalid.
2020-08-08 13:44:22 +01:00
William Carroll
926d8e643e Update jwtIsValid API to return IO Bool
I need IO for:
- Getting the current time to validate `exp`
- Making an HTTP request to Google's token verifier endpoint
2020-08-08 11:18:49 +01:00
William Carroll
3eaf6e5aea Remove redundant deps from API.hs
Thank you, -Wall. You are truly an unsung hero.
2020-08-08 11:10:28 +01:00
William Carroll
7b8ec4170a Begin work for supporting GoogleSignIn server-side
I'm attempting to be an obedient boy and implement this and future features
using TDD.

TL;DR:
- Defined a few tests
- Defined an empty GoogleSignIn module
- Defined a Fixtures module to quickly create JWTs to test
2020-08-08 11:10:19 +01:00
William Carroll
9dcbd0d067 Define Utils module
Dumping grounds for personal, stylistic functions intended to improve readabily
and writability (in that order).
2020-08-08 11:06:53 +01:00
William Carroll
a7ddb56b9b Support echo server to test POST /verify
TL;DR:
- Add common dependencies like Servant, Aeson, Warp, Cors
- Define a POST /verify endpoint for our client to hit
- POST to /verify client-side onSignIn
2020-08-06 22:23:06 +01:00
William Carroll
1fc1087014 Support Google Sign-in client-side
TODO: Support Google Sign-in server-side

Also:
- Add Haskell to project's shell.nix
- Add stubbed Main.hs and Spec.hs
- Add common .ghci file
2020-08-06 21:54:25 +01:00
William Carroll
5f52077492 Re-type type using the altered keyboard
Remember: always read the instructions; that's the most important part.
2020-08-06 00:18:44 +01:00
William Carroll
e14fff7d4b Support Transforms.optimize
Partially optimize inputs and document rules for further optimizations we can
make.
2020-08-06 00:15:31 +01:00
William Carroll
d45685e245 Apply a series of transformation to a QWERTY keyboard
TL;DR:
- Accept input from the CLI
- Add a project README.md
2020-08-05 23:36:04 +01:00
William Carroll
244503bba9 Support App.transform
Apply the transform to a Keyboard. Onwards to the final demonstration!
2020-08-05 23:21:08 +01:00
William Carroll
61a2fb108d Support parsing the list of transforms
Using Haskell's Text.ParserCombinators.ReadP library for the first time, and I
enjoyed it thoroughly! It's nice avoiding a third-party library like MegaParsec.
2020-08-05 22:54:50 +01:00
William Carroll
d948ed9ebf Define an instance for Show for a Keyboard
This will help me debug.
2020-08-05 21:52:10 +01:00
William Carroll
1af0007a7d Create a Utils module
To stylize things...
2020-08-05 21:51:55 +01:00