On programming automatics

Joined
Mar 11, 2013
Messages
5,542
Reaction score
9,755
Here I'll post my absolute ramblings about programming in node.js + typescript + puppeteer stack.

I need to sort my models as I had 350 lines code file.

Now each model needs to be initialized with [model].init() method as all models are in separate files.

1711871275753.png


How do I call this method? I attempted to mount it on model class as static method but...

It was yesterday when I was exhausted after 12 hours screen time and it didn't work.

Now I added static and it works.

I think I tried to connect abstract method + static inside abstract class, then inherit. What a foolishness.

So I just do this static. Ditched the abstract class idea for now.

1711871382173.png



As I was doing that yesterday I was kicked out the house and didn't finish.
 
Last edited:
1711875465540.png

1711875485299.png

1711875506662.png


It works. And it good.

What next do I do...

I got to implement cookie management next. Now following is the garbage I got off AI.

1711875665529.png


wtf... time to work

"I think what distinguishes human beings from all the other creatures on the earth is... is... our ability to engineer." - Michael Saylor

What am I doing exactly?

I have 15 - 20% finished project and it got chaotic. I'm rewriting this by copy-pasting and editing parts + building a mini framework based on that project to make it less chaotic. Then reuse that framework in other projects.

Edit:

We take things like "index.ts" or "index.js" for granted and assume we know what they're for.

But they're actually useful for organization.

We look at index like we would as in library. Index is as "(in a book or set of books) an alphabetical list of names, subjects, etc. with reference to the pages on which they are mentioned."

Instead of doing exports inside every file, we use index.ts for that.

1711876925203.png


Now we export everything just from "index" and import from "index" instead of individual files.
1711877016303.png


You can still use "export" keyword inside files, just to make it clear it'd be exported. You can export one thing multiple times from many places which is a sort of a trick.
 
Last edited:
1711877775293.png

When you do and listen to a podcast at the same time...

Let's change it to "getCookiesByAccount".

We add "accountId: number;" to definition of Cookie class.

Also we add to interface "CookieAttributes" that class implements.

Then we get it talking...

"Argument of type '{ name: { type: DataTypes.StringDataTypeConstructor; allowNull: false; }; value: { type: DataTypes.StringDataTypeConstructor; allowNull: true; }; domain: { type: DataTypes.StringDataTypeConstructor; allowNull: true; }; path: { ...; }; expires: { ...; }; httpOnly: { ...; }; secure: { ...; }; }' is not assignable to parameter of type 'ModelAttributes<Cookie, Optional<CookieAttributes, never>>'."

Hover, hold mouse over error code and click "quick fix" -> "add missing properties".

1711878138126.png


We have accountId on the model as our implemented interface states.


Small difference in how it's written, big difference in what it does (definition vs usage).

1711878447113.png


Full non-tested function

JavaScript:
export async function loadCookiesFromDatabase(
  page: Page,
  account: Account
): Promise<void> {

  //definition of async function
  const getCookiesByAccount = async (account: Account) => {
    const cookies = await Cookie.findAll({
      where: {
        accountId: account.id,
      },
    });

    return cookies;
  };

  //usage of async function
  const cookiesByAccount = await getCookiesByAccount(account);

  await page.setCookie(
    ...cookiesByAccount.map((cookie) => ({
      name: cookie.name,
      value: cookie.value,
      domain: cookie.domain,
      path: cookie.path,
      expires: cookie.expires
        ? new Date(cookie.expires).getTime() / 1000
        : undefined,
      httpOnly: cookie.httpOnly,
      secure: cookie.secure,
    }))
  );
}

Another way of organized export is this. It's ok for smaller modules.
1711880180536.png
 
Last edited:
  1. I have 4 hours till my next shift, so I work on this now as yesterday I was unable to focus due to eating all day long and family meeting + trolling on the forum for hours.
  2. There's something special during xmas when everyone just can't focus.
  3. Many known workaholics were inactive during that time. So was I (success compared to previous years).
  4. I wasn't drinking though which won't force me to spend another week for recovery.

Priority - list of to-do (to find order in chaos):

1. Finish cookie management off file. Off database isn't useful now.
2. Make git commits and push all the stuff to repository once it's in "working version".
I don't really know what are all benefits to it but I noticed sometimes I need to see how it was before a change. Naturally you would like to see how something worked in the previous version.
3. Write some tests to practice writing tests.
4. Create testing environment by writing decoupled functions that can be run using nothing else than cookies loaded off file.
5. Implement mechanisms to abstract classes that classes inherit from to check whether account works or not before doing anything.
6. Clean up and split browser.ts file - it's too long as it's 250 lines and all it does is opening browsers. It does some things that could be put away into different modules.

