From sport to self confidence

If you know me personally you probably will not agree when someone will tell you, I was shy, very shy. Yep, it’s true. Few years ago I was a young man, introverted and shy. To be clear: I was and I am still an introvert: it is a part of our nature, we can align some things, but personality type is not the same as character. During our life, our decisions, we can change our character, but not personality. I still do not like crowds, a lot of noise, loud parties, but there is one big difference between me now and me a few years ago: I believe in myself, I trust myself. Because of that, other people see me differently and can not believe I was shy. 

Again, if you know me, you know I like sports and I do a few workouts every week. Have pretty interesting habit for almost two months: I run a half-marathon every weekend. It used to be different a few years ago. I really… hated sports. It is true, really. Hard to say, what was the reason for that, but maybe bad experiences from school time? I remember the most popular activity was football and I was never interested in football… or basketball, or volleyball. First, I was not good at any manual things that require precision. Second, I did not feel good in teams in school: with a lot of people playing for themselves, not for the team – they could always complain about others, but they did not motivate others. Because of that and a few other aspects, I was shy and I did not like sports. In effect, at 23 (and even earlier), I was obese, I was really big man.

Then, things started to change. There was not a very successful episode in my life that I am laughing at now: first fascination, I got an elbow and was depressed for about half a year. It was a hard time, but then I changed my mind: decided I would never get down on my knees again, and also started weight training. First by just push-ups, crunches and squats, then using an exercise bench in my home. It was nice, very nice and I felt better and better every week. When spring came, I started cycling my old bike – just a few kilometres, to get to know my local area. I changed that old bike quickly to a new one, a trekking bike and cycled farther and farther. It was the beginning of my adventure with bikes.

Last year I made my “final fantasy”: cycled from my home to Baltic Sea in just one day, it was about 400 km. Did it with my friend, another local cyclist. Of course right now I have a different bike, different knowledge, physical level, but it is a clue: it was a process, step by step I builded different person, a different me. During that, I gained a lot of confidence. There was a period when I wanted to start each race: two MTB races in one month, next month road race and mix using cross bike, next be a part of a triathlon team (of course on bike). Did I want to prove something to myself? Maybe, I am not sure right now. Right now it is different: I do not race, do not have plans for that, just want to have a lot of fun… and make the transition from cycling to running, because after the first, completely unplanned marathon distance, I feel I found the next milestone in my life. 

Of course during these few years, I did a lot of things not related to any sports: getting a sweetheart, working in a startup, learning new things, trying new things, all of them are great challenges but I think sport was the basic, the fundamental of all changes. It allowed me to think better about myself, to trust myself. Right now I do not have to prove anything in races: I know I can, so it is just my choice. In most cases, I will not be interested, in some cases, I will do it on my terms: right now I want to do an ultra run, but not on an official competition, just for fun. And it is amazing, it works in different areas of life: you do not have to, you just want. It can also be funny, then in the gym (I do not look strong), someone starts a conversation, we talk about sports, I mention cycling and there is a question for me: “did you ever cycled 100 km?”. I can only smile and answer: yeah… it was fine, but it was only the beginning. 

Right now sport is part of my life and I know, it will be as long as it will be possible. It is a habit, it is passion, sometimes it is a positive addiction. I believe, without sport I would not be where I am – and I am very content and happy now. Can not recommend strict sports, competitions, a lot of austerities, keep pushing forward anyway – no, all these things are not important. Important is consistency and something like discipline. Even walking can help us a lot: it is a great time to refresh our minds, meditate, and rethink important questions. If our activities become passion, it is fine, we will change our life. 

Reduce WSL and Docker disks size

I really like WSL/WSL2 in Windows – it provides a lot of features with minimal performance impact (WSL2) and I can still use Windows app. In combination with Docker, it can handle a lot of things and it’s much better for me than for example MacOS. One problem I discovered last time is space consumed by WSL, and also Docker volumes. In both cases, Windows uses Virtual Hard Disk (VHD) format, vhdx files to store all data.

The problem is Windows can extend virtual disks on demand, without asking about that, but doesn’t reclaim free space if we make bigger changes inside WSL filesystem or Docker volumes. I had few IDE versions and different instances, each about 1,5 – 2 GB, and it consumed a lot of space. After deletion them from WSL filesystem, I didn’t get any real free space on my computer disk. We have to manually compact virtual hard disks to do that. How to do this? It’s quite simple. First, we have to enable Hyper-V if it’s not enabled. Just run terminal or PowerShell with admin privileges and execute this command:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

System restart may be required after that.

Second step is to compact disks. First, close Docker Desktop if it’s running and also shut down WSL by command:

