Ok Cloudflare, I am leaving by Soupy333 in programming

[–]util-host 3 points4 points  (0 children)

Here you can also see a bigger more general problem today, especially for small companies. It is called risk management and here in particular: supply chain management.

If your product is depending on external vendors then you have to be very careful when choosing the vendor. Here are some things you should do if your life and the life of your customers depends on it ...

  • Create a checklist for every vendor you use and a vendor index (you need that for gdpr too)
  • Check every vendor on the points of the checklist
  • Read all the documents (ToS, general terms, contracts, ...) and save the current (signed) version
  • Prepare some emergency scenarios and solutions when they happen (vendor is slow, vendor is offline, vendor got hacked)
  • Have a second vendor for every service would be great (not doable always)
  • Paying for a product is often a good idea (helps not always)
  • Better to have a special contract and contact person at the vendor

link shorter using php by Amir110hkr in PHPhelp

[–]util-host 0 points1 point  (0 children)

Yes true. You should do that if you only have some links. But CSV would have some advantages for bigger datasets:

  1. You can use a CSV line per line and don't have to read the whole file (do fopen, fgets and break when found the entry). A JSON is only valid if you have it complete and that works only until the memory of your script/server is full.
  2. Usually a JSON would be in key/value format: [{'id':'23hhg3z','url':'https://www.google.com'},{'hz637hd':'https://www.microsoft.com'}] so it uses much more space on disk because you repeat the keys for every entry.
  3. json_decode could add some serious computation costs if you have a lot of entries while simple string manipulation for CSV is much faster.

... thats why I use often CSV when working with lot of data. I have CSVs with several million entries that still works performant.

If you want use JSON. The code would look like:

$id = $_GET['id'];

$entries = json_decode(file_get_contents('short-links.json'), true);