On first step - Finish cookie management off file
I'll import cookies from json. So I'll import json. For now I can export them from browser using "Export cookie Json" chrome addon.
Getting JSON as "import" can be done as here https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#new---resolvejsonmodule
"import * as TestCookies from "./test-cookies/index.json with { type: "json" };";" once I set "resolveJsonModule": true," and "
"module": "ESNext" in tsconfig.json.
Turns out "number" type in typescript is also something like this "1743609864.452692". In other programming languages it wasn't called number but float or some.
page.setCookie(...cookies) - this apparently accepts "(...cookies)" which is called "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax" - basically that function will accept any number of arguments.

When I want to reuse some function, I want to create a reusable function with common name that I can use multiple times later and edit once, to edit everywhere.

So I create a module / file called "links.ts". And in that file I put:

JavaScript:
import { Page } from "puppeteer";
import { goToWebsite } from "./utils/customs";
export const goToYouTube = async (page: Page) => await goToWebsite(page, "https://youtube.com/");

Then I can import "goToYouTube" and use as "await goToYouTube(page) wherever I want based on that "goToWebsite" function. Very short, right.

For now I have this type of thing that seems to work with "any" types but I don't care now.

JavaScript:
import * as TestCookies from "./test-cookies/index.json" with { type: "json" };
import { Cookies, Cookie } from "../database/models";
import { Page, Cookie as PuppeteerCookie } from "puppeteer";

export async function loadCookiesFromFile(page: Page) {
  const cookiesToLaunch = TestCookies;

  try {
    const cookies: any = cookiesToLaunch;
    const cookiesDefault: any = cookies.default;

    console.log(cookiesDefault);

    await page.setCookie(
      ...cookiesDefault.map((cookie) => ({
        name: cookie.name,
        value: cookie.value,
        domain: cookie.domain,
        path: cookie.path,
        expires: cookie.expires,
        httpOnly: cookie.httpOnly,
        secure: cookie.secure,
      }))
    );
  } catch (error) {
    console.error("Error loading cookies from file:", error);
  }
}

Later homie...

On commits
Did some commits using "source control" tab in Visual Studio Code. Each commit is one significant change, so it's actually useful to describe and it will work as a list of tasks later.

We can use it to brag and build personal brand showing off to other people.

1712081722898.png
 
Last edited:
Very good.

I need to find a scheduling thing (npm module) to put things away in time as that's required to not fire my stuff early.

I have a list of sets of operations and between each operation there's is a random delay.

Now between each set of operations there is a long delay ie. 6 - 48 hours.

So it's not a loop but a long, spontaneous schedule.

Each set it constructed of random operations.

Sets of operations are put in random order as well.

Based on some operations there are other operations in the future but there might be a problem that the browser will be busy and 2 operations would overlap. So they need to be spaced in time and done subsequently.

What library is good for that? Probably none as 90% is custom anyways.

Maybe I'll find some article on scheduling tasks in node.js.

Edit: Agenda and other libraries look fine. But which one will be comfortable for me? I'll check their docs.
 
Last edited:
This code is all over the place. And honestly, the way you've (or whatever AI you're using) written it makes it really hard to follow. It's like there's no order or structure at all in your code and your thoughts/wall of text in this topic.

One glance and I see you're setting cookiesDefaultas any, but then in loadCookiesFromFile you're mapping over the values. Code makes no sense and is very prone to bugs.
JavaScript:
const cookiesDefault: any = cookies.default;

But you do you. Props for trying something

For scheduled stuff use https://www.npmjs.com/package/cron
 
Code is very clean. Despite what code gurus say.

The point is scaling to 10k weak accounts a day or 10k strong accounts a week.

So far it was 700 accounts a day but no scheduling + chaos which was javascript which was replaced by typescript. :p

Scheduling allows for proper aging and scaling over time.

But capital went down to zero due to personal expenses and I have to emigrate in order to continue.

This is 3rd world country, off the ground operation in complete chaos.

I'm living under a bridge. Which is extra challenge. Try it.
 
Last edited:
Code is not clean.
You will barely understand what's happening messing with import and exports when project grows.
Also for scaling, try to be minimal as possible and scale it with containers (docker/swarm or k8s)

Do micro-services architecture
Just use "fs.promises" to async read files
Use postgres as database or dont use it at all if the overhead is not worth it (for the amount of data you're storing)
If data is going back and forward from db and its not large, consider replacing it with redis (in memory cache) as you will gain tremendous performance
 
Code is not clean.
You will barely understand what's happening messing with import and exports when project grows.
Probably. I do it first time in this stack. Just exploring. That thread was mainly about it... exploring.
Also for scaling, try to be minimal as possible and scale it with containers (docker/swarm or k8s)
This might not work due to business reasons. It all happens on Windows.
Do micro-services architecture
Just use "fs.promises" to async read files
Use postgres as database or dont use it at all if the overhead is not worth it (for the amount of data you're storing)
If data is going back and forward from db and its not large, consider replacing it with redis (in memory cache) as you will gain tremendous performance
I use sqllite as it's lite. I don't have much experience with databases. I think I wrote 100 queries using ORMs in my life.

I didn't even study SQL.

I have all kinds of knowledge and am master of none. Typical black hat marketer. Still I feel like I only began, so I don't care about what happens.

I feel like half the community here is twice as old as I am, so I just feel like a kid playing in a sandpit.
 
It's ok! Every self-taught developer started somewhere.

You could scale it up using nodejs cluster if your machine is multi-core, just make sure its stateless to not issue into any race conditions.
SQL these days is not worth learning (if you dont need very specific use case / extreme performance), there are so many ORMs and you can just use them. Try "prisma".

Look into being stateless, save you application state externally and safe from multiprocessing so you can scale very easily.
Use queues for processing tasks, it will make everything easier.
 
It's ok! Every self-taught developer started somewhere.

You could scale it up using nodejs cluster if your machine is multi-core, just make sure its stateless to not issue into any race conditions.
SQL these days is not worth learning (if you dont need very specific use case / extreme performance), there are so many ORMs and you can just use them. Try "prisma".

Look into being stateless, save you application state externally and safe from multiprocessing so you can scale very easily.
Use queues for processing tasks, it will make everything easier.
Lol imagine this level of reply on Reddit. BHW surprised me again.

Though it's a marketing forum, they give decent programming advice.

I had something like queues on my mind, but I don't have any experience with writing them other than little bit Laravel.

That was long time ago.

I have never done anything stateless.

"When a program "does not maintain state" (is stateless) or when the infrastructure of a system prevents a program from maintaining state, it cannot take information about the last session into the next, such as settings the user chose or conditions that arose during processing."

So maybe I have, just don't realize because this term is vague.
 
Last edited:
So I'm using anti detect browser which means my program isn't really capable of being scaled forever with some kubernetes.

I have never seen anyone successful with this approach. I feel like people think of scaling programs too much and not money. Technical implementation here is 10% of work. The rest is solving business problems.

It's not a project for client.

It's supposed to work, not look pretty on paper with some "this is scalable!! Pay attention" red sign in the middle.

Though if you send me guides I can apply those. I don't care about typescript for random functions and being precise with types in every single place.

It's more needed for data structures and classes, interfaces, inheritance etc. I'll write docs later.

I'm solo and working daily on many things.

The chaotic style of writing classes lets me rest when I'm tired of implementation of one class and meanwhile I can work on another. This way I'm easier on myself.

I tried to code one class and solve a technical problem no matter what, making things look perfect, but it just was causing harm. Zooming in so hard on one little class is just pointless from energy expenditure perspective. Especially if it's something as simple as cookies setup.

Try to solve math problems in a single session without longer breaks between trials when you do it for the first time. This would burn! And I remember how frustratiing it was.

The rule is it works, it's good. Tests will confirm.

Well, why don't I just outsource it? I don't know. Maybe I should. Maybe next time. For now I can still learn.

Maybe I'll set typescript mode to stricter to get disciplined.
 
Last edited:
It got to me...

I'll use this https://optimalbits.github.io/bull/

As a scheduler.

It supports everything including rate limiting and concurrency and is based on Redis.

Which means it's not mongo which was another choice. And I don't want to complicate it with mongo.
 
It got to me...

I'll use this https://optimalbits.github.io/bull/

As a scheduler.

It supports everything including rate limiting and concurrency and is based on Redis.

Which means it's not mongo which was another choice. And I don't want to complicate it with mongo.
It's complete piece of garbage that no sane person should consider using because all it does is it introduces them to corporate level nonsense solutions that maybe will work in SaaS on a 256 core machine but would never work on Windows for small scalers aiming for $3k revenue per day. :p

1. Redis.
2. Linux.
3. Stupid library that isn't really that good but is quite cheap (marketing part), so st00pid *rich* developers ($15k mo payment) buy extra PRO license for their BOSS money. :p

So what I'll be doing is creating my own scheduler, queue, rate limiting, job overlapping avoidance solution system.

Please, don't do anything related to software in 2024 if you think someone has solved problems for you.

These idiots pissed me off so hard I would write 100000 pages describing their madness.

I literally feel inflammation increasing in my body just looking at this idiotic field. It's probably the most moronic filled with bs products engineering field ever created.

So stupid bullshit, millions of tightly coupled dependencies. Example: Scheduler > coupled wth Redis > coupled with Linux > coupled with Linux browsers / useragent.

Rationalization to switch to linux? "You can use Docker bro".

Revenue and source of income: my boss pays me. :oops: I'm changing my company every 2 years... :cool: Each time they say "project failed" but I have no idea why!

Yes, you can afford this "LInux" dependency because you have no fcking responsibility to generate revenue. You only lie to your boss it will work. :)

STUPID FIELD!!!!

The chaotic style of writing classes lets me rest when I'm tired of implementation of one class and meanwhile I can work on another. This way I'm easier on myself.

It works better than I predicted. I have thought of most functions and how to structure program not even sitting in front of computer.

All I had with myself was notepad and a phone to write a set of ideas for about 40 minutes a day.

Could literally send it to someone, pay $500 and it would be done in a week.

#Software engineering is dead. All you need is a notepad and thought. #IdeationRules
 
Last edited:
Interesting rant, I agree this field can be really daunting.

Tons of stuff to learn as a solo developer trying to create some hustles, while the peers you're interacting with are often employed by a relaxed company which affords them the ability to study (and engineer) overly-complex stuff without having to accomplish stuff with it quickly.

"Well no it's not actually a bloated overly complex mess abstracting everything behind 5 layers needlessly!!!! It only took me a full week of studying to figure it out in my cubicle while collecting my salary!"
 
Oh fuck fuck fuck

I made a huge thought mistake.

I was thinking about 5 classes instead of procedure that I would split into classes later.

You see how easy it is to get caught up in bullshit...

I have an extra module that's like a manager of everything, boss, almost god.

It observes everything and decides what to do next...

Before I was doing singular classes.

But now it's a whole module, a small library.

It requires different approach. Albeit the difference is small.
 
Last edited:
This is what happens when you happen to happen to make something happen for the first time.

You put a large file called "ActionService.ts" and you put everything in there creating sort of a large procedure that sucks and is pain in the ass to debug and everything feels like from decoupled pieces you created one messy coupled piece making you nauseous to work through it.

This would not be the way to earn a decoupling medal for sure.

1715481190669.png


663 lines long procedure... nothing of that makes sense.

Time to rework all of that garbage and create what should be created long time ago.

DB operations separated from automation operations separated from things that glue both of them together.

Then separation of something else I forgot about. Ahh, separation of scheduler and pieces that glue together scheduler and automation operations, and database operations.

Then separation of anti-detect browser APIs, so they can be easily implemented and switched back and forth.

1715481475194.png

You want these red links removed and make it have only one link - the green one.

If you are fast, cheap, you'll create red ones (many) which won't make you stand out in a good way.

A fckton of software is written like red ones. Why? Well, money... pressure...

Some software is written with red ones multiplied by x50. I worked like that for a while and all I wanted to do was alcohol / illicit drugs.

Boils down to organization - something an average lady is better at than an average man.

Women are known for striking the right balance between their personal and professional life.
A man who doesn't deal with women regularly harms himself.
 
Last edited:
If you work on too big units, it will be hard to scale them.

If your units are smaller, more people will be able to work on them and it will be easier to distribute the load.
 
So stupid bullshit, millions of tightly coupled dependencies. Example: Scheduler > coupled wth Redis > coupled with Linux > coupled with Linux browsers / useragent.
This is such a tight ass coupling I am about to start laughing reading how this whole field is one big cluster of nonsense. :D

I'm modifying Windows instead of installing Linuxers.

But what was Windows written on? MS-DOS.

And before MS-DOS: 86-DOS, CP/M (Control Program/Monitor)

First Linux was in 1991 which means it's something new rather. I was biased and thought it's some primitive system.

But it didn't win consumer market which is what drives social media and must be used to be successful in social media. So MacOs or Windows.

If you develop automation on Linux with Linux dependencies, you won't be able to run it on Windows...

What is a smart option is connecting multiple iPhones and managing them on Linux / MacOs.
 
Last edited:
Stop shitting on Linux because you cannot use it / do not want to learn.

For software development it's way better due to all software made ad hoc for production, huge workload handling, security, better file system, stability ecc.

It runs over 90% of internet servers, and it's not popular on consumers because was made for servers not client. Even BHW website runs on Linux.

Also if you are on windows, just use WSL, and you have linux on your local machine with very small effort.

Who cares about Linux to windows when literally using nodejs that's crossplatform?

You should run the software in a remote server and only control it from your local windows. So you don't need any dependecy.

If you start using it for development you will not come back.
 
Back
Top