Programming

image

Part 2 of my aws rant.

Still learning aws. I’m tasked with deploying an EKS cluster (aws managed kubernetes cluster) via terraform, so it can be automated and made into a generic module for other people so they don’t have to hassle with what a PITA terraform + aws is.

Automating isn’t super fun because AWS documentation wants you to do everything in the console UI. Google is very automation friendly. Compared to gcp provider in terraform, aws is a joke. I said before but to create a google managed kubernetes cluster is like, 10 lines of code. Give it a firewall and then boom done. Easy peasy.

Nah not so in aws. You need a VPC, subnets (in at least TWO different availability zones), security groups, gateways, IAM policies/roles, routing tables + rules, and an autoscaling group which tells the managed service how and when to deploy your nodes.

Then there’s this checklist of like 15 esoteric things you need to make sure your node has or it won’t join the eks cluster. Some of which is some bizarre ass script you need to put into your cluster to run at boot, a configmap inside kubernetes, and subnets/security groups must be tagged very precisely with your cluster. It seems so hacked together, and none of it is well documented really. My EC2 node wasn’t joining the cluster and there’s no logs or error messages anywhere to give me a clue as to why. Eventually, after a few hours, I narrowed it down to the VPC I was using not having hostnames enabled (easy fix) but even after that I couldn’t get it to join and I had to ssh to the machine to see its journalctl logs.

Well, even that was a pain in the ass, I had to define a new security group, NAT gateway and rule just to be able to ssh to the damn thing. In GCP you just add port 22 to the firewall rule, boom done. Nah. Finally, I’m in the machine and realize it cannot reach public addresses on the internet. It had the wrong security group applied to it, which ended up being a misnamed variable in my configs. Lol.

All in all deploying a google cluster is about 5 terraform resources tops. This one topped out at 45 resources, and it’s not even that complicated of a cluster. AWS provides a lot of fine tuned control, and cheap pricing, but good lord you are completely at their mercy when it comes to how you deploy this stuff. As an end user, I hate it more than anything I have ever worked on, and I worked with prolog once. I suspect this will be something I’ll laugh about in a year and wonder how I ever lived without it, but right now it is hell.

1 Like

I use Rails daily and I love it and Ruby. Just accept that there is magic; you can always look up everything that happens under the hood if you want to.

LMK any specific questions you might have. Writing a migration to change the db and then running it to apply it seems so standard to me, what’s crazy about it?

The migration’s name actually doesn’t make any difference for running the migration or what it does. But when you create it with such a name from the command line as you did, it will create a pre-filled migration file with smart defaults for convenience. You can just create a file called “7657324738925MicroAddsSomeFields” and do whatever you want in it, create tables, change them…

The only part of the filename that’s important is the number in front, that’s used for rollbacks etc, migrations are basically like git commits for the db.

1 Like

Thanks. Since that post I have gotten far enough that I get those things. I’ve been creating, editing, and running migrations. And rolling them back. And I found byebugs and see the code stepping through. I’m starting to get it. What seemed really crazy was the scaffolding (and at the time I was just copy pasting so I didn’t know what I was doing), but now that I’ve made more pages/classes/dbcalls of my own, I’m getting it better.

The way it just gets things that are singular/plural and maybe other connections is weird and I can see people hating it, but I can also see getting used to this “CoC” thing. I just have to learn the rules.

I’m doing some other stuff today, but when I get back in the code I’ll probably have some questions.

Thanks.

1 Like

The keyword you’re looking for is inflections. Also byebug is fine, pry is great: GitHub - pry/pry: A runtime developer console and IRB alternative with powerful introspection capabilities.

1 Like

Someone should put in a pull request to change it to

inflect.plural(/(octopu)s$/i, '\1ses')

or maybe

inflect.plural(/(octop)us$/i, '\1odes')
2 Likes

Well they do say right at the top

The current set of inflection rules is frozen. This means, we do not change them to become more complete.
This is a safety measure to keep existing applications from breaking.

:stuck_out_tongue_closed_eyes:
You can use / add your own inflections for your own project like here: https://github.com/rails/rails/blob/5aaaa1630ae9a71b3c3ecc4dc46074d678c08d67/actiontext/test/dummy/config/initializers/inflections.rb

