AI Coding
so many tokens
- tags
Ok boomer, is your laptop backed up? Do you compulsively press C-s
to
make sure that you files are saved? No, because who needs to do that
nonesense anymore. Kids today, don't even know what a file system
is…
This article is about thinking of your local computer as a cache for data that primary lives somewhere else. Or in the case of git, doesn't really live anywhere, and moves around at will. One thing that is nice about it is that you don't need to worry about backups, and you can easily move around from one machine to another.
A couple of key points
For me this is this blog. All my notes and scripts I want to move
around are here. I also use Obsidian
for regular type notes and
keeping track of links and that sort of thing, but all of my config
files and local scripts ultimately are documented here in a literate
coding style.
When I got a new machine, the first thing I did was to git clone this
repo. Then I ran scripts that lived in this repo to recreate the
entire environment. I get emacs
working by following along my emacs
post, for example.
Between this (where all code stuff lives) and Obsidian
all my personal
data is synced between machines. I've got the new and the backup
laptop, so with "the cloud" I have three backups of everything.
For personal stuff I think it's most important that you rely primarily on open source tools that can work on different operating systems.
For business documents I copy everything both to iCloud and google drive. A lot of times I'd edit with google docs, and then export to PDF onto iCloud, and then mail from my local filesystem to the customer. So there are 3 copies of everything in the cloud.
/tmp
It's all about cd $(mktemp -d)
In .zshrc
:
|
|
This makes it easy to create a new temporary directory, and then you can play around.
Write down what you are doing, so you can recreate it. Often times, it better to throw away the first couple iterations till you figure out what you want, and if you know that you are going to toss it you don't need to be so precious about what you are doing.
If you like what you've done, create a github repo (private), push it
there, and then check it out again recreating whatever env
files are
needed.
e.g.
Create a blank nextjs project
|
|
Create a blank astro project
|
|
Download a random git repo and play around with it.
|
|
autorun tasks on vscode project startup. This means that when you open up the project things start going, and when you close it it all goes away.
I also use shell
in emacs quite a lot. The hugo dev server starts up
with emacs so I have access to all of these notes locally if I want,
plus if I'm working on a project I'll have multiple processes running.
When I kill emacs it all goes away.
But this also can work with things like redis
and pgadmin
, open those
things up in the vscode/cursor windows so things are going, and when
you close the window it all disappears.
And if you are running stuff out of /tmp
all of the flotsom
dissappears.
I have a couple of project that I'm working on. For development stuff, I create a "Development" vault with the general keys, and when I'm ready to deploy I put the production keys there.
Inside of my projects, I create a env.template
file that defines what
the environment needs, For example:
env.template
This gets checked into git
|
|
Then I have a setup-env
script that parses all of that into a
.env.local
. This does not get checked into git
|
|
Then basically once I push code to git, I can get rid of that local folder if or when I need and I'll be able to recreate it with github and 1password.
Github actions run when you do git stuff. The obvious is on push, so most of the repos I have build on push. The static sites check out their dependancies, build and optimize whatever, and then push to (normally) github pages. Vercel projects push and build (on vercel servers) and things I've deployed on fly.io also get built and deployed on push.
In my github profile page there's a script that runs every hour to update the content. It pulls down a couple RSS feeds and updates the readme. No servers involved.
I also have an example of using github issues to write blog posts.
On the do nothing until user action side, almost all of my little toy fly.io project have autoscale down to 0. Which means that they cost basically nothing to have a full machine ready to go. Its also nice for these projects to have attached storage, so you can keep it really simple code wise (just reading and writing to a filesystem) but get the benefits of not having to manage the operating system
If you've setup gh
, you can do gh browse
in your local directory to
open up github. Press the ,
(comma) key and it will move you to the
codespaces window, where it will start up a server on github.
You can see your list of codespaces. When idle it will close down, and it will know if there are changes that need to be commited.
My github profile repository was all written in codespaces. It's rebuilt using a github action trigged by cron that pulls in feeds.
My customize tilde homepage was also built on codespaces.
This means you don't ever need to have the code on your machine.
pnpx
This command runs node packages directly without having to install them.
By far my most used goto. Quickly serve up a directory of html files. Handles auto updates.
|
|
These wrapper scripts to docker containers give us a couple of advantages. First we can install whatever version we want fairly easily, and we can isolate all of the files that it writes. If we want something to persist over time, then we can give it a docker volume which lives beyond the invocation.
I almost aways use --rm -it
which means remove the container once the
process is done, and open up an interactive terminal
Lets spin up postgres and pgadmin in little scripts. This pulls down the container, sets up the volumes, and when you close out everything goes away except the volumes.
ppgserver
|
|
To create the server connection, host is host.docker.local
, user is postgres
,
and password is mysecretpassword
.
pgadmin
|
|
openweb-ui
|
|
mitm
|
|
redis
|
|
And then a cli instance
redis-cli
|
|
I was having trouble getting the cli to connect. So I did nd
, asked
warp to write a script to connect to redis and increment a counter,
and verified that the server was working. This directory with those
temporary files will go away and I'll never need to think about them
again.
doku
|
|
When writing scripts, make sure that you check and/or install dependancies at the top.
For the bash script that does enviroment variables, the first thing we do is check for the 1password cli to be installed.
If you are scripting in a better scripting language, you can specify the requirements inline.
Ruby scripts can include gems in a single file.
|
|
These can be named whatever you want, and don't need to have a Gemfile
floating around.
uv
dependancies
|
|
The first time you run this it will download the needed dependancies.
The rules here are
Previously
Next