Skip to content

Instantly share code, notes, and snippets.

@cjlaborde
Last active April 26, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjlaborde/491ec85c8feaecccf0b4d02333427bdd to your computer and use it in GitHub Desktop.
Save cjlaborde/491ec85c8feaecccf0b4d02333427bdd to your computer and use it in GitHub Desktop.

maxymajzr Advice about making app concurrency-safe

https://www.informit.com/articles/article.aspx?p=22681&seqNum=3

right now, i can tell you that your code is not concurrency-safe (meaning multiple-inserts at once):

  1. there's only 1 proper way to do it, and sadly - you will never find it anywhere in any laravel or php tutorials and it's because this issue is related to data modelling and databasesthat's how it works

  2. It takes time() and adds config('session.lifetime') to it

  3. Then you get a cookie that expires at time() + config('session.lifetime')

  4. There's very little point in making the user extend the session, it's something you make user think about and users know fuck all about techy shit

  5. Instead, you can use what google does and does it really good set a cookie for 2 years literally, just make the session last 2 years. maxymajzr β€” Today at 5:40 PM wait, wait, wait, wait, wait a CHAT of any sort is considered.. work-related? πŸ˜„ ever since i was a young and aspiring gamer, we all knew that the unwritten truth is this: if you want to get any work done - disconnect Legit Dongo β€” Today at 5:41 PM then we made our jobs about connecting 😎 webdev kind of impossible while disconnected maxymajzr β€” Today at 5:42 PM ok, if one day you decide to humor me or test the theory, pull the cord - go and work on some simple business as usual CRUD and then tell me how many minutes you spent to achieve what you usually do in hours

  6. However, track when the user was last active.

  7. It basically means you put 2 values in the session - when the session expires and when the user was last active that's how google is able to tell you "your session expired" and just ask you for a password instead of full blown username + pass

  8. Instead of doing this check in PHP, you'd make your database allow or disallow inserts. it's done by placing unique keys to start, end and active columns in your table.

  9. if an active tour exists for a combination of start and end, database will throw an error saying that it can't write because unique key constraint fails. this is concurrency-safe and no record can exist with the same combination of data

  10. what i'm typing heavily depends on your table schema, i didn't include all keys you'd have to add to unique constraint, however that's the way you do it, you'd have to think a bit before applying the solution i'm mentioning

  11. Then, when it comes to PHP - you just attempt to insert. then you try/catch that insert and check if the error returned is 23000. if yes, the record exists and you tell the user "this date range is not available"

maxymajzrToday at 6:14 PM

Had to reboot. if you deal with dates that overlap and aren't exactly the same, then the problem is more difficult to solve on a database level. which means - keep your solution for now, but bear in mind that if you end up with duplicate records - it's because PHP can't stop concurrency-related issues. no language can, only databases can

guide to dates:

1. decide on one of the two models for storing dates. 
   1a. UTC - there is no time zone. data type: timestamp in mysql, no clue about the others. excellent for querying. 
   1b. ISO format with time zone offset. shit for querying, you're also a cunt if you do it

2. decide where you'll convert dates  for displaying it to humans - browser or backend? 
  2a. backend - you are literally stupid if you do this. backend needs to receive info about your user, such as time zone offset so it can calculate the date correctly. use it if you want to "practice" Carbon
  2b. frontend - smartest move. let the browser fuck about with time zones. use luxon, it's 60% similar to PHP's Carbon, it's also 10x smaller than moment.js

Time Zones

- supply user's time zone to PHP with the request that does the booking. this is to help PHP calculate the offset between user's local time and what's going to be saved to db
- set your PHP-FPM server to use UTC as its default time zone: https://www.php.net/manual/en/function.date-default-timezone-set.php 
- now MySQL won't perform conversion between PHP <-> MySQL

why is the above important?

user lives in NY
user selects 25th July 2020 @ 22:00 -> in UTC, this is (i think), +5 hours so it's 26th July 2020 @ 03:00

