Linux annoyances- turn off middle click to paste
It drives me crazy that my laptop pastes things with middle click. These commands fixed that up:
echo 'pointer = 1 25 3 4 5 6 7 8 9' > ~/.Xmodmap
xmodmap ~/.Xmodmap
Learning Prisma
One of my goals today is to learn about Prisma a node ORM for working with databases. I have a lot of experience with Active Recordwhich is Ruby on Railās ORM.
Iāve found Claude incredibly (!!) helpful in teaching me. I started with this message:
Can you give me a first lesson on prisma? I want just an overview of the main ideas and what I need to know as Iām using it. Only give a little bit at a time and ask when Iām ready for more.
It walked me through each concept and paused to let me ask questions (I had lots). Early on I told it that I had experience with Ruby on Rails and it altered its teaching to point out differences and explain similarities. SO GOOD.
A couple of things that I like about prisma:
- It generates a type safe client (this is stored in node_modules and normally you donāt look at it directly)
- The client doesnāt depend on any meta programming runtime magic (oh hiiiii ActiveRecord)
- It comes with a tool to explore data
- It comes with a set of tools to import a database directly
Things Iām not sure about yet (maybe cool?):
- You donāt generate migrations directly- you edit the schema and then run a command and prisma figures out (I had Claude explain what actually happens) how to create a migration. Hmmm
- The shape of the insert is a little weird it takes an object and you put the fields you want to insert on a
data
key. Itās a little clunky but itās ok
Things I worry about / wonder about:
- What if I want to keep all my data validation and protection logic in the datastore? Prisma seems very built around the application layer controlling the data buuuuuut databases very often outlive the first client that connects to them. Data is forever, apps come and go. So it makes sense to keep validation at that the datastore level
Environmental monitoring
Now that Iām back home Iām working on a workspace in my garage. Itās a nice space because it has tools (3D printing! hand tools! Crafting tools! computer bits!) but also Iām not sure if itās the healthiest air environment. I have a thermometer stuck to the wall and I can see the current temperature in here (72 as Iām writing). I want to build a little sensor to keep track of air quality.
It turns out thereās a great sensor for this- the BME680. It can read temperature, barometric pressure, humidity, and VOCās (which I think I can use to can estimate of CO2)? Itās relatively inexpensive too- about $15 each (I bought two I figure Iāll probably make a mistake while putting it together).
Iām going to use an ESP8266 with ESP home.
It looks like thereās some 3D printed cases that folks have already designed:
So I think Iāll just need to print a case, program the chip, and then Iāll be able to access the sensor data. Thereās also POE in this space so I think Iāll use a breakout from POE to usb and then itāll be always powered.
Maybe a dashboard would be useful but thatās another project after I see how this works.
Dashboard
If I did have a dashboard in this space I would want to know:
- Current weather outside (there arenāt any windows here)
- Camera of the space I exit into
- Temperature / Humidity / Pressure
- Air Quality
Light display
I have an Adafruit Matrix Displaythat I got sometime during the pandemic. In the RC hub in NYC thereās a display that shows off cool effects on a loop. And I could do something like that too!
But to get started with somebody made a clock that shows moon information: https://learn.adafruit.com/moon-phase-clock-for-adafruit-matrixportal/
I put that together and now I can see the time and how long until the moon rises again (just over an hour and a half):
Maybe for my next creative code thing Iāll write something for the display rather than the web?
Things about this space that bother me
- The lights are very bright and very very daylight white.
- Maybe I could make a diffuser with the 3D printer
- Maybe I could use nice strips
- I canāt tell whatās going on outside
- Maybe a camera outside the door?
- The desk is really a work bench has a rough edge
- Maybe I could router over it?
Contact app
My contact app (source code)is done. You can contact me on the web and I donāt have to use Google forms or Jot or anything that costs money. It mostly fits in with the style of my notes.
This was a good project because it got me to work on a whole bunch of server stuff:
- Thereās a database! Itās Postgres! Iām not using any tricky features of that!
- It has login for a very simple admin panel
- It notifies me via Pushover when a new message arrives
- Itās hosted on my dokkuinstance and deploys via a git push
- It supports devcontainers for getting up and running really quickly
Iām feeling more comfortable with the workflow of building things in node. I feel like the view layer and templating is a little bit of a disaster and I definitely wish there was a way to scaffold things but it at least feels workable and understandable.
Euler
Todayās Euler problem is to find the first fibonacci number that has more than 1,000 digits. Hereās my solution:
const result = takeUntil(
fibonachi(),
n => n.toString().length === 1000)
.length + 1
console.log(result)
I learned a couple of things today:
- Javascript has the ability to work with big numbers but you have to ask it to. You can make something into a bigIntby putting an
n
at the end so123n
is a big int. Knowing that let me modify my fibonacci generator like this:
export function* fibonachi(): Generator<bigint> {
let prev = 0n
let current = 1n
while (true) {
yield current
const next = current + prev
prev = current
current = next
}
}
I also discovered that I was only yielding 1 once. Eeek! I fixed that too. (And added an explicit return type because itās always a BigInt now)
Lion Clicker
Frontend:
- React with TypeScript
- Redux for state management
- WebSocket client for real-time updates
- Served as static files by backend in production
Backend:
- Fastify with TypeScript
- @fastify/websocket for real-time communication
- @fastify/static to serve frontend
- Mongoose for MongoDB interactions (good TypeScript support with clear schema types)
Infrastructure:
- Monorepo structure for simplicity
- Backend serves frontend
- Deployed to Dokku with single git push
- WebSocket over WSS for secure real-time communication
Project Structure:
/game
/client
- React/Redux code
- TypeScript configs
/server
- Fastify code
- Mongoose schemas
- TypeScript configs
/shared
- Types shared between client/server
- Game constants
- Utility functions
package.json
Procfile # For Dokku
Development:
- Local frontend dev server (port 3000)
- Local backend server (port 8000)
- TypeScript throughout for type safety
- Shared types between frontend/backend
Production:
- Single Dokku app
- Backend serves API, WebSocket, and frontend static files
- Dokku handles SSL, domains, etc
- Simple git-push deployment
Optimized for:
- Developer experience (TypeScript everywhere)
- Simple deployment
- Easy local development
- Type safety across full stack
- Real-time game state updates
- Solo developer productivity
Lion Clicker
code: https://github.com/nicolecomputer/lion-clicker deployed: https://clicker.lion.computer/
I went with a monorepo. I have a fastify server and a vite-powered react server. I feel like this gives me a lot of power- I get live reload on both. One thing that doesnāt feel great is that thereās a flash as soon as navigating to the page because react is initiating. Maybe iāll figure out fixing that later.
End of day
It was my first day in my space in Colorado. I felt really wired into building but was missing the serendipity of the hub (and also the people).
Worked on Today
- I finished my contact form project! I have a contact form up and live which I will link to from a bunch of places (friend presentation, professional page, notes, the optimist homepage). Live: https://contact.lion.computer/ Code: https://github.com/nicolecomputer/contact/
- I did this mostly as a skills building project and ohhhhh yes I learned a lot. I got familiar with prisma (an ORM kind of like ActiveRecord), Fastify (a replacement for express- the server), and the API for pushover (push notifications when I get a message)
- The design takes colors and fonts from nicole.computer
- I started on lion clicker (probably my next big project). It will be an autoclicker. I got the monorepo going today and have a server and a react client. Itās live, if very bare at: https://clicker.lion.computer
- I fussed with Electronics
- Iām building an environmental monitor for my space. Itās an ESP8266 running ESPHome and will have a sensor for temp, humidity, pressure and air quality
- I setup a grid of pixels with the phase of the moon. Itās not quite the sign from the hub but it makes me feel closer to NY
- I did a Euler problem: https://github.com/nicolecomputer/euler/blob/main/025/main.ts
I wrote A LOT today, hereās my journal page if you want to peep all the details: https://notes.nicole.computer/daily/2024-11-24
Tomorrow
I want to be heads down tomorrow. Iāve LOVED the social time in the hub. Iām also craving some time thinking about problems. Tomorrow!
- I want to build the environmental sensor. Itāll be some 3D printing, some soldering, some flashing firmware and a little configuration
- I want to get web sockets working on lion clicker and probably get state management going on the frontend