samdark blog ☕️

Description
Notes taken by Alexander Makarov, lead of Yii framework, CTO of Twindo.ai and a long term IT engineering manager.

- Official Yii updates: www.yiiframework.com
- Consulting: asapirl.com
Advertising
We recommend to visit

Community chat: https://t.me/hamster_kombat_chat_2

Twitter: x.com/hamster_kombat

YouTube: https://www.youtube.com/@HamsterKombat_Official

Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/

Last updated 3 months, 2 weeks ago

Your easy, fun crypto trading app for buying and trading any crypto on the market.

📱 App: @Blum
🆘 Help: @BlumSupport
ℹ️ Chat: @BlumCrypto_Chat

Last updated 3 months, 1 week ago

Turn your endless taps into a financial tool.
Join @tapswap_bot


Collaboration - @taping_Guru

Last updated 5 days, 5 hours ago

5 months, 3 weeks ago

*⚡️PHP performance: in_array → array_key_exists*

Let's imagine we need to process each user exactly once:

```
$processedIds = [];

foreach ($users as $user) {
if (in_array($user['id'], $processedIds)) {
continue;
}

// send an email to user $processedIds[] = $user['id'];

}
```

The complexity of in_array is O(n) and that's not great considering foreach which makes it O(n²). Is it possible to optimize? Yes:

```
$processedIds = [];

foreach ($users as $user) {
if (array_key_exists($user['id'], $processedIds)) {
continue;
}

// send an email to user $processedIds[$user['id']] = 1;

}
```

We've reverted array so IDs are now keys. The complexity of array_key_exists is close to O(1) so total complexity is now O(n).

#php #in_array #array_key_exists #performance

6 months, 2 weeks ago

*? Situational awareness. The decade ahead.*

Predictions about AI development in the next decade by ex-OpenAI employee Leopold Aschenbrenner.

Quite interesting read. Not sure we'll see AGI and ASI in the next 5 years but it would definitely be very interesting times.

https://situational-awareness.ai/wp-content/uploads/2024/06/situationalawareness.pdf

#ai #agi #asi

7 months ago

*? The technical books that affected me*

That's not the full list, of course.

?Designing Data-Intensive Applications - Applications Kleppmann, Martin
?Object Design Style Guide - Noback, Matthias
?Principles of Package Design: Creating Reusable Software Components - Noback, Matthias
? Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development - Larman, Craig
?Mastering Regular Expressions - Friedl, Jeffrey E.F.
?Phparchitect's Zend PHP 5 Certification Study Guide - Shafik, Davey
?Essential PHP Security - Shiflett, Chris
?Http Developer's Handbook - Shiflett, Chris
?Pro Git - Chacon, Scott

#books

8 months ago

*How do you clean up GitLab instances?*

For now I have the following in my crontab so GitLab doesn't take all the disk space:

rm \-rf /home/gitlab\-runner/builds/* && docker system prune \-f && docker volume prune \-f && docker image prune \-af

Is there a better way?

#gitlab

8 months, 1 week ago

*⚡️PHP on Alpine getting faster*

Some time ago I've posted about PHP being slow on Alpine. I didn't stop there and researched about musl, alternative memory allocators and how it's done in PHP.

Unfortunately, I don't have enough time and competence to make some pull requests. Fortunately, I've asked Roman Pronsky about it and he passed it to PHP core team.

Results are promising so far

GitHub

Remove zend_strtod mutex by arnaud-lb · Pull Request #13974 · php/php-src

zend\_strtod.c uses a global state (mostly an allocation freelist) protected by a mutex in ZTS builds. This state is used by zend\_dtoa(), zend\_strtod(), and variants. This creates a lot of contentio...

8 months, 3 weeks ago
11 months ago

*? SVN to git*

Majority of projects migrated to git long time ago. The ones left are interesting. You can do the migration for small SVN repos with git svn clone but for larger repos it would take too much time. Years in my case. Fortunately, there is svn-all-fast-export that works much faster.

*? Prepare*

  1. Install svn\-all\-fast\-export, available as Ubuntu package, sudo apt install svn\-all\-fast\-export.
  2. Get a copy of server's SVN repository (not the one checked out!) and put it into /svn/ directory.

*? Get authors mapping*

  1. Checkout repository from SVN into a temp directory of choice.
  2. Get authors with svn log \-\-xml \-\-quiet | grep author | sort \-u | perl \-pe 's/.*>(.*?)<.*/$1 = /' > authors.txt.
  3. Adjust these so format is schacon = Scott Chacon <[email protected]>.
  4. Copy the file to /authors.txt.
  5. You can remove checked out repository now.