wsl --shutdown

Right now we can compact disks, command is also very simple:

Optimize-VHD -Path "path_to_disk.vhdx" -Mode Full  

The question is, where can we find these disks?

You can find disks created by Docker in:

SYSTEM_DRIVE\Users\your_username\Local\Docker\wsl // and then directories inside

Second thing is related to your WSL distro – all should be in the same main directory, but with different subdirectory. I use Ubuntu, from Canonical and in that case, data is located on:

SYSTEM_DRIVE\Users\your_username\Local\Packages\CanonicalGroupLimited(...)\LocalState\ext4.vhdx

Of course you can use search or tools like Everything to locale any *.vhdx file easily.

After execute command, file should become smaller and you will have more free space.

The most important question in life

Last time I think about long-term goals in my life and what I really want to do, to achieve. These thoughts caused I decided to write a post about some of them. You will find sport-based examples in this post, but these are just analogies, and you can translate it into other views. The most important question is:

What do you want from your life, and how do you want to achieve that?

Even this year, I was a “bike-mech” geek. I really liked to read about cycling technical, new groupsets, different and proposed solutions, watch reviews and discuss with people about that. I have been in such point for few years, and it was fine for me. During that time, I also tested some things to form an opinion: I had about nine different bikes (not in the same time of course), tried tubeless three or four times, changed bike shoes, experimented with HR straps and bike computers… Whow, it was a ton of gadgets and bike parts. Of course, it was fine then, but right now when I think about that… it was a bit crazy. To be honest, right now I feel tired and do not want to join that “rat race” anymore. Because of COVID, some markets gone mad – and bicycle market is one of them. Prices are high, there are not enough parts, and it looks like situation will not be better in 2022, or even in 2023.

So, what choice do I have? What choice do other cyclists have? Can we only buy new things for higher prices? No, we can quit that race and stop doing that, we can look for something different, something simpler and more effective at the same time. In reality, I found something like that, and it is running. Much simpler, much more suitable for countries like Poland, when only max four months in the year are surprisingly good for cycling, without tons of gadgets and available to do in many unusual places: if I will go for business trip, holidays, to close family. No problem, I will only take shoes and clothes and I will be ready for that. With bike, logistic is bigger problem and it causes you must be “more stable”.

I live with my wife in the apartment. It is not big, but it is also not small – we have separate bedroom and two additional rooms, so for two people, it is enough place. Living in such apartment has disadvantages: your neighbors may be too noisy sometimes, you have limited space for all your things, you cannot decide about some matters like for example additional, independent power source. From my perspective, also cleaning bike is sometimes problematic and in effect, I avoid riding in bad conditions. But it also has advantages. I do not care about snow during winter: there are people hired for that. I do not care about grass around the building (and I really hate mowing), about heating, electrical or water systems or communal waste. I know that because I’ve lived in house for over 25 years. In apartment, a lot of things is included in rent I pay every month and it is extremely comfortable, I can spend the same time for more interesting things.

Last time I thought about my own house. A lot of people decide to loan a credit and build their one house to avoid some apartments disadvantages. I think some of them – not all of course – forgot about all new work they will have with house. All additional costs, all time spend for mowing, painting, gardening etc. Yes, of course you can hire people to do that, but in such case, you will have to earn additional money to do that so… you will spend more time in job, or in creating additional funding sources. I read article about people how won big lotteries. After a year, about 90-95% of them were… complete bankruptcy. Why? Because they were not prepared for such money, they do not invest that money, just spend for things which generated costs: new house with pool? Nice! But you will have to pay for cleaning that pool. Nice, fast car? Why not, but every inspection, every part will be more expensive. And these things will not earn additional money for you, they will only generate costs.

I think a lot of people want many things without real reasons. Just because other people have these things, because these things are fancy. In Poland, still some people think that iPhone is luxurious, a kind of social status symbol. It is bullshit. It is just phone, mass gadget. In the USA, iPhone has something about 50% of market. Are all US citizens rich? No. When are you rich? It is hard to say, because every time you can find people with more money, more things, more companies etc. It does not make sense to compete with different people. The only sense is to compete with yourself – if you really want to improve something in your life.

If you do not know, what you want and just look for other people, you waste a lot of energy, will power, money and time for something that does not bring you joy. I like competition, I like challenges, but sometimes I see, that comparing yourself with others does not make any sense at all. We can find exceptionally good example in sport, in any sport-social apps like Strava. It is fine to show your results, to share pictures from interesting events, to involve other people or be involved by them. But if we decide to train to be better than others on our feed… It is another bummer. It will be never-ending story because we can always find better people. And guess what – professional athletes do not use such apps! Why? Because social aspect is not important for them. They need raw training data, for trainers, to prepare better training and recovery plans, to prepare for the real competition.