CoC is great but you can still configure / do anything you want, if you need to or vice versa. Never saw anybody changing that though.

1 Like

Is there a better way to write the following TypeScript type? This is for a callback that generates a custom event–the goal is to type-check invocations of the callback against the particular type of custom event that is supposed to be generated.

export type CustomEvent = {
    name: string,
    detail?: unknown
}

export type $Dispatch<T extends CustomEvent = CustomEvent> = T extends {detail: unknown}
    ? ((name: T["name"], detail: T["detail"]) => void)
    : T extends {detail?: unknown}
        ? ((name: T["name"], detail?: T["detail"]) => void)
        : ((name: T["name"]) => void);

I tried introducing type aliases for the function types, but that made it worse.

I just got the green light on the Ruby on Rails project. Seems hard to overstate how important this is. Wish me luck.

@Europa - any help you can give, I’ll be immensely grateful for. I have a tiny project I’ve been playing with that’s live on Heroku and code is on github if you even would take a peek and let me know how bad it is.

7 Likes

I’m happy to take a look, pm me links / details. What’s your timeline, here?
Pretty swamped at work so can’t make promises / commit much time now, but will have time on the weekend for sure.

2 Likes

Typescript is like programming with a condom. Yes you’re protected, but it takes half the fun out of it.

2 Likes

It’s not that complicated. I have a function f that creates and dispatches a custom event. I want a type constructor that maps the type of the custom event to a supertype of the type of f that only accepts the appropriate subset of arguments for the type of the event. It’s pretty straightforward.

1 Like

Assuming it works. What’s the problem? You don’t like nested ternaries? If there were some syntax to shorten that, I wouldn’t be looking to do it.

Yeah, and it generally seems a little obscure. This was the best I was able to come up with:

export interface CustomEvent {
    name: string,
    detail?: any
}
export interface SimpleCustomEvent extends Omit<CustomEvent, "detail"> {}

type DetailRequired = {detail: any};
type SignatureWithRequiredDetail<T extends CustomEvent> = ((name: T["name"], detail: T["detail"]) => void);
type DetailOptional = {detail?: any}
type SignatureWithOptionalDetail<T extends CustomEvent> = (name: T["name"], detail?: T["detail"]) => void;
type SignatureWithOnlyName<T extends CustomEvent> = (name: T["name"]) => void;

export type $Dispatch<T extends CustomEvent | SimpleCustomEvent = CustomEvent> =
    T extends DetailRequired ? SignatureWithRequiredDetail<T>
    : T extends DetailOptional ? SignatureWithOptionalDetail<T>
        : SignatureWithOnlyName<T>;

It seems like it would be much clearer to just create an overloaded function that works the right way, then use typeof to get the compiler to work out its type for you, but that is not possible due to [reasons]. So I’m guessing this is as good as it gets. And it does pass the tests…

First couple days on the gig have been excellent!

3 Likes

IAM is painful as hell. My boss is the only one who has create role credentials in our production account. So I always have to go to her when I need to create something.

1 Like

Had a good one today. I lead a project that’s an internal npm style js package used in other projects. Guy pings me in slack at 3:15pm saying he’s updating his own dependencies and when he does that my library gives him some error, I say “OK I’ll look into it and get back to you”.

At 3:40pm he pings me again with “hey whats the ETA on that?”.

hahahahahahaha

404 option was confusing. Is that what happens if you don’t do the API check and they just paste the url in there or is that a new step? I can get someone saying “don’t waste our time with something that never happens or the user can fuck around and find out”, but if you’re going to do something, the API check and routing to where you want them with a message about their device seems right.

That was question two. For question one, yeah, unless I forget or don’t bother and I think I pretty much always do check - but then pretty much the only times that’s come up for me is authentication, so sending an unauthorized person to the log in page or w/e is pretty obvious. Device compatibility isn’t necessarily so important.

1 Like

I have no problem telling millions of people to fuck around and find out. In fact, that would make a good 404 page.

eta: I searched and could not find that being used. The closest I got:

Yeah, and like I said, you seem obviously right. They should be directed to a page that says their device is not compatible. Duh, right?

1 Like