*?Prepare rules*

Create /rules\-file:

```
create repository git
end repository

match /trunk/
repository git
branch master
end match

match /branches/([^/]+)/
repository git
branch \1
end match

match /
end match
```

In the above we'll create a /git/ directory w/ git repository. If SVN path starts with trunk, branches, or tags we add that to git repo as master, branches, or tags correspondingly.
Last rule is to ignore everything else. The rules might vary depending on your SVN layout.

Sometimes it's easier to include directories explicitly and ignore everything else. Usually it's enough, makes repository smaller and avoids tricky issues:

```
create repository git
end repository

match /(trunk|bla1|bla2)/
repository git
branch master
end match

match /
end match
```

*?Run the conversion*

svn\-all\-fast\-export \-\-identity\-map authors.txt \-\-rules rules\-file \-\-add\-metadata \-\-svn\-branches \-\-debug\-rules \-\-svn\-ignore \-\-empty\-dirs svn/

What you get in /git/ is a bare repository.

Do cleanup

git config pack.windowMemory 50m git gc \-\-aggressive

Push it

git remote add origin git@example\-server:repo.git git push origin \-\-all git push origin \-\-tags

*?References*

- Switching an SVN repository to Git with KDE's Svn2Git
- Projects/MoveToGit/UsingSvn2Git
- Git and Other Systems - Migrating to Git
- Svn2Git svn-all-fast-export Common Errors
- git fast-import: Empty path component found in input

GitHub

GitHub - svn-all-fast-export/svn2git: :octopus: A fast-import based converter for an svn repo to git repos

:octopus: A fast-import based converter for an svn repo to git repos - svn-all-fast-export/svn2git

11 months, 1 week ago

PHP recursion segfaults

PHP doesn't detect recursion by itself causing stack overflow and a segfault with SIGSEGV, exit code 139. In order to have a proper error with a stack trace you can install Xdebug and enable it in develop mode with XDEBUG_MODE=develop environment variable.

Then you'll get a proper stack trace pointing exactly to the cause:

/app/src/Entity/WeatherAlert/WeatherAlertSiteSettings.php:586 /app/src/Entity/Project/Site.php:354 /app/src/Entity/WeatherAlert/WeatherAlertSiteSettings.php:586 /app/src/Entity/Project/Site.php:354 /app/src/Entity/WeatherAlert/WeatherAlertSiteSettings.php:586 /app/src/Entity/Project/Site.php:354

#php

xdebug.org

Xdebug - Debugger and Profiler Tool for PHP

Xdebug: A powerful debugger for PHP

11 months, 2 weeks ago
11 months, 3 weeks ago

? 2023 #2

? Books

This year books are a mix of fiction, IT and psychology.

- Anxiety Free: Unravel Your Fears Before They Unravel You @ Leahy, Robert L.
- The Three-Body Problem @ Liu, Cixin
- Thicker than Blood @ Omer, Mike
- In the Darkness @ Omer, Mike
- A Killer's Mind @ Omer, Mike
- Crooked Kingdom @ Bardugo, Leigh
- Six of Crows @ Bardugo, Leigh
- The Clean Coder: A Code of Conduct for Professional Programmers @ Martin, Robert C.
- How to Control Your Anxiety Before It Controls You @ Albert Ellis, Ph.D. and Kristene A. Doyle, Ph.D. Sc.D
- Entreprenerd: Building a Multi-Million-Dollar Business with Open Source Software @ Lowagie, Bruno

✈️ Travel

Armenia, Georgia, Indonesia, Malaysia, Russia.

?My wishes for 2024

- I wish for worldwide peace, even though it may seem unlikely.
- Yii3 "release". Likely to happen.
- LLMs ate the world. These are on hype. Hope these aren't used mindlessly for serious decisions.

Americor

Americor: Debt Consolidation and Debt Settlement

Achieve financial freedom with Americor's industry-leading debt relief solutions. Explore our debt consolidation loans, debt settlement, and other services now!

We recommend to visit

Community chat: https://t.me/hamster_kombat_chat_2

Twitter: x.com/hamster_kombat

YouTube: https://www.youtube.com/@HamsterKombat_Official

Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/

Last updated 3 months, 2 weeks ago

Your easy, fun crypto trading app for buying and trading any crypto on the market.

📱 App: @Blum
🆘 Help: @BlumSupport
ℹ️ Chat: @BlumCrypto_Chat

Last updated 3 months, 1 week ago

Turn your endless taps into a financial tool.
Join @tapswap_bot


Collaboration - @taping_Guru

Last updated 5 days, 5 hours ago