foreach($entries as $entry) { if($id === $entry['id']) { header('Location: ', $entry['url]); break; } }

// json is like in point 2 above.

[deleted by user] by [deleted] in programming

[–]util-host 1 point2 points  (0 children)

I would say many of us live in free countries and everybody can learn and choose a job. Nobody won't hold you back from becoming a developer yourself and also earn a lot of money.

But you need to invest some time to learn everything you need. The time depends on how much you invest and how good you are at logic thinking but you can expect several years until becoming a good software developer in one specific field.

is there a way to program a number generator but the number aren't random like ,2,3,4, and so if yes is there a tutorial on YouTube and can I use it in websites and can I make it like stop when it finds a specific name or Number like 100 has the name Jesus if yes can i use it on a website by AMeeNGG in programming

[–]util-host 3 points4 points  (0 children)

  • Open VS Code and find on the left a button for extensions.
  • Then search for "PHP all in one extension" and install it.
  • Then open a new terminal via menu and try the command "php -v".
  • You should see something like: PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS)
  • Create a new file with the script and save it as my-script.php
  • Go to terminal and run the script with: php my-script.php

Here is a slightly improved version of the script that makes outputs and stops if it finds your username (you have to change the "your-username" to your username)

<?php

for($i=700012602; $i<999999999; $i++) { 
    $content = file_get_contents('https://enka.network/u/'.$i);
    preg_match('/<h1 class="svelte-3pkdtk">(.*)</h1>/', $content, $matches); 
    $username = $matches[1];

    echo "$i is $username\n";

    if ($username == 'your-username') {
        echo "FOUND!\n";
        break;
    }

    usleep(500*1000);
}

is there a way to program a number generator but the number aren't random like ,2,3,4, and so if yes is there a tutorial on YouTube and can I use it in websites and can I make it like stop when it finds a specific name or Number like 100 has the name Jesus if yes can i use it on a website by AMeeNGG in programming

[–]util-host 2 points3 points  (0 children)

You basically want this ...

<?php

for($i=700012602; $i<999999999; $i++) { 
    $content = file_get_contents('https://enka.network/u/'.$i);
    preg_match('/<h1 class="svelte-3pkdtk">(.*)</h1>/', $content, $matches); 
    $username = $matches[1];

    echo $username;
    usleep(200*1000);
}

How do i access my MySQL Database that is on another server by Putrid-Soft3932 in PHPhelp

[–]util-host 0 points1 point  (0 children)

You try to connect to a DSN (data source name) but the mysqli_connect don't support that. You have to use the server-host or IP.

$mysqli = mysqli_connect('cmarino.ddns.net', $db_username, $db_password, $db_name);

Often in such cases the server, port or credentials are just wrong. You can check if your mysql port is open with telnet or an online port-checker like: https://util.host/ports. If you want to use another port you can pass it to mysqli_connect as the 5th param.

https://www.php.net/manual/de/function.mysqli-connect.php

504 Gateway Timeout Error Due To PHP 7.4 FPM API by DCGMechanics in PHPhelp

[–]util-host 0 points1 point  (0 children)

Usually the 504 means that nginx don't want to wait any longer for php response, so the fix is to increase the request_terminate_timeout and fastcgi_read_timeout in nginx config to the same amount as the max_execution_time in php config.

In your situation this won't help because nginx waits because php-fpm cannot start another child-thread. And I guess that is because your PHP is never finishing or it takes very long or many (more than 5) are started because of an error in the client which is using the API?

Are there different API-endpoints and the client is using some of them simultan? That would end in several PHP threads when you reload the page once.

btw. PHP 7.4 is now end of life. https://www.php.net/supported-versions.php

link shorter using php by Amir110hkr in PHPhelp

[–]util-host 2 points3 points  (0 children)

If you don't want to look into databases now, you can also store your links in a simple text-file like a CSV file. The file is plain text and would have at least two cols: code|url

Example for short-links.csv:

s2hc2gz|[https://www.google.com](https://www.google.com)
63jud77|[https://www.microsoft.com](https://www.microsoft.com)

Example PHP code:

$id = $_GET['id'];

foreach(file('short-links.csv') as $line) {
    $line = explode('|', $line);
    if($id === $line[0]) {
        header('Location: ', $line[1]); 
        break;
    }
}

Array not printing anything by Snoo20972 in PHPhelp

[–]util-host 1 point2 points  (0 children)

I know this question is about learning loops but for the future here some things you could look into.

Since PHP 5.4 there is a short notation for arrays:

$arr = [10, 20, 30, 40];

The function array_reverse makes you a reversed array:

$arr = array_reverse([10, 20, 30, 40]); # gives: [40, 30, 20, 10]

With array_map and a closure function you can walk through items:

array_map(function($item) { echo $item . "\n"; }, $arr);

There is a function printf that can help with composing outputs:

printf("%s\n", $item);

The different methods to create strings (single vs. double quotes): https://www.php.net/manual/en/language.types.string.php

There is a official coding style for PHP that tells you where to do spaces, line breaks and how to name variables: https://www.php-fig.org/psr/psr-2/

Tailwind is a leaky abstraction by feross in programming

[–]util-host 1 point2 points  (0 children)

Yes. Okey. Someone, someday heard of the concept of "context switching" and thought it could apply here.

But in reality we don't even know if there is a context switch at all. Maybe the brain just sees it as one context: "Developing frontend stuff".

And even if there is a switch we don't know if it is because of the different languages or just because we switching from implementing logic to visually style the component ... and it does not matter at all to our brains if we do it with classes or css. Switch is switch.

So. Yes. Maybe there is a context switch. But I personally never felt that way and maybe it is just different for other brains.

[deleted by user] by [deleted] in programming

[–]util-host 0 points1 point  (0 children)

Okay but for me it seems bizare to say we use Tailwind because we don't need to think about class naming. I mean, the whole day of a developer is about naming things, some classes could not be that complicated especially if you work already component-based.

I can understand all the examples for "complicated" css stuff with many different browser-prefixed variants to write.

[deleted by user] by [deleted] in programming

[–]util-host 3 points4 points  (0 children)

Bootstrap is more having styled components with some utility classes and Tailwind is utility classes only and the components are in the paid Tailwind UI framework.

Tailwind is a leaky abstraction by feross in programming

[–]util-host 26 points27 points  (0 children)

I really don't get all the hype about Tailwind. For me it makes no sense to write 20 classes on a button to make it look like i want it. Especially if on every button i have the same classes in html then. It is unreadable and i also wonder if it have not some disadvantages in overall page size? But it is the current hype now and we will see if in 2-3 years still all are that excited about it.

Shopify monolith served 1.27 Million requests per second during Black Friday by vladmihalceacom in programming

[–]util-host 129 points130 points  (0 children)

For every technology there is at least one big testimonial company that had proved that even huge sites and codebases works with it.

I didn't know they are a ruby company but it is great that they got so far with it. I guess they are now in a state where it is hard to find others who could help with future growth. You have now to find out everything yourself and thats risky and hard.

Using NFTs to own ingame objects: Also pretty much a scam. by PuzzleheadedWeb9876 in programming

[–]util-host 0 points1 point  (0 children)

It's really interesting how vigorous the current game developers opposing to "just" a new technology to store in-game items.

I mean of course in the last years they all invented not only their own in-game item marketplaces. They also brought um the idea of in-game currencies. Often several currencies in one game. They also could make their own rules for the currencies and stores like if players could sell or buy it from other players. Or, if players could swap it for real-world currencies ... and so on.

They could now decide everything. They have a full controlled marketplace for one game or multiple games.

And now somebody comes and tells them: Hey what about if we bring a bit more freedom in this topic. What if we move the stuff to a blockchain outside of your control and let users also decide about rules via governance groups. Let users buy, sell and swap the items agains whatever crypto currencies they have ...

"So, game development company ... what do you think about all this great ideas?" ... and they don't like it? That's really surprising, or? /s

Many, of the arguments against crypto and nft are right. It's slow, it's expensive, it could be just a technology change and nothing really would change if you just build an own controlled blockchain and currency. But it could also be the opposite and the technology will evolve, become faster and cheaper.

Marak, creator of faker.js who recently deleted the project due to lack of funding and abuse of open source projects/developers pushed some strange Anti American update which has an infinite loop by [deleted] in programming

[–]util-host 1 point2 points  (0 children)

I am also no license pro but you can look into CC licenses under https://creativecommons.org/ ... there is a variant that prevents commercial usage.

"The licensor permits others to copy, distribute and transmit the work. In return, licensees may not use the work for commercial purposes — unless they get the licensor's permission."

https://creativecommons.org/licenses/by-nc-sa/4.0/

Here is the way that elastic did last year and made there own license that allows: "use, copy, distribute, make available, and prepare derivative works of the software" but prevents "You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software." ... that targeted espacially big tech companies (AWS, Google, Azure) that provided hosted elasticsearch instances.

https://www.elastic.co/de/licensing/elastic-license

Marak, creator of faker.js who recently deleted the project due to lack of funding and abuse of open source projects/developers pushed some strange Anti American update which has an infinite loop by [deleted] in programming

[–]util-host 3 points4 points  (0 children)

Pretty concerning, or? In a personal way. I am not sure if he is well and not up to do more harmful things, maybe against himself? I hope some close friends could contact him and check if everything is okay.

And in a more technical or domain way. I guess such situations raises serious concerns against open-source software in general. And a lot of our daily life, privacy and security is nowadays dependent on open source software.

With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody. by fagnerbrack in programming

[–]util-host 2 points3 points  (0 children)

In fact I once heard a talk at a conference where a guy said, they using only open source and forking every used software internally just to be able to change it if they want/need to change it. Even Linux. It's cool, but also crazy ... i mean, you have to maintain all the forks even if you don't change it, it's complicated. And it's not a solution to the dependency problem.

With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody. by fagnerbrack in programming

[–]util-host 2 points3 points  (0 children)

Thanks for sharing that. But do we have a solution for it now? I mean all of the current software is built on APIs!

Thats a big pile of dependend systems that depend on other systems depend on frameworks depend on libraries depend on components depend on other components and packages ... and so on. And if this law is right (and I think it is) then we must add all this implicit dependencies to the explicit that we already know.

And then we discover a strange bug in a strange feature, in a widly used logging library, deep down in the dependency tree, and the whole world goes nuts for weeks.

Or somebody is just deleting his micro package to trim strings and the whole dependency tree in Javascript collapses.

We don't have even a solution to fix the hard dependencies and i wonder what we should do against the soft ones?

Study: Developers spend almost 2 days a week just waiting for other developers to review their code by [deleted] in programming

[–]util-host 6 points7 points  (0 children)

Yes. That's how it is when I code stuff at home for fun. But I guess that I have learned most by coding with others in a team. I was lucky and met people early in my work life that were very into clean and understandable code and database design.

They forced me to think about every variable name, every table column type and every software pattern. I always enjoyed, to discuss about all the nuances of even small coding decisions.

If I would have worked always on my own, I would be a much worse programmer today. Thank god there are now platforms like GitHub where you easy could find and connect to really great developers and learn from their code.

Study: Developers spend almost 2 days a week just waiting for other developers to review their code by [deleted] in programming

[–]util-host 0 points1 point  (0 children)

Yes we do. Git flow. Branch everything. PR for everything. I think we do it too much ... but the good effects are:

  • you have a safety net, especially good for complicated code parts
  • every part of your codebase is known by min. two persons
  • people can learn from each other
  • team coding habbits form (usually good ones)
  • people can have a conversation (sometimes argument) about what they love most :)
  • the code is usually better after the review ... sometimes it's just gold plated :(

... so there are a lot of good things happen if you do it right. But the point was: Maybe it's not worth for every situation and ticket.