The fun thing is that we do not need most of things we “want”. We spend time to earn money, then buy them and… after 2-3 weeks the feeling of novelty disappears. So, we want next new thing… vicious circle, which offers us only additional work, additional worries, time we spend for something we will not remember on our deathbed. So simple, but I realized that just recently and right now I wonder a long time before I buy something new. Life passes, and we are still in the race. We can win it, but for what price? Did you ever think about that? If no, it is suitable time to do that.

Do not get me wrong. I do not think about abandon personal development and endeavor – I am a type of fighter, warrior and I always have interesting goals – even if I think, that systems-based approach is much better. That post is not something like “it doesn’t make sense”. It is about “maybe something doesn’t make sense”. Thinking and changing your mind is never bad. Aimlessly going one road never makes sense

MongoDB aggregation – why stages order really matters

MongoDB aggregation framework is very powerful tool. It can do much more than many relation databases features, but if we do not know or do not understand some simple rules, effects can be… a bit strange. Especially if we want to use it in PHP and build aggregation step by step, as array of commands. Great example is to use sorting or limiting, one small mistake and it will return false documents. Why? Because we can forget about commands order. 

When we use standard Eloquent, it’s not a problem to first set some conditions, then add sorting and then additional conditions, everything will be fine, because it will use simple find on Mongo: 

$query = MyModel::query()->where('foo', 'bar');
$query->limit(10);
$query->orderBy('name', 'desc');
$query->where('param1', 'val1');
$results = $query->get();

 
In that example, everything will be ok, because query builder will do all required things. But what if we will try to do the same thing using aggregation framework? We can do that in raw Mongo, but use another PHP and Laravel example, it will the same except small syntax changes: 

$aggregate = [];
$aggregate = [
	'$match' => [
		'foo' => 'bar'
	]
];
$aggregate = [
	'$limit' => 10
];
$aggregate = [
	'$sort' => ['name' => -1]
];
$aggregate = [
	'$match' => [
		'param1' => 'val1'
	]
];
        
$results = MyModel::raw(function (Builder $builder) use ($aggregate)) {
	return $builder->$aggregate;
};

In that case, results will be completely different. Why? Because when we use aggregation, command order matters. It will first filter documents and receive only these with field “foo” with “bar” value, then it will limit them to just 10, then sort and in the end, use additional filter by “param1” field. As you can see, limiter inside will cause, that a lot of documents will be skipped and not included in query. Its why command order is important – it allows us to make very complex queries, modify data, join collections in different way (using $lookup) but we should now, what we want to achieve.  

Ok, so, how should be prepared aggregation to work like simple query from first example? We need to change order. Also, we can simplify that by merge two $match stages into one: 

$aggregate = [];
$aggregate = [
	'$match' => [
		'foo' => 'bar',
		'param1' => 'val1'
	]
];
$aggregate = [
	'$sort' => ['name' => -1]
];
$aggregate = [
	'$limit' => 10
];
        
$results = MyModel::raw(function (Builder $builder) use ($aggregate)) {
	return $builder->$aggregate;
};

In that case, aggregation will first filter documents, then sort them and finally use limiter – no risk, that some documents meet our requirements will be skipped.  

Conditional query in Laravel Eloquent

Laravel Eloquent is very powerful and we can use it in many cases to get or filer data. One very common situation is to build query according to some statements and conditionals. The most common way to achieve that is to build id step by step: 

$onlyUnread = $request->only_unread ?? null;

$query = Article::query()->where('active', true);
if ($onlyUnread) {
    $query->where('unread', true);
}

$articles = $query->get();

Last time I checked some old documentation and found different method – when. It allows us to simplify that process a lot and include are conditionals and additional query steps in just one command: 

$articles = Article::query()->where('active', true)
    ->when($onlyUnread, function (Builder $query): Builder {
        return $query->where('unread', true);
    })
    ->get();

It’s much cleaner than build step by step, and because we still use Builder object, we can do exactly the same things like on higher level. Of course, it may be necessary to use some additional params – of course it is not a problem, we only must send them to function inside:

$articles = Article::query()->where('active', true)
    ->when($myCondition, function (Builder $query) use ($param1, $param2): Builder {
        return $query->where('unread', true)
            ->orWhere('param1', $param1)
            ->orWhere('param2', $param2);
    })
    ->get();

It is also possible to use when more than once – if you need set some steps with separate conditions, no problem. I do not know, why this is not present in current documentation, but when method is available in current Laravel version and can be used without additional steps.