now, using PHP, you actually manage to catch that edge-case and you convert the date to what DB would expect, 26th @ 03:00
you set your server's TZ to UTC, now MySQL won't perform the conversion between server's time zone and UTC and the data that ends up in DB is literally 2020-07-26 03:00:00

when you pull the data out, your API delivers 2020-07-26 03:00:00 but on frontend, using Luxon (or moment), you convert that time to user's local time so they'd see 2020-07-25 22:00:00

Advice on security

  • UBlock Origin / Adblock plus
  • nextdns.io for DNS level ad filtering
  • cookie autodelete extension for chrome
  • blokada.org for android paired with nextdns.io app
  • disable cookies in chrome on mobile

you're mostly safe with that

Standards of code

  • it does the job
  • it's clear in its intent
  • it's covering the scenarios
  • it's reasonably self-documented by proper variable/exception naming
  • it encapsulates a problem and deals with it
  • it's short code-wise
  • it's testable

maxymajzr

fuck one method being good - all of it needs to be good and working

When you supposed to use framework

the way i see it is this:

  • you start off with a problem you want to solve (say, a todo list app). unless you have this, your learning curve will be way, way longer
  • you try to solve it without a framework. this teaches you how many different systems play a role (web sever, php, database, user's browser)
  • then you use the framework and you see how some problems are gone in a few minutes (routing, authentication, validation, using the database)

and only THEN can you progress, after being aware what the tool does for you

excellent way to get out of eloquent callback hell

  ->with(['cakeAd:price,subid_1' => function($query) use($country){
                $query->where('country', $country);
            }])
  1. write the SQL, if you know how to
  2. create a view
  3. reuse via eloquent without having to use "scopes" or all the other ugly shit that makes it unreadable and that produces suboptimal queries

buzzword that turns into something captain obvious would do

something along the lines of GDD Goal-Driven-Development

  1. 1st rule of GDD: have a goal you want to achieve (because, people totally don't have a goal when they fire up their IDEs)
  2. 2nd rule of GDD: achieve the goal buy the course for only $999.99

TDD

The main reason you do it, because you can implement a new feature and it can cause another feature you created before to fail. So it protects you from that. -you described avoiding regressions

Learn the Why before focusing on the how have clear intention in mind and why you do things.

with no critical thinking ability. and that's precisely the ability you need if you want to become that $1000/h guy

-maxymajzr

stuffing yourself with principles without wondering why it's being done.. it's a sad existence

-@maxymajzr#6831

why repository pattern? why mvc? why CORS? why CSRF? why XSS? why vue? why TDD? why DDD? why unit tests?

-@maxymajzr#6831

You need to solve problems.

  • that's the end game. you simply need to be able to do it. when you are capable of solving problems that your employee / customers have, then you make money. if you solve someone's problem and make their ecommerce produce 30% more, they WANT TO KEEP YOU, and then you make that $1000 an hour

  • instead, had you spent that time to ask yourself why and make yourself someone capable of using pattern recognition to solve problems by writing algorithms

User Activity

simple: don't use cache, just write to the db whether the user is online / offline and then optimize later create route that fetches user info, ping it every now and then until you figure out how to use websockets for real-time notifications and then move on to avoiding db queries via cache simple steps first

  1. make it work

  2. make it work fast

  3. create last_active_at column in users table

  4. create /api/v1/user/info route that returns current users' info

  5. on frontend, calculate current time against API response, where you supply last_active_at

  6. determine whether the user is active or not on frontend, using an interval (say, 1 minute). you do so so you can shitft the logic to frontend

  7. every 1 minute (setInterval), do an ajax to /api/v1/user/info and repeat the step 3

  8. you are done, you have trivial code and no logic on the backend except updating users' last_active_at

LYMBDA FNKTYN GO BRRRRR

  • step 1: acquire 40 euros
  • step 2: rent a dedicated server from hetzner
  • step 3: laugh in 8 cores/16 threads at stancl and his poor ass pieceofshit computer that costs 500000 times more
  • step 4: install php
  • step 5: use your server to process image in batches
  • step 6: occasionally hit htop or top to see how low the load is
  • step 7: become a twitter superstar because you executed a trivial task and are better than 99% of human population
  • step 8: die a god among men

Be a Great programmer

so, my logic is the following - if you want to progress to a great programmer and make it your career, start with the basics: servers and where everything runs at. start learning linux. start learning how to compile php from scratch. start learning how to keep a programm running on linux in the event of crash. install nginx manually. configure php-fpm manually. make them work

there's a lot of people who don't even know PHP and yet they use laravel. they're the target audience for taylor otwell and several other people gathered around the laravel brand and they publish articles, create services and create traction around laravel ecosystem now, the problem with the above is that.. they kinda lie about many things and are on the road of creating a "famous" persona around them selves and we just call them laravel elite, jokingly. except it stopped being a joke when you create a following of several thousand or several tens of thousands of people, you can make some serious money but you can cause huge damage if you teach them wrong, and in my opinion - that's precisely what's happening. matt staufer and the likes are teaching people wrong, creating a bunch of devs with overly inflated ego (read: they ask for too much money for way too little work)

Market yourself and present yourself as a valuable asset in the field

  1. There's a misconception that employers are looking for people who have more shit in their CV than a hooker has STD's what everyone wants is people who are capable of finishing projects.
  2. Finished project = money.
  3. Now, if you look at what happens in IT is the following conclusion: if you get experienced people, you'll be faster with finishing the project.
  4. Reality does not reflect that notion. what most companies end up doing is this: they hire a bunch of mediocre people who bullshit their way into the company and ultimately they don't produce work that reflects their salaries.

What i would do if i were you is this

  1. I'd market myself as a person who is capable of working with mediocre devs, even with newbies such as students looking for internship.
  2. The one who can produce working project by utilising help of not-so-great programmers is a valuable employee.
  3. You'd be a teacher AND the coder.
  4. Which means, the cost to hire those other people would be significantly less.
  5. Which means, hiring you = cheaper than hiring someone else.
  6. You offer something that's super interesting: a potentially great team, taught by you, who doesn't cost a ton of money.
  7. Now the deal makes sense.
  8. You want something, i want something. you offer something, i offer something. now we tango.

what architects do

  1. you'd be doing initial design
  2. create tickets
  3. do code review
  4. set up pipelines for deployment
  5. define environments where the app would go
  6. enforce methodology and code style etc.
  7. decide about stack being used, do the analysis of cost versus time and shit like that that's what architects do.
  8. deal with getting students interns and others who cost a fraction of a senior dev

Cost Value you bring

  1. You + 9 people = cost of 2 devs
  2. Senior + 9 mids or seniors = much, much, MUCH higher cost for the employer in the scenario above, you are more appealing option
  3. Trust the Divide God Intellect.. anyone who dealt with programmers or anyone senior IT understand what cunts us devs are

You are the one

  1. If you are a non-cunt who teaches interns and meets the deadlines..
  2. Yeah, you're the one yes, they WOULD have to hire juniors

The Secret is

  1. A crud-y app written by a junior under supervision and a crud-y app written by a "10x" dev is ultmately going to work the same with the exception of costing 10000x more if it's written by a senior "10x" dev

Shitty CV

they talk about investing no effort and gaining a lot of money, then filling up their CV with buzzwords and fucking off to google/facebook πŸ˜„

how to tain Jr Devs

  1. Teach newbies how to do simple tasks
  2. Force them to write tests
  3. Do the code review (it's faster to review code than to write it),
  4. Standardize the code aesthetics
  5. Enforce the workflow

Be a quality Senior Developer

  1. it's not easy to create short explanations
  2. nor is it easy to create short code
  3. it takes a lot of practice. that's why seniors are appreciated, not because they're egoistic fucks who know a lot of buzzwords
  4. a senior is someone who is capable of taking a requirement and split it into concise set of problems that are solved via code and algorithms
  5. and if that senior keeps the code simple and problem easily understandable from the code itself, THAT'S the guy you want to keep and pay a fuckton of money
  6. the buzzwordy asshole whose code is unreadable? i call those old juniors

PHP uses Hashmap

what you see in PHP is not a multidimensional array
it's a fake one
the "real" one is heavy on memory :smile:
PHP uses something called a hashmap in order to fake a multidimensional array
but, if you can visualize it, that's good. an array is not a data structure

Leaning Data Structures the Right way

but learning about data structures is the bad way to go about it. solving problems whose solutions are made faster because of smart use of data structures is the way to go about it @R3N https://www.php.net/ds

Wrong way to learn Data structures

bad part is to learn about the solution without knowing what the problem is. that's what makes learning about DS hard like.. what the fuck for are you going to use a linked list or doubly-linked list or a queue or a stack people @ college have bad approach to that. IMO, it's better to take an old project and improve it by trying to utilize correct data structure for a particular segment of the app

the logic is simple to show backend validation error:

  • POST to server
  • when error occurs, save the data to vuex
  • match field name with the error array, using vuex
  • render error below the field

How to to a Code Review

in other news, i returned to the project that i left 6 years ago i worked on it for 6 years prior to that

  • no code upgrades
  • no tests, apart from a few i made
  • no documentation at all about anything
  • impossible to deploy, it literally takes over 5 days to deploy it
  • no migrations. copy an existing db. oh, they all come as 6.5 GB SQL dump of course. full with shit data

reason i returned to it was "it's slow". let's define slow: it takes over 120 seconds to submit 1 record to the system i've been dealing with it for 4 weeks now, i literally pulled executive decision about every single bit i found in the system and denied the current "lead" to say a single word i found such bugs in dude's code it's actually fucking scary, at one point i wondered whether we should abandon the project all together and just fire half the devs why? because there's accounting involved and the code looks like this:

if($variable = $this->lookupDbForPaymentAccount($payment_account_id))
keen eye will notice =
which was supposed to be ==

and that code was in production for a year so it's a huge question how much of the accounting was fucked because of that one line of code that's always true then there were oddities such as validate a huge amount of data huge amount of data is 26 448 form fields how did they do it? they stuck it in a loop, loop pulls validation from db, for each form field it performs select, then it validates it, then if it's valid it instantly inserts the row now, it's all in a transaction. which is good. why? because the validation we're talkng about tends to snap at around field number 15 000 and at that point db accumulated ~15k records to insert and it needs to do a rollback because validating first and insert afterwards was too complex of a concept for the fucks who work on the project then, a number of fields are involved in some kind of math calculations, and these formulas are supplied by customer they're not hard formulas, it's mostly shit like multiplying or summing numbers so, instead of a simple math library and simple logic that gathers all the formulas first, then populates it with variables - they didn't do it that way so what's the sum total for this fucking thing:

26 000 fields
26 000 initial selects to get the validation rules, and only ONE FUCKING RULE IS EVER SELECTED 
26 000 inserts that get rolled back
26 000 repeated inserts
2 000 inserts that deal with metadata
26 000 selects to obtain math formula - the same one
26 000 math operations that basically repeat the same numbers
no tests
no docs

i literally snapped today and couldn't hold back my anger it took between 100 and 180 seconds per REQUEST to actually do anything. the whole system was unresponsive of course. it runs on a huge machine on amazon and uses RDS so there's no question about machines being bad 4 weeks after and 2 insulted employees later it takes 0.5 seconds for the whole thing to work all 26 000 fields validated, pulled through math formula, cache placed where it's supposed to be, unit and feature tests provided, application performance monitoring added (Sentry) and containers built that are used to deploy - and now deployment takes 1 second instead of 5 fucking days i am at my wits end, i can't even explain how fucking mad i am about this shit, i've been working with code that's SHITTIER than fucking wordpress and symfony combined together in a gay orgy inside a church i had to rant somewhere, it's not a case of "i am fucking awesome", it's a case of "who the fuck am i working with, they can't even get the simplest logic down"

Create a proper library

maxymajzr β€” Today at 2:53 PM

  • library can't be installed with composer
  • no tests, so how do i verify your statements about it?
  • it doesn't offer anything beyond what PDO does
  • there are libraries that do much more, such as Eloquent, Doctrine, Propel

it's not the best code either, there are style issues all over the place. you can do better if you follow any of popular open source libraries; from how to make it installable via composer to doing tests, to code style and even documentation

there's usually only 2 reasons why PHP apps are slow

  1. you load all the data from a DB/NoSQL and filter it inside PHP. it works fast when there's no records, but deteriorates as the data grows
  2. you use cURL to do some HTTP calls from your app to something else, which blocks because the weakest link is the 3rd party app there's virtually no other reason to have a problem with PHP app, it's not going to be CPU bound because you've got no calculations to do in PHP since it's not a language meant to do vector calculations for graphics having said this, here, i'll give you a free gift: https://www.sentry.io/

this one's as good, except it's free if you host it yourself

anyone have a nice way to push logs into some central system?

  • Grafana - software in which you visualize the shit
  • Loki - the nosql where data is stored
  • Promtail - program that checks your logs/laravel.log and sends it to Loki

result: your logs end up in Loki, you query it and use Grafana to display results in a nice dashboard

sanctum does fuck all but go ahead and play with it

laravel has control over this as much as i have control over Saturn's orbit browser controls this

authentication and how http works is engraved into brain in vastly different way (read: i spent MONTHS fucking about with things that people deal within 5 minutes today) so i don't have problems understanding what something does and HOW it does it

but let's take 1 scenario right now token auth

why it exists, what problem it solves and how come you don't usually need it token based auth exists so that busy systems (read: facebook, google) don't need to ask some kind of DB or a service "hey, is this request valid?"

instead, you provide a token that's short lived and that's digitally signed. checking the digital signature and then a few bits of data (issued at, expires at, audience) you can quickly determine if token is valid or not which does not require the use of some kind of databse. all you need to do is have that shared key / private key available for your API to use to check the token

if session is stateless (i.e. there is no Redis or DB or file on the server where session data is written to), then you don't have a problem to scale your server setup to multiple machines and now what you can do is have a system that lets requests in, scales horizontally and uses PKI (public key infrastructure) to verify requests pretty cool, pretty safe, except:

  • tokens can be stolen/lost/leaked
  • if compromised, tokens need to be invalidated
  • invalidation system means that on every request you'd have to check the token against a service, which is what you wanted to avoid
  • therefore, to avoid having that invalidation service, the least of all bads is to create a short lived token (5 mins) after which you refresh it, and if the token is now invalid - refreshing the token would not yield a new token that's the story with tokens next step is to make it easy for people to use on frontend there are 2 methods
  1. save the token in the cookie and let browser handle including the cookie with every request
  2. save the token somewhere, this is usually localstorage and deal with including the token in the request manually the question you need to ask yourself - if you implement everything i wrote here, did you achieve the secure system you were after? what does secure even mean? does it mean "no authorized party will EVER access my API" or does it mean something else? you still have the problem of invalidating tokens in case of a leak using tokens is appealing, and if done right it's GREAT however, tokens are NOT TO BE USED to store session data, they carry immutable data. people tend to use them as sessions, and that's horrible so for most small apps, laravel's regular auth is totally fine. yes, it does change the contents of the cookie on each request but that's fine. let's say you made 2 requests at the same time

when laravel receives those two requests, it'll receive 2 cookies and both cookies will be fine and laravel will let you through it will send a response back, with 2 different cookies (but same contents) and depending on the browser that your user uses, only 1 of the cookies will actually be used for subsequent requests. firefox does this badly and fucks up, while chrome does not however, in reality, how feasible is it that you'd have a user who does more than 1 request at a time if they use your UI? anyway, problem with cookies does not really exist, you can try to force the error but it won't happen

both requests are isolated from each other, they can't interfere at all. and yes, both will produce a different cookie but your browser should just use the one that was the latest

you make 2 concurrent requests to the domain you get 2 responses you'll have 1 cookie

they will be different in the contents but the name will be the same laravel encrypts cookies, and it does it properly. what does properly mean? when you encrypt the same contents/payload, you need to use a different salt (this is usually referred to as Initialization Vector, or IV) so yes, if you hit the same API route twice, you will receive two different encrypted payloads, but the contents inside will be the same however, both cookies you receive concurrently will have the same NAME so your browser will save the contents of the cookie that came with the request that was last

maxymajzr Deployment workflow

i use laradock only for development at work, i don't have your regular setup you can read about online there are servers that deal only with PHP-FPM and servers that deal only with frontend (node.js, vue, nuxt, static files), load blancers etc. but this is the idea:

  • there's a gitlab project, which when it receives an event (merge to production branch or such) initialzies the pipepline

  • pipeline creates docker image and pushes it to local docker registry

  • pipeline also controls k8 which is responsible for handling how and where the updated container ends up in between there's, of course, automated testing, which if it passes - allows the CI/CD to create this docker image in the first place anyway.. you git push, if you didn't fuck up - in a few minutes the project is on staging environment, you get notified via mattermost (our chat) and mail whether it succeeded or not i mean.. it's not that different to every procedure out there, logic is the same. write tests, push to git, run tests, if pass do whatever - with whatever being "create docker image and push to local registry, then pull from local registry"****

  • you don't run your tests in the container itself? mean.. the project gets checked out on a runner which runs the tests which, if they pass, packs it up in a docker image so if i ran the tests in the docker image, it'd be the same result as if when they're ran on the runner and this "runner" is just a machine that gitlab sshs to and basically does "git pull && phpunit"

problem with the "run it in docker" is that i need to feed the docker with env variable values while with the runner approach, devops and devs simply set up variables in gitlab. there's a UI similar to github's where you supply values for certain variables and you're done, then there's no need to fuck about with docker and sending appropriate values in order to pass the test

Explaining

scenario 1

  • i am serious and ready to discuss with the other person and treat them as equal / peer
  • the other person can't listen to me calmly and needs to tell me what they think
  • the other person doesn't care what i have to say, they care what they have to say

result: i wasted my time, the other person heard what they wanted to hear and said what they wanted to say

scenario 2

  • i'm not serious, i don't care about the topic or the result
  • i notice cracks in logic of the person who likes the sound of their own voice
  • i just say/type anything that widens that crak
  • the person's now in an infinite loop and i'm gone

result: i spent a fraction of my time and the "i like to hear the sound of my own voice" is left spending a lot of precious time for nothing

balance has been restored

-maxymajzr

Brainstorming steps

there's never anything different. so, sit down, take a piece of paper, draw how the requests flow in and how they get checked and that'll give you the clue where to look at

Asking Questions:

  • explain what you are after
  • show the query you tried
  • show what you get
  • show PHP solution that works

now other devs have enough info

K8

you know how to deploy 1 container, right? you have a server, you want to stick your app on it, you create a container with your app now you just need to push the container to the server, ez pz it stops being ez pz when you have 100 containers that's where K8 helps you and it does other things, like recycle containers, ensures that when one goes down that another one is booted so your app doesn't experience downtime etc. it's like a utility swiss knife that's size of new york, made so you can avoid doing maintenance and deployment manually sadly, people usually fuck up when it comes to it as to what it does and the stumbling point is authentication

There are different kinds of tests like there's 3 really

that i would say exist

  • 1st-- one is your plain old unit test, if function receives X, does it return expected result type of shit what you'd use JEST for

  • 2nd -- one is "does this shit look ok in all browsers" -> check browserstack (or AWS device farm) this is where selenium automates browsers that run on various operating systems and you basically check if shit renders fine and doens't throw JS errors

  • 3rd one is end to end test or integration test, where you use Cypress to actually simulate a user and how user would use the app and the app under test would use a real API behind the scenes

Session

it takes time() and adds config('session.lifetime') to it then you get a cookie that expires at time() + config('session.lifetime') there's very little point in making the user extend the session, it's something you make user think about and users know fuck all about techy shit instead, you can use what google does and does it really good set a cookie for 2 years literally, just make the session last 2 years. however, track when the user was last active. it basically means you put 2 values in the session - when the session expires and when the user was last active that's how google is able to tell you "your session expired" and just ask you for a password instead of full blown username + pass

https://en.wikipedia.org/wiki/OSI_model

https://datatracker.ietf.org/doc/html/rfc2616

maxymjzr bullshit dictionary

  • "i am not feeling well today..." - he got drunk yesterday
  • "my pc is dead..." - he has a shit PC and wants to play games on the company-provided laptop
  • "docker is giving me hiccups" - he doesn't know what docker is
  • "it works from postman but not from browser" - CORS, of course
  • "in golang, we do it via channels" - he needs to write something to make himself look ok, i asked him about the channels - and goroutines, naturally he never used them - he merely heard of them

Use site.test/api for api in Nginx

server {

    listen                *:80;
    server_name           site.test;

    root                  /var/www/laravel/public;

    index                 index.html index.htm index.php;

    location / {
        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                          http://172.19.0.4:5500; # nuxt url + port
    }
    
    location /api {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_connect_timeout     3m;
        fastcgi_param               SERVER_NAME $host;
        fastcgi_pass                127.0.0.1:9000; # where your php is
        fastcgi_index               index.php;
        fastcgi_buffers             16 16k;
        fastcgi_buffer_size         32k;
        fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout        600;
        include                     fastcgi_params;
    }
}

have you ever used valgrind? πŸ™‚

that's the last tool i use when i can't spot the obvious you use xdebug to generate the .out file that collects the entire callstack, and valgrind shows you functions that are invoked and the entire "path" your code did so you can trace the function that messes with you

valgrid

an http request processed by php-fpm is traced by xdebug, it creates a file that shows which functions were called, internally, in the entire php engine and valgrind is the tool that visualizes it

Tracing Method to Fix Errors

ok, try to solve it on your own, trace the steps

  1. nuxt tries to connect to linereal.test/api
  2. but then it says that it thinks that it's on 127.0.0.1
  3. so nuxt, in workspace, tries to connect to workspace
  4. but connection is refused, there is nothing listening on port 80
  5. which means, it should connect to the API and API is laravel
  6. and to reach that, it has to go through webserver

tldr; in workspace, edit /etc/hosts and put linereal.test <ip of nginx container>

How to get Top Talent

  1. Offer Package with 10 year period.

  2. ultimately, the cheapest strategy is to actively target known talent. which means you should have a way of networking and listening to other companies and try to steal their people which is what big players in our field do

How to make Big Money

figuring out monetization strategy and then you throw software at it

  1. lie about the motives
  2. attract moths that fell for the bullshit story
  3. reach critical mass
  4. turn the members into products
  5. profit
  6. become life coach and have TED talks about what awesome human being you are

Business or working for a FAANG

problem with universities that teach you how to program is that they don't put any emphasis on committing mistakes. the best teacher is failure, sadly (i wish it weren't but it is) in uni, you're in an auditorium and you're listening to the professor talk, and lectures take an hour or more. not all students are the same and it's difficult to pay attention for so long. ultimately, what you end up doing are the same steps, principles and approaches that you were taught by the professor since your goal is to pass the subject. that takes away from focusing on figuring out what the problem is

good professors, in any subject, not just CS, teach students to figure the problem out first. but, we're creating engineers in unis as if we're in a factory. there's no time to make mistakes, reflect on them, ponder over the issue, try more than solution out, compare them and the objectively figure out what a good solution is (not BEST, good) ideal scenario for students is to do work on top of what they learn in CS, that's the way to level up. make mistakes. explore. don't hunt the "best" approach, stop learning patterns by heart. discover them on your own (most devs discover patterns on their own simply because it's the logical solution to the problem) and working for FAANG locks you down into their ecosystems and products. i've a friend in facebook, fucker chooses sidebar color for some retarded app. it's the effort that takes like 0.8 seconds for any human being on this planet, yet he graduated and ended up spending 0.000001% of his capacity for that kind of shit for a "good" salary that doesn't even let him buy a property imagine what happens when you do repetitive, boring, shitty tasks and you're surrounded by many other inexperienced devs - you end up repeating history; you come to illogical conclusions. example is facebook and their performance problems with PHP - their solution was "let's make another language, the FASTER one". and bunch of kids went on to do just that and they fucked up SO bad because, language's speed was not the problem to begin with. it was lack of understanding of the language. so the easiest thing for a dev is to write their own solution, we're better at writing our own code/frameworks/languages than we are at reading other people's code and solutions

the above story is about hacklang, facebook's poor attempt to make better php (spoiler: they failed miserably and wasted ton of time and money) FAANG companies are there to make money. period. and you will be there to make them money. once you're not useful, once you are burned out or old - it's bye bye. that's why they suck and if you're wise, you'll learn from other people's mistakes. smart people leave those companies. it's not because they are dumb or have some kind of "i need to save the world agenda". it's because they're basically code monkeys whose voice is rarely heard to make this shorter and to use analogy. say you want to become a boxer. you go to the gym, you train by punching the bag, the coach shows you the moves and you do that for 4 years.

after 4 years, you enter the ring the first time and there's another boxer. he didn't train like you. he spent 4 years FIGHTING all the time.

and you get hit for the first time and it's lights out. why? theory is good, but without constant repetition and without going to the fight where you make use of the theory - you're going to get knocked out

IMO, the patterns..

it's idiotic to LEARN them by heart and then try to forcibly use them (that is what literally any course about OO is, learn the pattern, forcibly use it) you're bound to rediscover most of the patterns, if you code long enough. it's good to read about them, but what's bad is to use them by force. the programmer should never think about which hammer to use, programmer must think about figuring out what the problem is

reason: when the programmer figures what the problem is, the solution becomes easy - and there can be more than 1 solution i am all for reinventing and reiterating what exists

Productivity? Remove the Cord

maxymajzr β€” Today at 5:40 PM wait, wait, wait, wait, wait a CHAT of any sort is considered.. work-related? πŸ˜„ ever since i was a young and aspiring gamer, we all knew that the unwritten truth is this: if you want to get any work done - disconnect Legit Dongo β€” Today at 5:41 PM then we made our jobs about connecting 😎 webdev kind of impossible while disconnected maxymajzr β€” Today at 5:42 PM ok, if one day you decide to humor me or test the theory, pull the cord - go and work on some simple business as usual CRUD and then tell me how many minutes you spent to achieve what you usually do in hours

Update Laradock Container

stop the container with docker-compose stop name-of-container, build it with docker-compose build name-of-container and then start it with docker-compose up -d name-of-container the FROM in dockerfile usually uses a version specified in .env, always go docker-compose > dockerfile > env

Politics

maxymajzr
 β€” 
Today at 10:59 AM
since i was a kid, i was never able to listen or talk to people who are invested in politics
for some reason, i get this "oh my god, what a bunch of cretinous retards" feel from them
plus, it's boring beyond any reasoning
all that one can gain by being too "loud" in political topics is 1) losing people they had fun with 2) surrounding themselves with mentally-liable people. it's a great recipe to turn your life into a huge pile of shit and to be come one of those people no one wants to be near

Being Productive

maxymajzr
 β€” 
12/07/2021
- stop smoking
- stop drinking
- stop drugs
- cold shower in the morning. your life now sucks and you can be productive
- sit down
- notify client it will take 8 hours to go over the project and to analyze it, charge for it
- if client accepts, sit down, don't be distracted and analyze the project
- open a spreadsheet, write down the steps needed to complete the project
- 1 unit = 1 day of work
- put number of days next to each feature
- triple the number once you are done
- give that number to client
maxymajzr
 β€” 
06/07/2021
what mister @MAX DAMAGE wrote. if you actually want to be productive, turn off discord and any messaging - whatsapp, telegram, signal, emails. there's no human on this planet who can be productive under distraction. even if someone claims they are productive using shit like slack and other "communication" bullshit like that - they're lying
and you can control the "desire" to procastrinate
and to get shit done, just don't talk to anyone, turn discord off. it works wonders for me
if communication is minimized, productivity skyrockets. talking to people online is shit anyway, you can't learn shit except listen to someone brag or pretend they're victims so they can bully others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment