From 8697555125c57ae64a0c9b78514b4aac4fd523de Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Tue, 27 Jun 2023 14:50:20 +0200 Subject: Massive formatting and added figcaption --- ...01-13-most-likely-to-succeed-in-year-of-2011.md | 36 +-- .../posts/2012-03-09-led-technology-not-so-eco.md | 30 +- .../posts/2013-10-24-wireless-sensor-networks.md | 64 ++-- .../2015-11-10-software-development-pitfalls.md | 256 ++++++++-------- .../2017-03-07-golang-profiling-simplified.md | 24 +- ...04-17-what-i-ve-learned-developing-ad-server.md | 154 +++++----- ...ng-python-web-applications-with-visual-tools.md | 47 +-- content/posts/2017-08-11-simple-iot-application.md | 308 +++++++++---------- ...digitalocean-spaces-object-storage-with-fuse.md | 152 +++++----- ...01-03-encoding-binary-data-into-dna-sequence.md | 143 +++++---- .../2019-10-14-simplifying-and-reducing-clutter.md | 85 +++--- ...g-sentiment-analysis-for-clickbait-detection.md | 50 +-- .../2020-03-22-simple-sse-based-pubsub-server.md | 132 ++++---- ...0-03-27-create-placeholder-images-with-sharp.md | 46 +-- ...nge-case-of-elasticsearch-allocation-failure.md | 74 ++--- ...30-my-love-and-hate-relationship-with-nodejs.md | 170 ++++++----- content/posts/2020-05-05-remote-work.md | 59 ++-- .../2020-08-15-systemd-disable-wake-onmouse.md | 43 +-- content/posts/2020-09-06-esp-and-micropython.md | 58 ++-- content/posts/2020-09-08-bind-warning-on-login.md | 27 +- content/posts/2020-09-09-digitalocean-sync.md | 83 ++--- .../posts/2021-01-24-replacing-dropbox-with-s3.md | 61 ++-- content/posts/2021-01-25-goaccess.md | 109 +++---- content/posts/2021-06-26-simple-world-clock.md | 48 +-- ...from-internet-consumer-to-full-hominum-again.md | 118 ++++---- ...n-based-riced-up-distribution-for-developers.md | 165 +++++----- ...021-12-25-running-golang-application-as-pid1.md | 7 +- .../2021-12-30-wap-mobile-web-before-the-web.md | 87 +++--- .../posts/2022-06-30-trying-out-helix-editor.md | 33 +- ...22-07-05-what-would-dna-sound-if-synthesized.md | 163 +++++----- .../2022-08-13-algae-spotted-on-river-sava.md | 8 +- ...10-06-state-of-web-technologies-in-year-2022.md | 334 ++++++++++----------- ...hat-sound-that-machine-makes-when-struggling.md | 49 +-- ...ing-to-build-a-new-kind-of-terminal-emulator.md | 184 ++++++------ ...5-10-push-to-multiple-origins-at-once-in-git.md | 17 +- ...023-05-16-rekindling-my-love-for-programming.md | 109 ++++--- .../2023-05-22-crafting-stories-in-zed-editor.md | 81 +++-- .../2023-05-23-i-was-wrong-about-git-workflows.md | 95 +++--- ...nting-task-runner-that-i-actually-used-daily.md | 158 +++++----- 39 files changed, 1942 insertions(+), 1925 deletions(-) (limited to 'content/posts') diff --git a/content/posts/2011-01-13-most-likely-to-succeed-in-year-of-2011.md b/content/posts/2011-01-13-most-likely-to-succeed-in-year-of-2011.md index bdf965a..9fc484a 100644 --- a/content/posts/2011-01-13-most-likely-to-succeed-in-year-of-2011.md +++ b/content/posts/2011-01-13-most-likely-to-succeed-in-year-of-2011.md @@ -5,31 +5,31 @@ date: 2011-01-13T12:00:00+02:00 draft: false --- -The year of 2010 was definitely the year of Geo-location. The market responded -beautifully and lots of very cool services were launched. We all have to thank -the mobile market for such extensive adoption. With new generations of mobile -phones that are not only buffed with high-tech hardware but are also affordable. -We can now manage tasks that were not so long time ago, almost Star Trek’ish. -And all this had and has great influence on the destination to which we are +The year of 2010 was definitely the year of Geo-location. The market responded +beautifully and lots of very cool services were launched. We all have to thank +the mobile market for such extensive adoption. With new generations of mobile +phones that are not only buffed with high-tech hardware but are also affordable. +We can now manage tasks that were not so long time ago, almost Star Trek’ish. +And all this had and has great influence on the destination to which we are going now. -Reading all this articles about new innovation about new thriving technologies -makes me wonder what’s the next step. The future is the mesh, like Lisa Gansky +Reading all this articles about new innovation about new thriving technologies +makes me wonder what’s the next step. The future is the mesh, like Lisa Gansky said in her book The Mesh. -Many still have conservative views on distributed systems. The problems with -security of information. Fear of not controlling every aspect of information -flow. I am very opened to distributed systems and heterogeneous applications, +Many still have conservative views on distributed systems. The problems with +security of information. Fear of not controlling every aspect of information +flow. I am very opened to distributed systems and heterogeneous applications, and I think this is the correct and best way to proceed. -This year will definitely be about communication platforms. Mobile to mobile. -Machine to mobile and vice versa. All the tech is available and ready to put -into action. Wireless is today’s new mantra. And the concept of semantic web -is now ready for industry. +This year will definitely be about communication platforms. Mobile to mobile. +Machine to mobile and vice versa. All the tech is available and ready to put +into action. Wireless is today’s new mantra. And the concept of semantic web is +now ready for industry. -Applications and developers now can gain access to new layers of systems and -can prepare and build solutions to meet the high quality needs of market. The -speed is everything now. +Applications and developers now can gain access to new layers of systems and can +prepare and build solutions to meet the high quality needs of market. The speed +is everything now. My vote goes to “Machine to Machine” and “Embedded Systems”! diff --git a/content/posts/2012-03-09-led-technology-not-so-eco.md b/content/posts/2012-03-09-led-technology-not-so-eco.md index 6e5aab9..a683aec 100644 --- a/content/posts/2012-03-09-led-technology-not-so-eco.md +++ b/content/posts/2012-03-09-led-technology-not-so-eco.md @@ -5,25 +5,25 @@ date: 2012-03-09T12:00:00+02:00 draft: false --- -There is a lot of talk about LED technology. It is beginning to infiltrate -industry at a fast rate, and it’s a challenge for designers and also engineers. -I wondered when a weakness will be revealed. Then I stomped on an article -talking about harm in using LED technology. It looks like this magical +There is a lot of talk about LED technology. It is beginning to infiltrate +industry at a fast rate, and it’s a challenge for designers and also engineers. +I wondered when a weakness will be revealed. Then I stomped on an article +talking about harm in using LED technology. It looks like this magical technology is not so magical and eco-friendly. -A new study from the University of California indicates that LED lights -contain toxic metals, and should be produced, used and disposed of carefully. -Besides the lead and nickel, the bulbs and their associated parts were also -found to contain arsenic, copper, and other metals that have been linked to -different cancers, neurological damage, kidney disease, hypertension, skin -rashes and other illnesses in humans, and to ecological damage in waterways. +A new study from the University of California indicates that LED lights contain +toxic metals, and should be produced, used and disposed of carefully. Besides +the lead and nickel, the bulbs and their associated parts were also found to +contain arsenic, copper, and other metals that have been linked to different +cancers, neurological damage, kidney disease, hypertension, skin rashes and +other illnesses in humans, and to ecological damage in waterways. -Since then, I haven’t yet found any regulation for disposal of LED lights or -any other regulation or standard. This might be a problem in the future. And -it is a massive drawback. This might have quite an impact on consumer market. +Since then, I haven’t yet found any regulation for disposal of LED lights or any +other regulation or standard. This might be a problem in the future. And it is a +massive drawback. This might have quite an impact on consumer market. -Nevertheless, there is a potential, and I am sure the market will adapt. I -also hope I will be reading documents regarding solution for this concern soon. +Nevertheless, there is a potential, and I am sure the market will adapt. I also +hope I will be reading documents regarding solution for this concern soon. **Additional resources:** diff --git a/content/posts/2013-10-24-wireless-sensor-networks.md b/content/posts/2013-10-24-wireless-sensor-networks.md index dabdebc..fc5d372 100644 --- a/content/posts/2013-10-24-wireless-sensor-networks.md +++ b/content/posts/2013-10-24-wireless-sensor-networks.md @@ -5,47 +5,45 @@ date: 2013-10-24T12:00:00+02:00 draft: false --- -Zigbee networks have this wonderful capability to self-heal, which means they -can reorder connections between them if one of them is inoperable. This works -our of the box when you deploy them. But you have to have in mind that -achieving this is not as easy as you would think. None of it is plug&play. -So to make your life a bit easier, here are some pointers which, I hope, -will help you. +Zigbee networks have this wonderful capability to self-heal, which means they +can reorder connections between them if one of them is inoperable. This works +our of the box when you deploy them. But you have to have in mind that achieving +this is not as easy as you would think. None of it is plug&play. So to make +your life a bit easier, here are some pointers which, I hope, will help you. -- Be careful when you are ordering your equipment abroad. There are many rules - and regulations you need to comply before you get your Xbee radios. What they - do is they wait until you prove that you won’t use the technology for some - kind of evil take over control of the world project :). For this, they have +- Be careful when you are ordering your equipment abroad. There are many rules + and regulations you need to comply before you get your Xbee radios. What they + do is they wait until you prove that you won’t use the technology for some + kind of evil take over control of the world project :). For this, they have EAR (Export Administration Regulations) which basically means “This product may require a license to export from the United States.”. -- I don’t know if this applies for every country, but when we purchased our - Xbee radios from Mouser, this was mandatory! What we needed to do was to - print out a form and write information about our company and send them a - copy via email. With this document, we proved that we are a legitimate - company. -- When you complete your purchase and send all the documentation, you are not - clear yet. Then customs will take it from there :). There will be some - additional costs. Before purchasing, make sure you have as much information +- I don’t know if this applies for every country, but when we purchased our Xbee + radios from Mouser, this was mandatory! What we needed to do was to print out + a form and write information about our company and send them a copy via + email. With this document, we proved that we are a legitimate company. +- When you complete your purchase and send all the documentation, you are not + clear yet. Then customs will take it from there :). There will be some + additional costs. Before purchasing, make sure you have as much information about costs as possible. Because it can get costly in the end. -- I suggest you use companies from your country. You can seriously cut your - costs. Here in Slovenia, the best option so far as I know is Farnell. And +- I suggest you use companies from your country. You can seriously cut your + costs. Here in Slovenia, the best option so far as I know is Farnell. And based on my personal experience, they rock! All I need to say! -- Make plans when ordering larger quantities. Do not, I say, do not make your - orders in December! :) Believe me! You will have problems with stock they - can provide for you. So, we were forced to buy some things from Mouser, - which was extremely painful because of all the regulations you need to obey - when importing goods from the USA. -- Make sure that firmware version on your Xbee radios is exactly the same! Do - not get creative!!! I propose using templates. You can get template by - exporting settings/profile in X-CTU application. Make sure you have enabled +- Make plans when ordering larger quantities. Do not, I say, do not make your + orders in December! :) Believe me! You will have problems with stock they can + provide for you. So, we were forced to buy some things from Mouser, which was + extremely painful because of all the regulations you need to obey when + importing goods from the USA. +- Make sure that firmware version on your Xbee radios is exactly the same! Do + not get creative!!! I propose using templates. You can get template by + exporting settings/profile in X-CTU application. Make sure you have enabled “Upgrade firmware” so you can be sure each radio has the same firmware. -- And again: make plans! Plan everything! In months advanced! You will thank - me later :) +- And again: make plans! Plan everything! In months advanced! You will thank me + later :) - Test, test, test. Wireless networks can be tricky. -If you are serious, I suggest you buy this book, Building Wireless Sensor -Networks. You will get a glimpse of how networks work in lumens terms. It is -a good starting point for everybody who wants to build wireless networks. +If you are serious, I suggest you buy this book, Building Wireless Sensor +Networks. You will get a glimpse of how networks work in lumens terms. It is a +good starting point for everybody who wants to build wireless networks. **Additional resources:** diff --git a/content/posts/2015-11-10-software-development-pitfalls.md b/content/posts/2015-11-10-software-development-pitfalls.md index 57e9736..b9edd19 100644 --- a/content/posts/2015-11-10-software-development-pitfalls.md +++ b/content/posts/2015-11-10-software-development-pitfalls.md @@ -5,178 +5,176 @@ date: 2015-11-10T12:00:00+02:00 draft: false --- -Over the years I had the privilege to work on some very excited projects both -in software development field and also in electronics field and every experience -taught me some invaluable lessons about how NOT TO approach development. And -through this post I will try to point out some absurd, outdated techniques I -find the most annoying and damaging during a development cycle. There will be -swearing because this topic really gets on my nerves and I never coherently +Over the years I had the privilege to work on some very excited projects both in +software development field and also in electronics field and every experience +taught me some invaluable lessons about how NOT TO approach development. And +through this post I will try to point out some absurd, outdated techniques I +find the most annoying and damaging during a development cycle. There will be +swearing because this topic really gets on my nerves and I never coherently tried to explain them in writing. So if I get heated up, please bear with me. -As new methods of project management are emerging, underlying processes still -stay old and outdated. This is mainly because we as people are unable to +As new methods of project management are emerging, underlying processes still +stay old and outdated. This is mainly because we as people are unable to completely shift away from these approaches. -I was always struggling with communication, and many times that cost me a -relationship or two because I was not on the ball all the time. Through every -experience, I became more convinced that I am the problem and never ever -doubted that the problem may be that communication never evolved a single step -from emails. And if you think for a second, not many things have changed around -this topic. We just have different representations of email (message boards, -chats, project management tools). And I believe this is the real issue we are -facing now. - -There are many articles written about hyper connectivity and the effects that -are a direct result of it. But mainstream does nothing towards it. We are just -putting out fires, and we do nothing to prevent it. I am certain this will be -a major source of grief in coming years. And what we all can do to avoid this -is to change our mindset and experiment on our communication skills, -development approaches. We need to maximize possible output that a person can -give. And to achieve this we need to listen to them, encourage them. I know -that not everybody is a naturally born leader, but with enough practice and -encouragement they also can become active participants in leadership. - -There are many talks now about methodologies such as Scrum, Kanban, Cleanroom -and they all fucking piss me of :). These are all boxes that imprison people -and take away their freedom of thought. This is a straightforward -mindfuck / amputation of creativity. - -Let me list a couple of things that I find really destructive and bad for a +I was always struggling with communication, and many times that cost me a +relationship or two because I was not on the ball all the time. Through every +experience, I became more convinced that I am the problem and never ever doubted +that the problem may be that communication never evolved a single step from +emails. And if you think for a second, not many things have changed around this +topic. We just have different representations of email (message boards, chats, +project management tools). And I believe this is the real issue we are facing +now. + +There are many articles written about hyper connectivity and the effects that +are a direct result of it. But mainstream does nothing towards it. We are just +putting out fires, and we do nothing to prevent it. I am certain this will be a +major source of grief in coming years. And what we all can do to avoid this is +to change our mindset and experiment on our communication skills, development +approaches. We need to maximize possible output that a person can give. And to +achieve this we need to listen to them, encourage them. I know that not +everybody is a naturally born leader, but with enough practice and encouragement +they also can become active participants in leadership. + +There are many talks now about methodologies such as Scrum, Kanban, Cleanroom +and they all fucking piss me of :). These are all boxes that imprison people and +take away their freedom of thought. This is a straightforward mindfuck / +amputation of creativity. + +Let me list a couple of things that I find really destructive and bad for a project and in a long run company. ## Ping emails -Ping emails are emails you have to write as soon as you receive an email. Its -sole purpose is to inform the sender that you received their email, and you -are working on it. Its result is only to calm down the sender that their task -is being dealt with. It’s intent basically is, I did my job by sending you -this email, so I am on clear grounds. I categorize this email as fuck you email. -This is one of the most irritating types of emails I need to write. This is -the ultimate control freak show you can experience, and it gives the sender a -false feeling of control. Newsflash: We do not live in 1982 where there was a -possibility that email never reached the destination. I really hate this from +Ping emails are emails you have to write as soon as you receive an email. Its +sole purpose is to inform the sender that you received their email, and you are +working on it. Its result is only to calm down the sender that their task is +being dealt with. It’s intent basically is, I did my job by sending you this +email, so I am on clear grounds. I categorize this email as fuck you email. +This is one of the most irritating types of emails I need to write. This is the +ultimate control freak show you can experience, and it gives the sender a false +feeling of control. Newsflash: We do not live in 1982 where there was a +possibility that email never reached the destination. I really hate this from the bottom of my heart. -They should be like: “Yes, I am fucking alive, and I am at your service my -leash!”. I guess if I would reply like this, I wouldn’t have to write any -more of this kind of messages. +They should be like: “Yes, I am fucking alive, and I am at your service my +leash!”. I guess if I would reply like this, I wouldn’t have to write any more +of this kind of messages. ## Everybody is a project manager -Well, this is a tough one. I noticed that as soon as you let people to give -their suggestions, you are basically screwed. There is a truth in the saying: +Well, this is a tough one. I noticed that as soon as you let people to give +their suggestions, you are basically screwed. There is a truth in the saying: “Give low expectations and deliver little more than you promised.”. -People tend to take a role of a manager as soon as they are presented with an -opportunity. And by getting angry at them, you only provoke yourself. They are -not at fault. You just need to tell them they are only giving suggestions and -not tasks at the beginning and everything will be alright. But if you give -them a feeling that they are in control, you will have immense problems -explaining why their features are not in current release. +People tend to take a role of a manager as soon as they are presented with an +opportunity. And by getting angry at them, you only provoke yourself. They are +not at fault. You just need to tell them they are only giving suggestions and +not tasks at the beginning and everything will be alright. But if you give them +a feeling that they are in control, you will have immense problems explaining +why their features are not in current release. -Project mission must be always leading project requirements and any deviation -from it will result in major project butchering. And by this, I mean that the -project will get its own path, and you will be left with half done software -that helps nobody. Clear mission goals and clean execution will allow you to -develop software will clear intent. +Project mission must be always leading project requirements and any deviation +from it will result in major project butchering. And by this, I mean that the +project will get its own path, and you will be left with half done software that +helps nobody. Clear mission goals and clean execution will allow you to develop +software will clear intent. ## We are never wrong I find this type of arrogance the worst. We must always conduct ourselves that -we are infallible and cannot make mistakes. As soon as a procedure or process -is established, there is no room for changes or improvements. This is the most +we are infallible and cannot make mistakes. As soon as a procedure or process is +established, there is no room for changes or improvements. This is the most idiotic thing someone can say of think. I think that processes need to involve -and change over time. This is imperative and need to have in your organization -if you want to improve and develop company. We all need to grow balls and change -everything in order to adapt to current situations. Being a prisoner of +and change over time. This is imperative and need to have in your organization +if you want to improve and develop company. We all need to grow balls and change +everything in order to adapt to current situations. Being a prisoner of predefined processes kills creativity. -I am constantly trying new software for project managing and communication. -I believe every team has its own dynamic, and it needs to be discovered -organically and naturally through many experiments. By putting the team in a -box, you are amputating their creativity and therefore minimizing their -potential. But if you talk to an executive, you will mainly find archetypical -thinking and a strong need to compartmentalize everything from business -processes to resource management. And this type of management that often -displays micromanagement techniques only works for short periods (couple of -years) and then employees either leave the company or become basically retarded +I am constantly trying new software for project managing and communication. I +believe every team has its own dynamic, and it needs to be discovered +organically and naturally through many experiments. By putting the team in a +box, you are amputating their creativity and therefore minimizing their +potential. But if you talk to an executive, you will mainly find archetypical +thinking and a strong need to compartmentalize everything from business +processes to resource management. And this type of management that often +displays micromanagement techniques only works for short periods (couple of +years) and then employees either leave the company or become basically retarded drones on autopilot. ## Micromanaging -This basically implies that everybody on the team is an idiot who needs to -have a to-do list that they cannot write themselves. How about spoon-feeding -the team at launch because besides the team leader, everybody must be a -retarded idiot at best? +This basically implies that everybody on the team is an idiot who needs to have +a to-do list that they cannot write themselves. How about spoon-feeding the team +at launch because besides the team leader, everybody must be a retarded idiot at +best? -I prefer milestones as they give developers much more freedom and creativity -in developing and not waste their time checking some bizarre to-do list that -was not even thought through. Projects constantly change throughout the -development cycle, and all you are left at the end is a list of unchecked tasks -and the wrath of management why they are not completed. Best WTF moment! +I prefer milestones as they give developers much more freedom and creativity in +developing and not waste their time checking some bizarre to-do list that was +not even thought through. Projects constantly change throughout the development +cycle, and all you are left at the end is a list of unchecked tasks and the +wrath of management why they are not completed. Best WTF moment! ## Human contact — no need for it! -We are vigorously trying to eliminate physical contact by replacing short -meetings with software, with no regards that we are not machines. Many times -a simple 5-min meeting at morning can solve most of the problems. In rapid -development, short bursts of man to man communication is possibly the best -way to go. +We are vigorously trying to eliminate physical contact by replacing short +meetings with software, with no regards that we are not machines. Many times a +simple 5-min meeting at morning can solve most of the problems. In rapid +development, short bursts of man to man communication is possibly the best way +to go. -We now have all this software available, and all what we get out of it is a +We now have all this software available, and all what we get out of it is a giant clusterfuck. An obstacle and not a solution. So, why we still use them? ## MVP is killing innovation -Many will disagree with me on this one, but I stand strong by this statement. -What I noticed in my experience that all this buzz words around us only -mislead and capture us in a circle of solving issues that already have a -solution, but we are unable to see it without using some fancy word for it. - -The toughest thing to do for a developer is to minimize requirements. Well, -this is though only for bad developers. Yes, I said it. There are many types -of developers out there. And those unable to minimize feature scope are the -ones you don’t need on your team. Their only goal is to solve problems that -exist only in their heads. And then you have to argue with them, and waste -energy on them, instead of developing your awesome product. They are a cancer -and I suggest you cut them off. - -MVP as an idea is great, but sadly people don’t understand underlying -philosophy, and they spent too much time focusing and fixating on something -that every sane person with normal IQ will understand without some made up +Many will disagree with me on this one, but I stand strong by this statement. +What I noticed in my experience that all this buzz words around us only mislead +and capture us in a circle of solving issues that already have a solution, but +we are unable to see it without using some fancy word for it. + +The toughest thing to do for a developer is to minimize requirements. Well, this +is though only for bad developers. Yes, I said it. There are many types of +developers out there. And those unable to minimize feature scope are the ones +you don’t need on your team. Their only goal is to solve problems that exist +only in their heads. And then you have to argue with them, and waste energy on +them, instead of developing your awesome product. They are a cancer and I +suggest you cut them off. + +MVP as an idea is great, but sadly people don’t understand underlying +philosophy, and they spent too much time focusing and fixating on something that +every sane person with normal IQ will understand without some made up acronym. And the result is a lot of talking and barely no execution. -Well, MVP is not directly killing innovation, but stupid people do when they -try to understand it. +Well, MVP is not directly killing innovation, but stupid people do when they try +to understand it. ## Pressure wasteland -You must never allow to be pressured into confirming a deadline if you are not -confident. We often feel a need that we are in service of others, which is -true to some extent. But it is also true that others are in service to us to -some extent. And we forget this all the time. We are all pressured all the -time to make decisions just to calm other people down. And when they leave -your office you experience WTF moment :) How the hell did they manage to -fuck me up again? - -People need to realize that the more pressure you put on somebody, the less -they will be able to do. So 5-min update email requests will only resolve in -mental breakdown and inability to work that day. Constant poking is probably -the only thing I lose my mind instantly. For all you that are doing this: -“Stop bothering us with your insecurities and let us do our job. We will do -it quicker and better without you breathing down our necks.” +You must never allow to be pressured into confirming a deadline if you are not +confident. We often feel a need that we are in service of others, which is true +to some extent. But it is also true that others are in service to us to some +extent. And we forget this all the time. We are all pressured all the time to +make decisions just to calm other people down. And when they leave your office +you experience WTF moment :) How the hell did they manage to fuck me up again? + +People need to realize that the more pressure you put on somebody, the less they +will be able to do. So 5-min update email requests will only resolve in mental +breakdown and inability to work that day. Constant poking is probably the only +thing I lose my mind instantly. For all you that are doing this: “Stop bothering +us with your insecurities and let us do our job. We will do it quicker and +better without you breathing down our necks.” If this happens to me, I end up with no energy at the end. Don’t you get it? -You will get much more from and out of me if you ask me like a human person -and not your personal butler. On a long run, you are destroying your -relationships and nobody would want to work with you. Your schizophrenic -approach will damage only you in a long run. Nobody is anybody’s property. +You will get much more from and out of me if you ask me like a human person and +not your personal butler. On a long run, you are destroying your relationships +and nobody would want to work with you. Your schizophrenic approach will damage +only you in a long run. Nobody is anybody’s property. ## Conclusion -I am guilty of many things described in this post. And I find it hard sometimes -to acknowledge this. And I lie to myself and try vigorously to find some -explanation why I do these things. There is always space for growth. And -maybe you will also find some of yourself in this post and realize what needs -to change for you to evolve. - +I am guilty of many things described in this post. And I find it hard sometimes +to acknowledge this. And I lie to myself and try vigorously to find some +explanation why I do these things. There is always space for growth. And maybe +you will also find some of yourself in this post and realize what needs to +change for you to evolve. diff --git a/content/posts/2017-03-07-golang-profiling-simplified.md b/content/posts/2017-03-07-golang-profiling-simplified.md index 7eee2dd..4bd18b2 100644 --- a/content/posts/2017-03-07-golang-profiling-simplified.md +++ b/content/posts/2017-03-07-golang-profiling-simplified.md @@ -6,34 +6,34 @@ draft: false --- Many posts have been written regarding profiling in Golang and I haven’t found -proper tutorial regarding this. Almost all of them are missing some part of -important information and it gets pretty frustrating when you have a deadline +proper tutorial regarding this. Almost all of them are missing some part of +important information and it gets pretty frustrating when you have a deadline and are not finding simple distilled solution. -Nevertheless, after searching and experimenting I have found a solution that +Nevertheless, after searching and experimenting I have found a solution that works for me and probably should also for you. ## Where are my pprof files? -By default pprof files are generated in /tmp/ folder. You can override folder -where this files are generated programmatically in your golang code as we will +By default pprof files are generated in /tmp/ folder. You can override folder +where this files are generated programmatically in your golang code as we will see below in example. ## Why is my CPU profile empty? -I have found out that sometimes CPU profile is empty because program was not -executing long enough. Programs, that execute too quickly don’t produce pprof +I have found out that sometimes CPU profile is empty because program was not +executing long enough. Programs, that execute too quickly don’t produce pprof file in my cases. Well, file is generated but only contains 4KB of information. ## Profiling -As you can see from examples we are executing dummy_benchmark functions to -ensure some sort of execution. Memory profiling can be done without such a +As you can see from examples we are executing dummy_benchmark functions to +ensure some sort of execution. Memory profiling can be done without such a “complex” function. But CPU profiling needs it. -Both memory and CPU profiling examples are almost the same. Only parameters -in main function when calling profile.Start are different. When we set -profile.ProfilePath(“.”) we tell profiler to store pprof files in the same +Both memory and CPU profiling examples are almost the same. Only parameters in +main function when calling profile.Start are different. When we set +profile.ProfilePath(“.”) we tell profiler to store pprof files in the same folder as our program. ### Memory profiling diff --git a/content/posts/2017-04-17-what-i-ve-learned-developing-ad-server.md b/content/posts/2017-04-17-what-i-ve-learned-developing-ad-server.md index 1b9be06..bb98efd 100644 --- a/content/posts/2017-04-17-what-i-ve-learned-developing-ad-server.md +++ b/content/posts/2017-04-17-what-i-ve-learned-developing-ad-server.md @@ -5,10 +5,10 @@ date: 2017-04-17T12:00:00+02:00 draft: false --- -For the past year and half I have been developing native advertising server -that contextually matches ads and displays them in different template forms -on variety of websites. This project grew from serving thousands of ads per -day to millions. +For the past year and half I have been developing native advertising server that +contextually matches ads and displays them in different template forms on +variety of websites. This project grew from serving thousands of ads per day to +millions. The system is made from couple of core components: @@ -16,56 +16,56 @@ The system is made from couple of core components: - Utils - cronjobs and queue management tools, - Dashboard UI. -Initial release was using [MongoDB](https://www.mongodb.com/) for full-text -search but was later replaced by [Elasticsearch](https://www.elastic.co/) -for better CPU utilization and better search performance. This provided us -with many amazing functionalities of [Elasticsearch](https://www.elastic.co/). -You should check it out if you do any search related operations. +Initial release was using [MongoDB](https://www.mongodb.com/) for full-text +search but was later replaced by [Elasticsearch](https://www.elastic.co/) for +better CPU utilization and better search performance. This provided us with many +amazing functionalities of [Elasticsearch](https://www.elastic.co/). You should +check it out if you do any search related operations. -Because the premise of the server is to provide native ad experience, they -are rendered on the client side via simple templating engine. This ensures -that ads can be displayed number of different ways based on the visual style -of the page. And this makes JavaScript client library quite complex. +Because the premise of the server is to provide native ad experience, they are +rendered on the client side via simple templating engine. This ensures that ads +can be displayed number of different ways based on the visual style of the +page. And this makes JavaScript client library quite complex. -So now that you know basic information about the product lets get into the +So now that you know basic information about the product lets get into the lessons we learned. ## Aggregate everything -After beta version was released everything (impressions, clicks, etc) was -written in nanosecond resolution in the database. At that time we were using -[PostgreSQL](https://www.postgresql.org/) and database quickly grew way above -200GB in disk space. And that was problematic. Statistics took disturbingly -long time to aggregate. Also using indexes on stats table in database was no -help after we reached 500 million datapoints. +After beta version was released everything (impressions, clicks, etc) was +written in nanosecond resolution in the database. At that time we were using +[PostgreSQL](https://www.postgresql.org/) and database quickly grew way above +200GB in disk space. And that was problematic. Statistics took disturbingly long +time to aggregate. Also using indexes on stats table in database was no help +after we reached 500 million datapoints. -> There is a marketing product information and there is real life experience. +> There is a marketing product information and there is real life experience. And the tend to be quite the opposite. -This was the reason that now everything is aggregated on daily basis and this -data is then fed to Elastic in form of daily summary. With this we achieved we -can now track many more dimensions such as zone, channel and platform information. -And with this information we can now adapt occurrences of ads on specific -places more precisely. +This was the reason that now everything is aggregated on daily basis and this +data is then fed to Elastic in form of daily summary. With this we achieved we +can now track many more dimensions such as zone, channel and platform +information. And with this information we can now adapt occurrences of ads on +specific places more precisely. -We have also adapted [Redis](https://redis.io/) as a full-time citizen in our -stack. Because Redis also stores information on a local disk we have some sort +We have also adapted [Redis](https://redis.io/) as a full-time citizen in our +stack. Because Redis also stores information on a local disk we have some sort of backup if server would accidentally suffer some failure. -All the real-time statistics for ad serving and redirecting is presented as +All the real-time statistics for ad serving and redirecting is presented as counters in Redis instance and daily extracted and pushed to Elastic. ## Measure everything -The thing about software is that we really don't know how well it is performing -under load until such load is presented. When testing locally everything is -fine but when on production things tend to fall apart. +The thing about software is that we really don't know how well it is performing +under load until such load is presented. When testing locally everything is fine +but when on production things tend to fall apart. -As a solution for this we are measuring everything we can. Function execution -time (by encapsulating functions with timers), server performance (cpu, memory, -disk, etc), Nginx and [uWSGI](https://uwsgi-docs.readthedocs.io/) performance. -We sacrifice a bit of performance for the sake of this information. And we -store all this information for later analysis. +As a solution for this we are measuring everything we can. Function execution +time (by encapsulating functions with timers), server performance (cpu, memory, +disk, etc), Nginx and [uWSGI](https://uwsgi-docs.readthedocs.io/) performance. +We sacrifice a bit of performance for the sake of this information. And we store +all this information for later analysis. **Example of function execution time** @@ -99,27 +99,28 @@ store all this information for later analysis. } ``` -We have also started profiling with [cProfile](https://pymotw.com/2/profile/) -and then visualizing with [KCachegrind](http://kcachegrind.sourceforge.net/). +We have also started profiling with [cProfile](https://pymotw.com/2/profile/) +and then visualizing with [KCachegrind](http://kcachegrind.sourceforge.net/). This provides much more detailed look into code execution. ## Cache control is your friend -Because we use Javascript library for rendering ads we rely on this script -extensively and when in need we need to be able to change behavior of the -script quickly. +Because we use Javascript library for rendering ads we rely on this script +extensively and when in need we need to be able to change behavior of the script +quickly. -In our case we can not simply replace javascript url in html code. It usually -takes a day or two for the guys who maintain sites to change code or add -?ver=xxx attribute. And this makes rapid deployment and testing very difficult +In our case we can not simply replace javascript url in html code. It usually +takes a day or two for the guys who maintain sites to change code or add +?ver=xxx attribute. And this makes rapid deployment and testing very difficult and time consuming. There is a limitation of how much you can test locally. -We are now in the process of integrating [Google Tag Manager](https://www.google.com/analytics/tag-manager/) -but couple of websites are developed on ASP.net platform that have some -problems with tag manager. With a solution below we are certain that we are -serving latest version of the script. +We are now in the process of integrating [Google Tag +Manager](https://www.google.com/analytics/tag-manager/) but couple of websites +are developed on ASP.net platform that have some problems with tag manager. With +a solution below we are certain that we are serving latest version of the +script. -And it only takes one mistake and users have the script cached and in case of +And it only takes one mistake and users have the script cached and in case of caching it for 1 year you probably know where the problem is. ```nginx @@ -143,10 +144,10 @@ location /static/ { } ``` -Also be careful when redirecting to url in your python code. We noticed that -if we didn't precisely setup cache control and expire headers in response we -didn't get the request on the server and therefore couldn't measure clicks. -So when redirecting do as follows and there will be no problems. +Also be careful when redirecting to url in your python code. We noticed that if +we didn't precisely setup cache control and expire headers in response we didn't +get the request on the server and therefore couldn't measure clicks. So when +redirecting do as follows and there will be no problems. ```python # python ➜ bottlepy web micro-framework @@ -157,42 +158,41 @@ response.set_header("Location", url) return response ``` -> Cache control in browsers is quite aggressive and you need to be precise -to avoid future problems. We learned that lesson the hard way. +> Cache control in browsers is quite aggressive and you need to be precise to +avoid future problems. We learned that lesson the hard way. ## Learn NGINX -When deciding on a web server we went with Nginx as a reverse proxy for our -applications. We adapted micro-service oriented architecture early in the -project to ensure when we scale we can easily add additional servers to our -cluster. And Nginx was crucial to perform load balancing and static content +When deciding on a web server we went with Nginx as a reverse proxy for our +applications. We adapted micro-service oriented architecture early in the +project to ensure when we scale we can easily add additional servers to our +cluster. And Nginx was crucial to perform load balancing and static content delivery. -At first our config file was quite simple and later grew larger. After patching -and adding new settings I sat down and learned more about the guts of Nginx. -This proved to be very useful and we were able to squeeze much more out of our -setup. So I advise you to take your time and read through the -[documentation](https://nginx.org/en/docs/). This saved us a lot of headache. +At first our config file was quite simple and later grew larger. After patching +and adding new settings I sat down and learned more about the guts of Nginx. +This proved to be very useful and we were able to squeeze much more out of our +setup. So I advise you to take your time and read through the +[documentation](https://nginx.org/en/docs/). This saved us a lot of headache. Googling for solutions only goes so far. ## Use Redis/Memcached -As explained above we are using caching basically for everything. It is the -corner stone of our services. At first we were very careful about the quantity -of things we stored in [Redis](https://redis.io/). But we later found out that +As explained above we are using caching basically for everything. It is the +corner stone of our services. At first we were very careful about the quantity +of things we stored in [Redis](https://redis.io/). But we later found out that the memory footprint is very low even when storing large amount of data in it. -So we gradually increased our usage to caching whole HTML outputs of dashboard. -This improved our performance in order of magnitude. And by using native TTL +So we gradually increased our usage to caching whole HTML outputs of dashboard. +This improved our performance in order of magnitude. And by using native TTL support this goes hand in hand with our needs. -The reason why we choose [Redis](https://redis.io/) over [Memcached](https://memcached.org/) -was the nature of scalability of Redis out of the box. But all this can be -achieved with Memcached. +The reason why we choose [Redis](https://redis.io/) over +[Memcached](https://memcached.org/) was the nature of scalability of Redis out +of the box. But all this can be achieved with Memcached. ## Conclusion -There are a lot more details that could have been written and every single -topic in here deserves it's own post but you probably got the idea about -the problems we faced. - +There are a lot more details that could have been written and every single topic +in here deserves it's own post but you probably got the idea about the problems +we faced. diff --git a/content/posts/2017-04-21-profiling-python-web-applications-with-visual-tools.md b/content/posts/2017-04-21-profiling-python-web-applications-with-visual-tools.md index 911e6e0..2e36eaf 100644 --- a/content/posts/2017-04-21-profiling-python-web-applications-with-visual-tools.md +++ b/content/posts/2017-04-21-profiling-python-web-applications-with-visual-tools.md @@ -5,10 +5,9 @@ date: 2017-04-21T12:00:00+02:00 draft: false --- -I have been profiling my software with KCachegrind for a long time now and I -was missing this option when I am developing API's or other web services. I -always knew that this is possible but never really took the time and dive -into it. +I have been profiling my software with KCachegrind for a long time now and I was +missing this option when I am developing API's or other web services. I always +knew that this is possible but never really took the time and dive into it. Before we begin there are some requirements. We will need to: @@ -17,7 +16,9 @@ Before we begin there are some requirements. We will need to: - visualize data with [KCachegrind](http://kcachegrind.sourceforge.net/html/Home.html) or [Profiling Viewer](http://www.profilingviewer.com/). -If you are using MacOS you should check out [Profiling Viewer](http://www.profilingviewer.com/) or [MacCallGrind](http://www.maccallgrind.com/). +If you are using MacOS you should check out [Profiling +Viewer](http://www.profilingviewer.com/) or +[MacCallGrind](http://www.maccallgrind.com/). ![KCachegrind](/assets/python-profiling/kcachegrind.png) @@ -28,7 +29,7 @@ We will be dividing this post into two main categories: ## Simple web-service -Let's use virtualenv so we won't pollute our base system. If you don't have +Let's use virtualenv so we won't pollute our base system. If you don't have virtualenv installed on your system you can install it with pip command. ```bash @@ -73,8 +74,8 @@ $ pip install bottle $ deactivate ``` -We are now ready to write simple web service. Let's create file app.py and -paste code bellow in this newly created file. +We are now ready to write simple web service. Let's create file app.py and paste +code bellow in this newly created file. ```python # -*- coding: utf-8 -*- @@ -126,8 +127,8 @@ if __name__ == '__main__': # open browser 'http://0.0.0.0:4000' ``` -When browser hits awesome\_random\_number() function profile is created in -prof/ subfolder. +When browser hits awesome\_random\_number() function profile is created in prof/ +subfolder. ## Visualize profile @@ -139,26 +140,27 @@ $ pyprof2calltree -i awesome_random_number.prof # this creates 'awesome_random_number.prof.log' file in the same folder ``` -This file can be opened with visualizing tools listed above. In this case we -will be using Profilling Viewer under MacOS. You can open image in new tab. -As you can see from this example there is hierarchy of execution order of -your code. +This file can be opened with visualizing tools listed above. In this case we +will be using Profilling Viewer under MacOS. You can open image in new tab. As +you can see from this example there is hierarchy of execution order of your +code. ![Profilling Viewer](/assets/python-profiling/profiling-viewer.png) -> Make sure you convert output of the cProfile output every time you want to -refresh and take a look at your possible optimizations because cProfile -updates .prof file every time browser hits the function. +> Make sure you convert output of the cProfile output every time you want to +refresh and take a look at your possible optimizations because cProfile updates +.prof file every time browser hits the function. -This is just a simple example but when you are developing real-life applications -this can be very illuminating, especially to see which parts of your code are +This is just a simple example but when you are developing real-life applications +this can be very illuminating, especially to see which parts of your code are bottlenecks and need to be optimized. ## Update 2017-04-22 -Reddit user [mvt](https://www.reddit.com/user/mvt) also recommended this -awesome web based profile visualizer [SnakeViz](https://jiffyclub.github.io/snakeviz/) -that directly takes output from [cProfile](https://docs.python.org/2/library/profile.html#module-cProfile) +Reddit user [mvt](https://www.reddit.com/user/mvt) also recommended this awesome +web based profile visualizer [SnakeViz](https://jiffyclub.github.io/snakeviz/) +that directly takes output from +[cProfile](https://docs.python.org/2/library/profile.html#module-cProfile) module.
Comment from discussion Profiling Python web applications with visual tools.
@@ -201,4 +203,3 @@ $ pip install snakeviz --user Or as suggested by [mvt](https://www.reddit.com/user/mvt) you can use [pipsi](https://github.com/mitsuhiko/pipsi). - diff --git a/content/posts/2017-08-11-simple-iot-application.md b/content/posts/2017-08-11-simple-iot-application.md index a0ac4be..e7e086b 100644 --- a/content/posts/2017-08-11-simple-iot-application.md +++ b/content/posts/2017-08-11-simple-iot-application.md @@ -7,34 +7,35 @@ draft: false ## Initial thoughts -I have been developing these kind of application for the better part of my last -5 years and people keep asking me how to approach developing such application +I have been developing these kind of application for the better part of my last +5 years and people keep asking me how to approach developing such application and I will give a try explaining it here. -IOT applications are really no different than any other kind of applications. -We have data that needs to be collected and visualized in some form of tables -or charts. The main difference here is that most of the times these data is -collected by some kind of device foreign to developer that mainly operates in +IOT applications are really no different than any other kind of applications. +We have data that needs to be collected and visualized in some form of tables or +charts. The main difference here is that most of the times these data is +collected by some kind of device foreign to developer that mainly operates in web domain. But fear not, it's not that different than writing some JavaScript. -There are many devices able to transmit data via wireless or wired network by -default but for the sake of example we will be using commonly known Arduino -with wireless module already on the board → [Arduino MKR1000](https://store.arduino.cc/arduino-mkr1000). - -In order to make this little project as accessible to others as possible I will -try to make it as inexpensive as possible. And by this I mean that I will avoid -using hosted virtual servers and will be using my own laptop as a server. But -you must buy Arduino MKR1000 to follow steps below. But if you would want to -deploy this software I would suggest using -[DigitalOcean](https://www.digitalocean.com) → smallest VPS is only per month -making this one of the most affordable option out there. Please notice that -this software will not run on stock web hosting that only supports LAMP -(Linux, Apache, MySQL, and PHP). - -But before we begin please take notice that this is strictly experimental code -and not well optimized and there are much better ways in handling some aspects -of the application but that requires much deeper knowledge of technology that -is not needed for an example like this. +There are many devices able to transmit data via wireless or wired network by +default but for the sake of example we will be using commonly known Arduino with +wireless module already on the board → [Arduino +MKR1000](https://store.arduino.cc/arduino-mkr1000). + +In order to make this little project as accessible to others as possible I will +try to make it as inexpensive as possible. And by this I mean that I will avoid +using hosted virtual servers and will be using my own laptop as a server. But +you must buy Arduino MKR1000 to follow steps below. But if you would want to +deploy this software I would suggest using +[DigitalOcean](https://www.digitalocean.com) → smallest VPS is only per month +making this one of the most affordable option out there. Please notice that this +software will not run on stock web hosting that only supports LAMP (Linux, +Apache, MySQL, and PHP). + +But before we begin please take notice that this is strictly experimental code +and not well optimized and there are much better ways in handling some aspects +of the application but that requires much deeper knowledge of technology that is +not needed for an example like this. **Development steps** @@ -42,32 +43,34 @@ is not needed for an example like this. 2. Prototype C++ code that will read "sensor data" and transmit it to API. 3. Data visualization with charts → extends Python web application. -Step 1. and 3. will share the same web application. One route will be dedicated +Step 1. and 3. will share the same web application. One route will be dedicated to API and another to serving HTML with chart. -Schema below represents what we will try to achieve and how different parts +Schema below represents what we will try to achieve and how different parts correlates to each other. ![Overview](/assets/iot-application/simple-iot-application-overview.svg) ## Simple Python API -I have always been a fan of simplicity so we will be using [Bottle: Python Web Framework](https://bottlepy.org/docs/dev/). -It is a single file web framework that seriously simplifies working with routes, -templating and has built-in web server that satisfies our need in this case. +I have always been a fan of simplicity so we will be using [Bottle: Python Web +Framework](https://bottlepy.org/docs/dev/). It is a single file web framework +that seriously simplifies working with routes, templating and has built-in web +server that satisfies our need in this case. -First we need to install bottle package. This can be done by downloading -```bottle.py``` and placing it in the root of your application or by using -pip software ```pip install bottle --user```. +First we need to install bottle package. This can be done by downloading +```bottle.py``` and placing it in the root of your application or by using pip +software ```pip install bottle --user```. -If you are using Linux or MacOS then Python is already installed. If you will -try to test this on Windows please install [Python for Windows](https://www.python.org/downloads/windows/). -There may be some problems with path when you will try to launch -```python webapp.py``` so please take care of this before you continue. +If you are using Linux or MacOS then Python is already installed. If you will +try to test this on Windows please install [Python for +Windows](https://www.python.org/downloads/windows/). There may be some problems +with path when you will try to launch ```python webapp.py``` so please take care +of this before you continue. ### Basic web application -Most basic bottle application is quite simple. Paste code below in +Most basic bottle application is quite simple. Paste code below in ```webapp.py``` file and save. ```python @@ -96,59 +99,62 @@ if __name__ == "__main__": ) ``` -To run this simple application you should open command prompt or terminal on -your machine and go to the folder containing your file and type -```python webapp.py```. If everything goes ok then open your web browser and -point it to ```http://0.0.0.0:5000```. +To run this simple application you should open command prompt or terminal on +your machine and go to the folder containing your file and type ```python +webapp.py```. If everything goes ok then open your web browser and point it to +```http://0.0.0.0:5000```. -If you would like change the port of your application (like port 80) and not -use root to run your app this will present a problem. The TCP/IP port numbers -below 1024 are privileged ports → this is a security feature. So in order of -simplicity and security use a port number above 1024 like I have used port -5000. +If you would like change the port of your application (like port 80) and not use +root to run your app this will present a problem. The TCP/IP port numbers below +1024 are privileged ports → this is a security feature. So in order of +simplicity and security use a port number above 1024 like I have used port 5000. -If this fails at any time please fix it before you continue, because nothing +If this fails at any time please fix it before you continue, because nothing below will work otherwise. -We use 0.0.0.0 as default host so that this app is available over your local -network. If you find your local ip ```ifconfig``` and try accessing this site -with your phone (if on same network/router as your machine) this should work -as well (example of such ip ```http://192.168.1.15:5000```). This is a must -have because Arduino will be accessing this application to send it's data. +We use 0.0.0.0 as default host so that this app is available over your local +network. If you find your local ip ```ifconfig``` and try accessing this site +with your phone (if on same network/router as your machine) this should work as +well (example of such ip ```http://192.168.1.15:5000```). This is a must have +because Arduino will be accessing this application to send it's data. ### Web application security -There is a lot to be said about security and is a topic of many books. Of course -all this can not be written here but to just establish some basic -security → you should always use SSL with your application. Some fantastic free -certificates are available by [Let's Encrypt - Free SSL/TLS Certificates](https://letsencrypt.org). -With SSL certificate installed you should then make use of HTTP headers and -send your "API key" via a header. If your key is send via header then this -key is encrypted by SSL and send encrypted over the network. Never send your -api keys by GET parameter like ```http://example.com/?api_key=somekeyvalue```. -The problem that this kind of sending presents is that this key is visible in -logs and by network sniffers. - -There is a fantastic article describing some aspects about security: [11 Web Application Security Best Practices](https://www.keycdn.com/blog/web-application-security-best-practices/). Please check it out. +There is a lot to be said about security and is a topic of many books. Of course +all this can not be written here but to just establish some basic security → you +should always use SSL with your application. Some fantastic free certificates +are available by [Let's Encrypt - Free SSL/TLS +Certificates](https://letsencrypt.org). With SSL certificate installed you +should then make use of HTTP headers and send your "API key" via a header. If +your key is send via header then this key is encrypted by SSL and send encrypted +over the network. Never send your api keys by GET parameter like +```http://example.com/?api_key=somekeyvalue```. The problem that this kind of +sending presents is that this key is visible in logs and by network sniffers. + +There is a fantastic article describing some aspects about security: [11 Web +Application Security Best +Practices](https://www.keycdn.com/blog/web-application-security-best-practices/). Please +check it out. ### Simple API for writing data-points -We will now be using boilerplate code from example above and extend it to be -able to write data received by API to local storage. For example use I will -use SQLite3 because it plays well with Python and can store quite large amount -of data. I have been using it to collect gigabytes of data in a single database +We will now be using boilerplate code from example above and extend it to be +SQLite3 because it plays well with Python and can store quite large amount of +able to write data received by API to local storage. For example use I will use +data. I have been using it to collect gigabytes of data in a single database without any corruption or problems → your experience may vary. -To avoid learning SQLite I will be using [Dataset: databases for lazy people](https://dataset.readthedocs.io/en/latest/index.html). -This package abstracts SQL and simplifies writing and reading data from -database. You should install this package with pip software -```pip install dataset --user```. +To avoid learning SQLite I will be using [Dataset: databases for lazy +people](https://dataset.readthedocs.io/en/latest/index.html). This package +abstracts SQL and simplifies writing and reading data from database. You should +install this package with pip software ```pip install dataset --user```. -Because API will use POST method I will be testing if code works correctly by -using [Restlet Client for Google Chrome](https://chrome.google.com/webstore/detail/restlet-client-rest-api-t/aejoelaoggembcahagimdiliamlcdmfm). +Because API will use POST method I will be testing if code works correctly by +using [Restlet Client for Google +Chrome](https://chrome.google.com/webstore/detail/restlet-client-rest-api-t/aejoelaoggembcahagimdiliamlcdmfm). This software also allows you to set headers → for basic security with API_KEY. -To quickly generate passwords or API keys I usually use this nifty website +To quickly generate passwords or API keys I usually use this nifty website [RandomKeygen](https://randomkeygen.com/). Copy and paste code below over your previous code in file ```webapp.py```. @@ -204,12 +210,12 @@ if __name__ == "__main__": ) ``` -To run this simply go to folder containing python file and run -```python webapp.py``` from terminal. If everything goes ok you should have -simple API available via POST method on /api route. +To run this simply go to folder containing python file and run ```python +webapp.py``` from terminal. If everything goes ok you should have simple API +available via POST method on /api route. -After testing the service with Restlet Client you should be able to view -your data in a database file ```data.db```. +After testing the service with Restlet Client you should be able to view your +data in a database file ```data.db```. ![REST settings example](/assets/iot-application/iot-rest-example.png) @@ -218,38 +224,38 @@ for SQLite → [DB Browser for SQLite](http://sqlitebrowser.org/). ![SQLite database example](/assets/iot-application/iot-sqlite-db.png) -Table structure is as simple as it can be. We have ts (timestamp) and -value (value from Arduino). As you can see timestamp is generated on API -side. If you would happen to have atomic clock on Arduino it would be then -better to generate and send timestamp with the value. This would be -particularity useful if we would be collecting sensor data at a higher -frequency and then sending this data in bulk to API. +Table structure is as simple as it can be. We have ts (timestamp) and value +(value from Arduino). As you can see timestamp is generated on API side. If you +would happen to have atomic clock on Arduino it would be then better to generate +and send timestamp with the value. This would be particularity useful if we +would be collecting sensor data at a higher frequency and then sending this data +in bulk to API. -If you will deploy this app with uWSGI and multi-threaded, use -DSN (Data Source Name) url with ```?check_same_thread=False```. +If you will deploy this app with uWSGI and multi-threaded, use DSN (Data Source +Name) url with ```?check_same_thread=False```. -Ok, now that we have some sort of a working API with some basic security -so unwanted people can not post data to your database can we proceed further -and try to program Arduino to send data to API. +Ok, now that we have some sort of a working API with some basic security so +unwanted people can not post data to your database can we proceed further and +try to program Arduino to send data to API. ## Sending data to API with Arduino MKR1000 -First of all you should have MKR1000 module and microUSB cable to proceed. -If you have ever done any work with Arduino you should know that you also -need [Arduino IDE](https://www.arduino.cc/en/Main/Software). On provided link -you should be able to download and install IDE. Once that task is completed -and you have successfully run blink example you should proceed to the next step. +First of all you should have MKR1000 module and microUSB cable to proceed. If +you have ever done any work with Arduino you should know that you also need +[Arduino IDE](https://www.arduino.cc/en/Main/Software). On provided link you +should be able to download and install IDE. Once that task is completed and you +have successfully run blink example you should proceed to the next step. -In order to use wireless capabilities of MKR1000 you need to first install -[WiFi101 library](https://www.arduino.cc/en/Reference/WiFi101) in Arduino IDE. +In order to use wireless capabilities of MKR1000 you need to first install +[WiFi101 library](https://www.arduino.cc/en/Reference/WiFi101) in Arduino IDE. Please check before you install, you may already have it installed. -Code below is a working example that sends data to API. Before you try to test -your code make sure you have run Python web application. Then change settings -for wifi, api endpoint and api_key. If by some reason code bellow doesn't work +Code below is a working example that sends data to API. Before you try to test +your code make sure you have run Python web application. Then change settings +for wifi, api endpoint and api_key. If by some reason code bellow doesn't work for you please leave a comment and I'll try to help. -Once you have opened IDE and copied this code try to compile and upload it. +Once you have opened IDE and copied this code try to compile and upload it. Then open "Serial monitor" to see if any output is presented by Arduino. ```c @@ -335,50 +341,50 @@ void loop() { } ``` -As seen from example you can notice that Arduino is generating random integer -between [ 0 .. 1000 ]. You can easily replace this with a temperature sensor -or any other kind of sensor. +As seen from example you can notice that Arduino is generating random integer +between [ 0 .. 1000 ]. You can easily replace this with a temperature sensor or +any other kind of sensor. -Now that we have API under the hood and Arduino is sending demo data we can -now focus on data visualization. +Now that we have API under the hood and Arduino is sending demo data we can now +focus on data visualization. ## Data visualization -Before we continue we should examine our project folder structure. Currently -we only have two files in our project: +Before we continue we should examine our project folder structure. Currently we +only have two files in our project: _simple-iot-app/_ * _webapp.py_ * _data.db_ -We will now add HTML template that will contain CSS and JavaScript code inline -for the simplicity reason. And for the bottle framework to be able to scan root -application folder for templates we will add -```bottle.TEMPLATE_PATH.insert(0, "./")``` in ```webapp.py```. By default bottle -framework uses ```views/``` subfolder to store templates. This is not the ideal -situation and if you will use bottle to develop web applications you should use -native behavior and store templates in it's predefined folder. But for the sake -of example we will over-ride this. Be careful to fully replace your code with -new code that is provided below. Avoid partially replacing code in file :) Also -new code for reading data-points is provided in Python example below. - -First we add new route to our web application. It should be trigger when browser -hits root of application ```http://0.0.0.0:5000/```. This route will do nothing -more than render ```frontend.html``` template. This is done by -```return bottle.template("frontend.html")```. Check code below to further -examine how exactly this is done. - -Now we will expand ```/api``` route and use different methods to write or -read data-points. For writing data-point we will use POST method and for -reading points we will use GET method. GET method will return JSON object -with latest readings and historical data. - -There is a fantastic JavaScript library for plotting time-series charts -called [MetricsGraphics.js](https://www.metricsgraphicsjs.org) that is -based on [D3.js](https://d3js.org/) library for visualizing data. - -Data schema required by MetricsGraphics.js → to achieve this we need to +We will now add HTML template that will contain CSS and JavaScript code inline +for the simplicity reason. And for the bottle framework to be able to scan root +application folder for templates we will add ```bottle.TEMPLATE_PATH.insert(0, +"./")``` in ```webapp.py```. By default bottle framework uses ```views/``` +subfolder to store templates. This is not the ideal situation and if you will +use bottle to develop web applications you should use native behavior and store +templates in it's predefined folder. But for the sake of example we will +over-ride this. Be careful to fully replace your code with new code that is +provided below. Avoid partially replacing code in file :) Also new code for +reading data-points is provided in Python example below. + +First we add new route to our web application. It should be trigger when browser +hits root of application ```http://0.0.0.0:5000/```. This route will do nothing +more than render ```frontend.html``` template. This is done by ```return +bottle.template("frontend.html")```. Check code below to further examine how +exactly this is done. + +Now we will expand ```/api``` route and use different methods to write or read +data-points. For writing data-point we will use POST method and for reading +points we will use GET method. GET method will return JSON object with latest +readings and historical data. + +There is a fantastic JavaScript library for plotting time-series charts called +[MetricsGraphics.js](https://www.metricsgraphicsjs.org) that is based on +[D3.js](https://d3js.org/) library for visualizing data. + +Data schema required by MetricsGraphics.js → to achieve this we need to transform data from database into this format: ```json @@ -394,9 +400,9 @@ transform data from database into this format: ] ``` -Web application is now complete and we only need ```frontend.html``` that we -will develop now. If you would try to start web app now and go to root app -this will return error because we don't have frontend.html yet. +Web application is now complete and we only need ```frontend.html``` that we +will develop now. If you would try to start web app now and go to root app this +will return error because we don't have frontend.html yet. ```python # -*- coding: utf-8 -*- @@ -477,9 +483,9 @@ if __name__ == "__main__": ) ``` -And now finally we can implement ```frontend.html```. Create file with this -name and copy code below. When you are done you can start web application. -Steps for this part are listed below the code. +And now finally we can implement ```frontend.html```. Create file with this name +and copy code below. When you are done you can start web application. Steps for +this part are listed below the code. ```html @@ -572,23 +578,24 @@ Ok, lets now start application and start feeding it data. 2. connect Arduino MKR1000 to power source 3. open browser and go to ```http://0.0.0.0:5000``` -If everything goes well you should be seeing new data-points rendered on -chart every 5 seconds. +If everything goes well you should be seeing new data-points rendered on chart +every 5 seconds. -If you navigate to ```http://0.0.0.0:5000``` you should see rendered chart -as shown on picture below. +If you navigate to ```http://0.0.0.0:5000``` you should see rendered chart as +shown on picture below. ![Application output](/assets/iot-application/iot-app-output.png) -Complete application with all the code is available for [download](/assets/iot-application/simple-iot-application.zip). +Complete application with all the code is available for +[download](/assets/iot-application/simple-iot-application.zip). ## Conclusion -I hope this clarifies some aspects of IOT application development. Of course -this is a minimal example and is far from what can be done in real life with +I hope this clarifies some aspects of IOT application development. Of course +this is a minimal example and is far from what can be done in real life with some further dive into other technologies. -If you would like to continue exploring IOT world here are some interesting +If you would like to continue exploring IOT world here are some interesting resources for you to examine: * [Reading Sensors with an Arduino](https://www.allaboutcircuits.com/projects/reading-sensors-with-an-arduino/) @@ -597,4 +604,3 @@ resources for you to examine: * [Internet of Things (IoT) Tutorials](http://www.tutorialspoint.com/internet_of_things/) Any comment or additional ideas are welcomed in comments below. - diff --git a/content/posts/2018-01-16-using-digitalocean-spaces-object-storage-with-fuse.md b/content/posts/2018-01-16-using-digitalocean-spaces-object-storage-with-fuse.md index bfc77ee..3a62594 100644 --- a/content/posts/2018-01-16-using-digitalocean-spaces-object-storage-with-fuse.md +++ b/content/posts/2018-01-16-using-digitalocean-spaces-object-storage-with-fuse.md @@ -5,63 +5,67 @@ date: 2018-01-16T12:00:00+02:00 draft: false --- -Couple of months ago [DigitalOcean](https://www.digitalocean.com) introduced -new product called [Spaces](https://blog.digitalocean.com/introducing-spaces-object-storage/) -which is Object Storage very similar to Amazon's S3. This really peaked my -interest, because this was something I was missing and even the thought of -going over the internet for such functionality was in no interest to me. Also -in fashion with their previous pricing this also is very cheap and pricing -page is a no-brainer compared to AWS or GCE. [Prices are clearly and precisely defined and outlined](https://www.digitalocean.com/pricing/). -You must love them for that :) +Couple of months ago [DigitalOcean](https://www.digitalocean.com) introduced new +product called +[Spaces](https://blog.digitalocean.com/introducing-spaces-object-storage/) which +is Object Storage very similar to Amazon's S3. This really peaked my interest, +because this was something I was missing and even the thought of going over the +internet for such functionality was in no interest to me. Also in fashion with +their previous pricing this also is very cheap and pricing page is a no-brainer +compared to AWS or GCE. [Prices are clearly and precisely defined and +outlined](https://www.digitalocean.com/pricing/). You must love them for that +:) ## Initial requirements * Is it possible to use them as a mounted drive with FUSE? (tl;dr YES) -* Will the performance degrade over time and over different sizes of objects? +* Will the performance degrade over time and over different sizes of objects? (tl;dr NO&YES) -* Can storage be mounted on multiple machines at the same time and be writable? +* Can storage be mounted on multiple machines at the same time and be writable? (tl;dr YES) -> Let me be clear. This scripts I use are made just for benchmarking and are -> not intended to be used in real-life situations. Besides that, I am looking -> into using this approaches but adding caching service in front of it and then -> dumping everything as an object to storage. This could potentially be some -> interesting post of itself. But in case you would need real-time data without -> eventual consistency please take this scripts as they are: not usable in such +> Let me be clear. This scripts I use are made just for benchmarking and are not +> intended to be used in real-life situations. Besides that, I am looking into +> using this approaches but adding caching service in front of it and then +> dumping everything as an object to storage. This could potentially be some +> interesting post of itself. But in case you would need real-time data without +> eventual consistency please take this scripts as they are: not usable in such > situations. ## Is it possible to use them as a mounted drive with FUSE? -Well, actually they can be used in such manor. Because they are similar to -[AWS S3](https://aws.amazon.com/s3/) many tools are available and you can find -many articles and [Stackoverflow items](https://stackoverflow.com/search?q=s3+fuse). +Well, actually they can be used in such manor. Because they are similar to [AWS +S3](https://aws.amazon.com/s3/) many tools are available and you can find many +articles and [Stackoverflow items](https://stackoverflow.com/search?q=s3+fuse). -To make this work you will need DigitalOcean account. If you don't have one you -will not be able to test this code. But if you have an account then you go and -[create new Droplet](https://cloud.digitalocean.com/droplets/new?size=s-1vcpu-1gb®ion=ams3&distro=debian&distroImage=debian-9-x64&options=private_networking,install_agent). -If you click on this link you will already have preselected Debian 9 with +To make this work you will need DigitalOcean account. If you don't have one you +will not be able to test this code. But if you have an account then you go and +[create new +Droplet](https://cloud.digitalocean.com/droplets/new?size=s-1vcpu-1gb®ion=ams3&distro=debian&distroImage=debian-9-x64&options=private_networking,install_agent). +If you click on this link you will already have preselected Debian 9 with smallest VM option. -* Please be sure to add you SSH key, because we will login to this machine +* Please be sure to add you SSH key, because we will login to this machine remotely. -* If you change your region please remember which one you choose because we - will need this information when we try to mount space to our machine. +* If you change your region please remember which one you choose because we will + need this information when we try to mount space to our machine. -Instuctions on how to use SSH keys and how to setup them are available in article -[How To Use SSH Keys with DigitalOcean Droplets](https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets). +Instuctions on how to use SSH keys and how to setup them are available in +article [How To Use SSH Keys with DigitalOcean +Droplets](https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets). ![DigitalOcean Droplets](/assets/do-fuse/fuse-droplets.png) -After we created Droplet it's time to create new Space. This is done by clicking -on a button [Create](https://cloud.digitalocean.com/spaces/new) (right top -corner) and selecting Spaces. Choose pronounceable ```Unique name``` because we -will use it in examples below. You can either choose Private or Public, it +After we created Droplet it's time to create new Space. This is done by clicking +on a button [Create](https://cloud.digitalocean.com/spaces/new) (right top +corner) and selecting Spaces. Choose pronounceable ```Unique name``` because we +will use it in examples below. You can either choose Private or Public, it doesn't matter in our case. And you can always change that in the future. -When you have created new Space we should [generate Access key](https://cloud.digitalocean.com/settings/api/tokens). -This link will guide to the page when you can generate this key. After you -create new one, please save provided Key and Secret because Secret will not -be shown again. +When you have created new Space we should [generate Access +key](https://cloud.digitalocean.com/settings/api/tokens). This link will guide +to the page when you can generate this key. After you create new one, please +save provided Key and Secret because Secret will not be shown again. ![DigitalOcean Spaces](/assets/do-fuse/fuse-spaces.png) @@ -90,14 +94,13 @@ s3fs UNIQUE-NAME /mnt/ -ourl=https://ams3.digitaloceanspaces.com -ouse_cache=/tm echo "Hello cruel world" > /mnt/hello.txt ``` -After all this you can return to your browser and go to -[DigitalOcean Spaces](https://cloud.digitalocean.com/spaces) and click on your -created space. If file hello.txt is present you have successfully mounted -space to your machine and wrote data to it. +After all this you can return to your browser and go to [DigitalOcean +Spaces](https://cloud.digitalocean.com/spaces) and click on your created +space. If file hello.txt is present you have successfully mounted space to your +machine and wrote data to it. -I choose the same region for my Droplet and my Space but you don't have to. -You can have different regions. What this actually does to performance I -don't know. +I choose the same region for my Droplet and my Space but you don't have to. You +can have different regions. What this actually does to performance I don't know. Additional information on FUSE: @@ -106,9 +109,9 @@ Additional information on FUSE: ## Will the performance degrade over time and over different sizes of objects? -For this task I didn't want to just read and write text files or uploading -images. I actually wanted to figure out if using something like SQlite is -viable in this case. +For this task I didn't want to just read and write text files or uploading +images. I actually wanted to figure out if using something like SQlite is viable +in this case. ### Measurement experiment 1: File copy @@ -134,12 +137,12 @@ n=0; while (( n++ < 100 )); do (time cp 1MB.dat /mnt/1MB.$n.dat) |& tee -a 1MB.r n=0; while (( n++ < 100 )); do (time cp 10MB.dat /mnt/10MB.$n.dat) |& tee -a 10MB.results.txt; done ``` -Files of size 100MB were not successfully transferred and ended up displaying +Files of size 100MB were not successfully transferred and ended up displaying error (cp: failed to close '/mnt/100MB.1.dat': Operation not permitted). -As I suspected, object size is not really that important. Sadly I don't have -the time to test performance over periods of time. But if some of you would do -it please send me your data. I would be interested in seeing results. +As I suspected, object size is not really that important. Sadly I don't have the +time to test performance over periods of time. But if some of you would do it +please send me your data. I would be interested in seeing results. **Here are plotted results** @@ -177,18 +180,18 @@ Measurements are in seconds. })(); -As far as these tests show, performance is quite stable and can be predicted -which is fantastic. But this is a small test and spans only over couple of +As far as these tests show, performance is quite stable and can be predicted +which is fantastic. But this is a small test and spans only over couple of hours. So you should not completely trust them. ### Measurement experiment 2: SQLite performanse -I was unable to use database file directly from mounted drive so this is a -no-go as I suspected. So I executed code below on a local disk just to get -some benchmarks. I inserted 1000 records with DROPTABLE, CREATETABLE, -INSERTMANY, FETCHALL, COMMIT for 1000 times to generate statistics. As you can -see performance of SQLite is quite amazing. You could then potentially just -copy file to mounted drive and be done with it. +I was unable to use database file directly from mounted drive so this is a no-go +as I suspected. So I executed code below on a local disk just to get some +benchmarks. I inserted 1000 records with DROPTABLE, CREATETABLE, INSERTMANY, +FETCHALL, COMMIT for 1000 times to generate statistics. As you can see +performance of SQLite is quite amazing. You could then potentially just copy +file to mounted drive and be done with it. ```python import time @@ -305,24 +308,23 @@ and check locking etc. ## Can storage be mounted on multiple machines at the same time and be writable? -Well, this one didn't take long to test. And the answer is **YES**. I mounted -space on both machines and measured same performance on both machines. But -because file is downloaded before write and then uploaded on complete there -could potentially be problems is another process is trying to access the same +Well, this one didn't take long to test. And the answer is **YES**. I mounted +space on both machines and measured same performance on both machines. But +because file is downloaded before write and then uploaded on complete there +could potentially be problems is another process is trying to access the same file. ## Observations and conslusion -Using Spaces in this way makes it easier to access and manage files. But -besides that you would need to write additional code to make this one play -nice with you applications. - -Nevertheless, this was extremely simple to setup and use and this is just -another excellent product in DigitalOcean product line. I found this exercise -very valuable and am thinking about implementing some sort of mechanism for -SQLite, so data can be stored on Spaces and accessed by many VM's. For a -project where data doesn't need to be accessible in real-time and can have -couple of minutes old data this would be very interesting. If any of you find -this proposal interesting please write in a comment box below or shoot me an -email and I will keep you posted. - +Using Spaces in this way makes it easier to access and manage files. But besides +that you would need to write additional code to make this one play nice with you +applications. + +Nevertheless, this was extremely simple to setup and use and this is just +another excellent product in DigitalOcean product line. I found this exercise +very valuable and am thinking about implementing some sort of mechanism for +SQLite, so data can be stored on Spaces and accessed by many VM's. For a project +where data doesn't need to be accessible in real-time and can have couple of +minutes old data this would be very interesting. If any of you find this +proposal interesting please write in a comment box below or shoot me an email +and I will keep you posted. diff --git a/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md b/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md index a57201f..f0343ae 100644 --- a/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md +++ b/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md @@ -7,64 +7,59 @@ draft: false ## Initial thoughts -Imagine a world where you could go outside and take a leaf from a tree and put -it through your personal DNA sequencer and get data like music, videos or -computer programs from it. Well, this is all possible now. It was not done -on a large scale because it is quite expensive to create DNA strands but it's +Imagine a world where you could go outside and take a leaf from a tree and put +it through your personal DNA sequencer and get data like music, videos or +computer programs from it. Well, this is all possible now. It was not done on a +large scale because it is quite expensive to create DNA strands but it's possible. -Encoding data into DNA sequence is relatively simple process once you understand -the relationship between binary data and nucleotides and scientists have been -making large leaps in this field in order to provide viable long-term storage -solution for our data that would potentially survive our specie if case of -global disaster. We could imprint all the world's knowledge into plants and +Encoding data into DNA sequence is relatively simple process once you understand +the relationship between binary data and nucleotides and scientists have been +making large leaps in this field in order to provide viable long-term storage +solution for our data that would potentially survive our specie if case of +global disaster. We could imprint all the world's knowledge into plants and ensure the survival of our knowledge. -More optimistic usage for this technology would be easier storage of ever -growing data we produce every day. Once machines for sequencing DNA become fast -enough and cheaper this could mean the next evolution of storing data and +More optimistic usage for this technology would be easier storage of ever +growing data we produce every day. Once machines for sequencing DNA become fast +enough and cheaper this could mean the next evolution of storing data and abandoning classical hard and solid state drives in data warehouses. -As we currently stand this is still not viable but it is quite an amazing and +As we currently stand this is still not viable but it is quite an amazing and cool technology. -My interests in this field are purely in encoding processes and experimental -testing mainly because I don't have the access to this expensive machines. My -initial goal was to create a toolkit that can be used by everybody to encode +My interests in this field are purely in encoding processes and experimental +testing mainly because I don't have the access to this expensive machines. My +initial goal was to create a toolkit that can be used by everybody to encode their data into a proper DNA sequence. ## Glossary -**deoxyribose** -A five-carbon sugar molecule with a hydrogen atom rather than a hydroxyl group -in the 2′ position; the sugar component of DNA nucleotides. +**deoxyribose** A five-carbon sugar molecule with a hydrogen atom rather than a +hydroxyl group in the 2′ position; the sugar component of DNA nucleotides. -**double helix** -The molecular shape of DNA in which two strands of nucleotides wind around -each other in a spiral shape. +**double helix** The molecular shape of DNA in which two strands of nucleotides +wind around each other in a spiral shape. -**nitrogenous base** -A nitrogen-containing molecule that acts as a base; often referring to one of -the purine or pyrimidine components of nucleic acids. +**nitrogenous base** A nitrogen-containing molecule that acts as a base; often +referring to one of the purine or pyrimidine components of nucleic acids. -**phosphate group** -A molecular group consisting of a central phosphorus atom bound to four oxygen -atoms. +**phosphate group** A molecular group consisting of a central phosphorus atom +bound to four oxygen atoms. -**RGB** -The RGB color model is an additive color model in which red, green and blue -light are added together in various ways to reproduce a broad array of colors. +**RGB** The RGB color model is an additive color model in which red, green and +blue light are added together in various ways to reproduce a broad array of +colors. -**GCC** -The GNU Compiler Collection is a compiler system produced by the GNU Project -supporting various programming languages. +**GCC** The GNU Compiler Collection is a compiler system produced by the GNU +Project supporting various programming languages. ## Data encoding -**TL;DR:** Encoding involves the use of a code to change original data into a +**TL;DR:** Encoding involves the use of a code to change original data into a form that can be used by an external process. -Encoding is the process of converting data into a format required for a number +Encoding is the process of converting data into a format required for a number of information processing needs, including: - Program compiling and execution @@ -74,7 +69,7 @@ of information processing needs, including: Encoding can have two meanings: - In computer technology, encoding is the process of applying a specific code, - such as letters, symbols and numbers, to data for conversion into an + such as letters, symbols and numbers, to data for conversion into an equivalent cipher. - In electronics, encoding refers to analog to digital conversion. @@ -99,23 +94,25 @@ Encoding can have two meanings: ## What is DNA? -Deoxyribonucleic acid, a self-replicating material which is -**present in nearly all living organisms** as the main constituent of -chromosomes. It is the **carrier of genetic information**. +Deoxyribonucleic acid, a self-replicating material which is **present in nearly +all living organisms** as the main constituent of chromosomes. It is the +**carrier of genetic information**. > The nitrogen in our DNA, the calcium in our teeth, the iron in our blood, > the carbon in our apple pies were made in the interiors of collapsing stars. > We are made of starstuff. > **-- Carl Sagan, Cosmos** -The nucleotide in DNA consists of a sugar (deoxyribose), one of four bases -(cytosine (C), thymine (T), adenine (A), guanine (G)), and a phosphate. -Cytosine and thymine are pyrimidine bases, while adenine and guanine are purine +The nucleotide in DNA consists of a sugar (deoxyribose), one of four bases +(cytosine (C), thymine (T), adenine (A), guanine (G)), and a phosphate. +Cytosine and thymine are pyrimidine bases, while adenine and guanine are purine bases. The sugar and the base together are called a nucleoside. ![DNA](/assets/dna-sequence/dna-basics.jpg) -*DNA (a) forms a double stranded helix, and (b) adenine pairs with thymine and cytosine pairs with guanine. (credit a: modification of work by Jerome Walker, Dennis Myts)* +*DNA (a) forms a double stranded helix, and (b) adenine pairs with thymine and +cytosine pairs with guanine. (credit a: modification of work by Jerome Walker, +Dennis Myts)* ## Encode binary data into DNA sequence @@ -128,18 +125,18 @@ As an input file you can use any file you want: - Database files, - etc. -Note: If you would copy all the bytes from RAM to file or pipe data to file you +Note: If you would copy all the bytes from RAM to file or pipe data to file you could encode also this data as long as you provide file pointer to the encoder. ### Basic Encoding -As already mentioned, the Basic Encoding is based on a simple mapping. Since -DNA is composed of 4 nucleotides (Adenine, Cytosine, Guanine, Thymine; usually +As already mentioned, the Basic Encoding is based on a simple mapping. Since DNA +is composed of 4 nucleotides (Adenine, Cytosine, Guanine, Thymine; usually referred using the first letter). Using this technique we can encode $$ log_2(4) = log_2(2^2) = 2 bits $$ -using a single nucleotide. In this way, we are able to use the 4 bases that +using a single nucleotide. In this way, we are able to use the 4 bases that compose the DNA strand to encode each byte of data. | Two bits | Nucleotides | @@ -149,8 +146,8 @@ compose the DNA strand to encode each byte of data. | 01 | **C** (Cytosine) | | 11 | **T** (Thymine) | -With this in mind we can simply encode any data by using two-bit to -Nucleotides conversion. +With this in mind we can simply encode any data by using two-bit to Nucleotides +conversion. ```python { Algorithm 1: Naive byte array to DNA encode } @@ -173,29 +170,29 @@ begin end ``` -Another encoding would be **Goldman encoding**. Using this encoding helps with -Nonsense mutation (amino acids replaced by a stop codon) that occurs and is -the most problematic during translation because it leads to truncated amino -acid sequences, which in turn results in truncated proteins. +Another encoding would be **Goldman encoding**. Using this encoding helps with +Nonsense mutation (amino acids replaced by a stop codon) that occurs and is the +most problematic during translation because it leads to truncated amino acid +sequences, which in turn results in truncated proteins. [Where to store big data? In DNA: Nick Goldman at TEDxPrague](https://www.youtube.com/watch?v=a4PiGWNsIEU) ### FASTA file format -In bioinformatics, FASTA format is a text-based format for representing either -nucleotide sequences or peptide sequences, in which nucleotides or amino acids -are represented using single-letter codes. The format also allows for sequence -names and comments to precede the sequences. The format originates from the -FASTA software package, but has now become a standard in the field of +In bioinformatics, FASTA format is a text-based format for representing either +nucleotide sequences or peptide sequences, in which nucleotides or amino acids +are represented using single-letter codes. The format also allows for sequence +names and comments to precede the sequences. The format originates from the +FASTA software package, but has now become a standard in the field of bioinformatics. -The first line in a FASTA file started either with a ">" (greater-than) symbol -or, less frequently, a ";" (semicolon) was taken as a comment. Subsequent -lines starting with a semicolon would be ignored by software. Since the only -comment used was the first, it quickly became used to hold a summary -description of the sequence, often starting with a unique library accession -number, and with time it has become commonplace to always use ">" for the first -line and to not use ";" comments (which would otherwise be ignored). +The first line in a FASTA file started either with a ">" (greater-than) symbol +or, less frequently, a ";" (semicolon) was taken as a comment. Subsequent lines +starting with a semicolon would be ignored by software. Since the only comment +used was the first, it quickly became used to hold a summary description of the +sequence, often starting with a unique library accession number, and with time +it has become commonplace to always use ">" for the first line and to not use +";" comments (which would otherwise be ignored). ``` ;LCBO - Prolactin precursor - Bovine @@ -218,7 +215,7 @@ GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX IENY ``` -FASTA format was extended by [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) +FASTA format was extended by [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) format from the [Sanger Centre](https://www.sanger.ac.uk/) in Cambridge. ### PNG encoded DNA sequence @@ -230,7 +227,7 @@ format from the [Sanger Centre](https://www.sanger.ac.uk/) in Cambridge. | C ➞ Cytosine | (255,0,0) | Red | | T ➞ Thymine | (255,255,0) | Yellow | -With this in mind we can create a simple algorithm to create PNG representation +With this in mind we can create a simple algorithm to create PNG representation of a DNA sequence. ```python @@ -252,7 +249,7 @@ end ## Encoding text file in practice -In this example we will take a simple text file as our input stream for +In this example we will take a simple text file as our input stream for encoding. This file will have a quote from Niels Bohr and saved as txt file. > How wonderful that we have met with a paradox. Now we have some hope of @@ -306,8 +303,9 @@ After encoding into PNG format this file looks like this. The larger the input stream is the larger the PNG file would be. -Compiled basic Hello World C program with [GCC](https://www.gnu.org/software/gcc/) -would [look like](/assets/dna-sequence/sample.png). +Compiled basic Hello World C program with +[GCC](https://www.gnu.org/software/gcc/) would [look +like](/assets/dna-sequence/sample.png). ```c // gcc -O3 -o sample sample.c @@ -370,7 +368,7 @@ First we generate some binary sample data with dd. dd if=<(openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero) of=1KB.bin bs=1KB count=1 iflag=fullblock ``` -Our freshly generated 1KB file looks something like this (its full of garbage +Our freshly generated 1KB file looks something like this (its full of garbage data as intended). ![Sample binary file 1KB](/assets/dna-sequence/sample-binary-file.png) @@ -410,4 +408,3 @@ gzip -9 < 10MB.fa > 10MB.fa.gz - https://opentextbc.ca/biology/chapter/9-1-the-structure-of-dna/ - https://arxiv.org/abs/1801.04774 - https://en.wikipedia.org/wiki/FASTA_format - diff --git a/content/posts/2019-10-14-simplifying-and-reducing-clutter.md b/content/posts/2019-10-14-simplifying-and-reducing-clutter.md index 13f4f42..97ddb34 100644 --- a/content/posts/2019-10-14-simplifying-and-reducing-clutter.md +++ b/content/posts/2019-10-14-simplifying-and-reducing-clutter.md @@ -5,53 +5,54 @@ date: 2019-10-14T12:00:00+02:00 draft: false --- -I recently moved my main working machine back from Hachintosh to Linux. Well -the experiment was interesting and I have done some great work on macOS but it -was time to move back. - -I actually really missed Linux. The simplicity of `apt-get` or just the amount -of software that exists for Linux should be a no-brainer. I spent most of my -time on macOS finding solutions to make things work. Using [Brew](https://brew.sh/) -was just a horrible experience and far from package managers of Linux. At least -they managed to get that `sudo` debacle sorted. - -Not all was bad. macOS in general was a perfectly good environment. Things like -Docker and tooling like this worked without any hiccups. My normal tools like -coding IDE worked flawlessly and the whole look and feel is just superb. I have -been using MacBook Air for couple of years so I was used to the system but -never as a daily driver. - -One of the things I did after I installed Linux back on my machine was cleaning -up my Dropbox folder. I have everything on Dropbox. Even projects folder. I -write code for living so my whole life revolves around couple of megs of code -(with assets). So it's not like I have huge files on my machine. I don't have -movies or music or pictures on my PC. All of that stuff is in cloud. I use +I recently moved my main working machine back from Hachintosh to Linux. Well the +experiment was interesting and I have done some great work on macOS but it was +time to move back. + +I actually really missed Linux. The simplicity of `apt-get` or just the amount +of software that exists for Linux should be a no-brainer. I spent most of my +time on macOS finding solutions to make things work. Using +[Brew](https://brew.sh/) was just a horrible experience and far from package +managers of Linux. At least they managed to get that `sudo` debacle sorted. + +Not all was bad. macOS in general was a perfectly good environment. Things like +Docker and tooling like this worked without any hiccups. My normal tools like +coding IDE worked flawlessly and the whole look and feel is just superb. I have +been using MacBook Air for couple of years so I was used to the system but never +as a daily driver. + +One of the things I did after I installed Linux back on my machine was cleaning +up my Dropbox folder. I have everything on Dropbox. Even projects folder. I +write code for living so my whole life revolves around couple of megs of code +(with assets). So it's not like I have huge files on my machine. I don't have +movies or music or pictures on my PC. All of that stuff is in cloud. I use Google music and I have Netflix account which is more than enough for me. -I also went and deleted some of the repositories on my Github account. I have -deleted more code than deployed. People find this strange but for me deleting -something feels so cathartic and also forces me to write better code next time -around when I am faced with similar problem. That was a huge relief if I am +I also went and deleted some of the repositories on my Github account. I have +deleted more code than deployed. People find this strange but for me deleting +something feels so cathartic and also forces me to write better code next time +around when I am faced with similar problem. That was a huge relief if I am being totally honest. -Next step was to do something with my webpage. I have been using some scripts -I wrote a while ago to generate static pages from markdown source posts. I kept -on adding and adding stuff on top of it and it became a source of a +Next step was to do something with my webpage. I have been using some scripts I +wrote a while ago to generate static pages from markdown source posts. I kept on +adding and adding stuff on top of it and it became a source of a frustration. And this is just a simple blog and I was using gulp and npm. -Anyways after couple of hours of searching and testing static generators I -found an interesting one [https://github.com/piranha/gostatic](https://github.com/piranha/gostatic) -and I just decided to use this one. It was the only one that had a simple -templating engine, not that I really need one. But others had this convoluted -way of trying to solve everything and at the end just required quite bigger -learning curve I was ready to go with. So I deleted couple of old posts, -simplified HTML, trashed most of the CSS and went with -[https://motherfuckingwebsite.com/](https://motherfuckingwebsite.com/) aesthetics. -Yeah, the previous site was more visually stimulating but all I really care is -the content at this point. And Times New Roman font is kind of awesome. - -I stopped working on most of the projects in the past couple of months because -the overhead was just too insane. There comes a point when you stretch yourself +Anyways after couple of hours of searching and testing static generators I found +an interesting one +[https://github.com/piranha/gostatic](https://github.com/piranha/gostatic) and I +just decided to use this one. It was the only one that had a simple templating +engine, not that I really need one. But others had this convoluted way of trying +to solve everything and at the end just required quite bigger learning curve I +was ready to go with. So I deleted couple of old posts, simplified HTML, trashed +most of the CSS and went with +[https://motherfuckingwebsite.com/](https://motherfuckingwebsite.com/) +aesthetics. Yeah, the previous site was more visually stimulating but all I +really care is the content at this point. And Times New Roman font is kind of +awesome. + +I stopped working on most of the projects in the past couple of months because +the overhead was just too insane. There comes a point when you stretch yourself too much and then you stop progressing and with that comes dissatisfaction. So that's about it. Moving forward minimal style. - diff --git a/content/posts/2019-10-19-using-sentiment-analysis-for-clickbait-detection.md b/content/posts/2019-10-19-using-sentiment-analysis-for-clickbait-detection.md index 995da25..e7324bb 100644 --- a/content/posts/2019-10-19-using-sentiment-analysis-for-clickbait-detection.md +++ b/content/posts/2019-10-19-using-sentiment-analysis-for-clickbait-detection.md @@ -7,22 +7,22 @@ draft: false ## Initial thoughts -One of the things that interested me for a while now is if major well -established news sites use click bait titles to drive additional traffic -to their sites and generate additional impressions. +One of the things that interested me for a while now is if major well +established news sites use click bait titles to drive additional traffic to +their sites and generate additional impressions. -Goal is to see how article titles and actual content of article differ from -each other and see if titles are clickbaited. +Goal is to see how article titles and actual content of article differ from each +other and see if titles are clickbaited. ## Preparing and cleaning data -For this example I opted to just use RSS feed from a new website and decided -to go with [The Guardian](https://www.theguardian.com) World news. While this -gets us limited data (~40) articles and also description (actual content) is -trimmed this really doesn't reflect the actual article contents. +For this example I opted to just use RSS feed from a new website and decided to +go with [The Guardian](https://www.theguardian.com) World news. While this gets +us limited data (~40) articles and also description (actual content) is trimmed +this really doesn't reflect the actual article contents. -To get better content I could use web scraping and use RSS as link list and -fetch contents directly from website, but for this simple example this will +To get better content I could use web scraping and use RSS as link list and +fetch contents directly from website, but for this simple example this will suffice. There are couple of requirements we need to install before we continue: @@ -50,12 +50,12 @@ for item in feed.entries: Since we now have cleaned up data in our `feed.entries` object we can start with performing sentiment analysis. -There are many sentiment analysis libraries available that range from rule-based -sentiment analysis up to machine learning supported analysis. To keep things -simple I decided to use rule-based analysis library -[vaderSentiment](https://github.com/cjhutto/vaderSentiment) from -[C.J. Hutto](https://github.com/cjhutto). Really nice library and quite -easy to use. +There are many sentiment analysis libraries available that range from rule-based +sentiment analysis up to machine learning supported analysis. To keep things +simple I decided to use rule-based analysis library +[vaderSentiment](https://github.com/cjhutto/vaderSentiment) from +[C.J. Hutto](https://github.com/cjhutto). Really nice library and quite easy to +use. ```python from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer @@ -68,9 +68,9 @@ for item in feed.entries: sentiment_results.append([sentiment_title['compound'], sentiment_description['compound']]) ``` -Now that we have this data in a shape that is compatible with matplotlib we can -plot results to see the difference between title and description sentiment of -an article. +Now that we have this data in a shape that is compatible with matplotlib we can +plot results to see the difference between title and description sentiment of an +article. ```python import matplotlib.pyplot as plt @@ -85,15 +85,15 @@ plt.show() ## Results and assets 1. Because of the small sample size further conclusions are impossible to make. -2. Rule-based approach may not be the best way of doing this. By using deep +2. Rule-based approach may not be the best way of doing this. By using deep learning we would be able to get better insights. -3. **Next step would be to** periodically fetch RSS items and store them over - a longer period of time and then perform analysis again and use either - machine learning or deep learning on top of it. +3. **Next step would be to** periodically fetch RSS items and store them over a + longer period of time and then perform analysis again and use either machine + learning or deep learning on top of it. ![Relationship between title and description](/assets/sentiment-analysis/guardian-sa-title-desc-relationship.png) -Figure above displays difference between title and description sentiment for +Figure above displays difference between title and description sentiment for specific RSS feed item. 1 means positive and -1 means negative sentiment. [» Download Jupyter Notebook](/assets/sentiment-analysis/sentiment-analysis.ipynb) diff --git a/content/posts/2020-03-22-simple-sse-based-pubsub-server.md b/content/posts/2020-03-22-simple-sse-based-pubsub-server.md index 77c42a9..60745d0 100644 --- a/content/posts/2020-03-22-simple-sse-based-pubsub-server.md +++ b/content/posts/2020-03-22-simple-sse-based-pubsub-server.md @@ -7,35 +7,35 @@ draft: false ## Before we continue ... -Publisher Subscriber model is nothing new and there are many amazing solutions -out there, so writing a new one would be a waste of time if other solutions +Publisher Subscriber model is nothing new and there are many amazing solutions +out there, so writing a new one would be a waste of time if other solutions wouldn't have quite complex install procedures and weren't so hard to maintain. -But to be fair, comparing this simple server with something like -[Kafka](https://kafka.apache.org/) or [RabbitMQ](https://www.rabbitmq.com/) is +But to be fair, comparing this simple server with something like +[Kafka](https://kafka.apache.org/) or [RabbitMQ](https://www.rabbitmq.com/) is laughable at the least. Those solutions are enterprise grade and have many -mechanisms there to ensure messages aren't lost and much more. Regardless of -these drawbacks, this method has been tested on a large website and worked -until now without any problems. So now, that we got that cleared up, let's -continue. - -***Wiki definition:** Publish/subscribe messaging, or pub/sub messaging, is a -form of asynchronous service-to-service communication used in serverless and -microservices architectures. In a pub/sub model, any message published to a +mechanisms there to ensure messages aren't lost and much more. Regardless of +these drawbacks, this method has been tested on a large website and worked until +now without any problems. So now, that we got that cleared up, let's continue. + +***Wiki definition:** Publish/subscribe messaging, or pub/sub messaging, is a +form of asynchronous service-to-service communication used in serverless and +microservices architectures. In a pub/sub model, any message published to a topic is immediately received by all the subscribers to the topic.* ## General goals - provide a simple server that relays messages to all the connected clients, - messages can be posted on specific topics, -- messages get sent via [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) +- messages get sent via [Server-Sent + Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) to all the subscribers. ## How exactly does the pub/sub model work? -The easiest way to explain this is with diagram bellow. Basic function is -simple. We have subscribers that receive messages, and we have publishers that -create and post messages. Similar model is also well know pattern that works -on a premise of consumers and producers, and they take similar roles. +The easiest way to explain this is with diagram bellow. Basic function is +simple. We have subscribers that receive messages, and we have publishers that +create and post messages. Similar model is also well know pattern that works on +a premise of consumers and producers, and they take similar roles. ![How PubSub works](/assets/simple-pubsub-server/pubsub-overview.png) @@ -45,43 +45,47 @@ on a premise of consumers and producers, and they take similar roles. - consumer is receiving messages from subscribed topic, - servers is also known as Broker, - broker does not store messages or tracks success, -- broker uses [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) - method for delivering messages, -- if consumer wants to receive messages from a topic, producer and consumer topics - must match, +- broker uses + [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) method + for delivering messages, +- if consumer wants to receive messages from a topic, producer and consumer + topics must match, - consumer can subscribe to multiple topics, - producer can publish to multiple topics, - each message has a messageId. **Known drawbacks:** -- messages will not be stored in a persistent queue or unreceived messages like - [DeadLetterQueue](https://en.wikipedia.org/wiki/Dead_letter_queue) so old +- messages will not be stored in a persistent queue or unreceived messages like + [DeadLetterQueue](https://en.wikipedia.org/wiki/Dead_letter_queue) so old messages could be lost on server restart, -- [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) - opens a long-running connection between the client and the server so make - sure if your setup is load balanced that the load balancer in this case can - have long opened connection, +- [Server-Sent + Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) + opens a long-running connection between the client and the server so make sure + if your setup is load balanced that the load balancer in this case can have + long opened connection, - no system moderation due to the dynamic nature of creating queues. ## Server-Sent Events -Read more about it on [official specification page](https://html.spec.whatwg.org/multipage/server-sent-events.html). +Read more about it on [official specification +page](https://html.spec.whatwg.org/multipage/server-sent-events.html). ### Current browser support ![Browser support](/assets/simple-pubsub-server/caniuse.png) -Check [https://caniuse.com/#feat=eventsource](https://caniuse.com/#feat=eventsource) +Check +[https://caniuse.com/#feat=eventsource](https://caniuse.com/#feat=eventsource) for latest information about browser support. ### Known issues - Firefox 52 and below do not support EventSource in web/shared workers -- In Firefox prior to version 36 server-sent events do not reconnect +- In Firefox prior to version 36 server-sent events do not reconnect automatically in case of a connection interrupt (bug) -- Reportedly, CORS in EventSource is currently supported in Firefox 10+, - Opera 12+, Chrome 26+, Safari 7.0+. +- Reportedly, CORS in EventSource is currently supported in Firefox 10+, Opera + 12+, Chrome 26+, Safari 7.0+. - Antivirus software may block the event streaming data chunks. Source: [https://caniuse.com/#feat=eventsource](https://caniuse.com/#feat=eventsource) @@ -104,7 +108,7 @@ data: this is line two ``` -And you can specify your own event types (the above messages will all trigger +And you can specify your own event types (the above messages will all trigger the message event): ```bash @@ -116,7 +120,7 @@ data: 103.34 ### Server requirements -The important thing is how you send headers and which headers are sent by the +The important thing is how you send headers and which headers are sent by the server that triggers browser to threat response as a EventStream. Headers responsible for this are: @@ -129,23 +133,23 @@ Connection: keep-alive ### Debugging with Google Chrome -Google Chrome provides build-in debugging and exploration tool for -[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) +Google Chrome provides build-in debugging and exploration tool for [Server-Sent +Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) which is quite nice and available from Developer Tools under Network tab. -> You can debug only client side events that get received and not the server -> ones. For debugging server events add `console.log` to `server.js` code and +> You can debug only client side events that get received and not the server +> ones. For debugging server events add `console.log` to `server.js` code and > print out events. ![Google Chrome Developer Tools EventStream](/assets/simple-pubsub-server/chrome-debugging.png) ## Server implementation -For the sake of this example we will use [Node.js](https://nodejs.org/en/) -with [Express](https://expressjs.com) as our router since this is the easiest -way to get started and we will use already written SSE library for node -[sse-pubsub](https://www.npmjs.com/package/sse-pubsub) so we don't reinvent -the wheel. +For the sake of this example we will use [Node.js](https://nodejs.org/en/) with +[Express](https://expressjs.com) as our router since this is the easiest way to +get started and we will use already written SSE library for node +[sse-pubsub](https://www.npmjs.com/package/sse-pubsub) so we don't reinvent the +wheel. ```bash npm init --yes @@ -252,16 +256,16 @@ app.listen(port, () => { ### Our custom message format -Each message posted on a server must be in a specific format that out server -accepts. Having structure like this allows us to have multiple separated type -of events on each topic. +Each message posted on a server must be in a specific format that out server +accepts. Having structure like this allows us to have multiple separated type of +events on each topic. -With this we can separate streams and only receive events that belong to the +With this we can separate streams and only receive events that belong to the topic. -One example would be, that we have index page and we want to receive messages -about new upvotes or new subscribers but we don't want to follow events for -other pages. This reduces clutter and overall network. And structure is much +One example would be, that we have index page and we want to receive messages +about new upvotes or new subscribers but we don't want to follow events for +other pages. This reduces clutter and overall network. And structure is much nicer and maintanable. ```json @@ -278,15 +282,15 @@ nicer and maintanable. -You can download [the code](../simple-pubsub-server/sse-pubsub-server.zip) -and follow along. +You can download [the code](../simple-pubsub-server/sse-pubsub-server.zip) and +follow along. ### Publisher -As talked about above publisher is the one that send messages to the -broker/server. Message inside the payload can be whatever you want (string, -object, array). I would however personally avoid send large chunks of data -like blobs and such. +As talked about above publisher is the one that send messages to the +broker/server. Message inside the payload can be whatever you want (string, +object, array). I would however personally avoid send large chunks of data like +blobs and such. ```html @@ -359,19 +363,19 @@ like blobs and such. ### Subscriber -Subscriber is responsible for receiving new messages that come from server via -publisher. The code bellow is very rudimentary but works and follows the +Subscriber is responsible for receiving new messages that come from server via +publisher. The code bellow is very rudimentary but works and follows the implementation guidelines for EventSource. -You can use either Developer Tools Console to see incoming messages or you can +You can use either Developer Tools Console to see incoming messages or you can defer to Debugging with Google Chrome section above to see all EventStream messages. -> Don't be alarmed if the subscriber gets disconnected from the server every -> so often. The code we have here resets connection every 15s but it -> automatically get reconnected and fetches all messages up to last received -> message id. This setting can be adjusted in `server.js` file; search for -> the `maxStreamDuration` variable. +> Don't be alarmed if the subscriber gets disconnected from the server every so +> often. The code we have here resets connection every 15s but it automatically +> get reconnected and fetches all messages up to last received message id. This +> setting can be adjusted in `server.js` file; search for the +> `maxStreamDuration` variable. ```html diff --git a/content/posts/2020-03-27-create-placeholder-images-with-sharp.md b/content/posts/2020-03-27-create-placeholder-images-with-sharp.md index f7dd362..ac4f053 100644 --- a/content/posts/2020-03-27-create-placeholder-images-with-sharp.md +++ b/content/posts/2020-03-27-create-placeholder-images-with-sharp.md @@ -5,14 +5,15 @@ date: 2020-03-27T12:00:00+02:00 draft: false --- -I have been searching for a solution to pre-generate some placeholder images -for image server I needed to develop that resizes images on S3. I though this -would be a 15min job and quickly found out how very mistaken I was. +I have been searching for a solution to pre-generate some placeholder images for +image server I needed to develop that resizes images on S3. I though this would +be a 15min job and quickly found out how very mistaken I was. -Even though Node.js is not really the best way to do this kind of things -(surely something written in C or Rust or even Golang would be the correct way -to do this but we didn't need the speed in our case) I found an excellent -library [sharp - High performance Node.js image processing](https://github.com/lovell/sharp). +Even though Node.js is not really the best way to do this kind of things (surely +something written in C or Rust or even Golang would be the correct way to do +this but we didn't need the speed in our case) I found an excellent library +[sharp - High performance Node.js image +processing](https://github.com/lovell/sharp). Getting things running was a breeze. @@ -53,20 +54,20 @@ s3.putObject({ All this code was wrapped inside a web service with some additional security checks and defensive coding to detect if key is missing on S3. -And at that point I needed to return placeholder images as a response in case -key is missing or x,y are not allowed by the server etc. I could have created -PNG in Gimp and just serve them but I wanted to respect aspect ratio and I +And at that point I needed to return placeholder images as a response in case +key is missing or x,y are not allowed by the server etc. I could have created +PNG in Gimp and just serve them but I wanted to respect aspect ratio and I didn't want to return some mangled images. -> Main problem with finding a clean solution I could copy and paste and change -a bit was a task. API is changing constantly and there weren't clear examples -or I was unable to find them. +> Main problem with finding a clean solution I could copy and paste and change a +> bit was a task. API is changing constantly and there weren't clear examples or +> I was unable to find them. ## Generating placeholder images using SVG -What I ended up was using SVG to generate text and created image with sharp and -used composition to combine both layers. Response returned by this function is -a buffer you can use to either upload to S3 or save to local file. +What I ended up was using SVG to generate text and created image with sharp and +used composition to combine both layers. Response returned by this function is a +buffer you can use to either upload to S3 or save to local file. ```js const generatePlaceholderImageWithText = async (width, height, message) => { @@ -91,11 +92,10 @@ const generatePlaceholderImageWithText = async (width, height, message) => { } ``` -That is about it. Nothing more to it. You can change the color of the image by -changing `background` and if you want to change text styling you can adapt -SVG to your needs. - -> Also be careful about the length of the text. This function positions text -> at the center and adds `20px` padding on all sides. If text is longer than -> the image it will get cut. +That is about it. Nothing more to it. You can change the color of the image by +changing `background` and if you want to change text styling you can adapt SVG +to your needs. +> Also be careful about the length of the text. This function positions text at +> the center and adds `20px` padding on all sides. If text is longer than the +> image it will get cut. diff --git a/content/posts/2020-03-29-the-strange-case-of-elasticsearch-allocation-failure.md b/content/posts/2020-03-29-the-strange-case-of-elasticsearch-allocation-failure.md index d0f4bac..bf1d710 100644 --- a/content/posts/2020-03-29-the-strange-case-of-elasticsearch-allocation-failure.md +++ b/content/posts/2020-03-29-the-strange-case-of-elasticsearch-allocation-failure.md @@ -5,33 +5,33 @@ date: 2020-03-29T12:00:00+02:00 draft: false --- -I've been using Elasticsearch in production for 5 years now and never had a -single problem with it. Hell, never even known there could be a problem. Just +I've been using Elasticsearch in production for 5 years now and never had a +single problem with it. Hell, never even known there could be a problem. Just worked. All this time. The first node that I deployed is still being used in production, never updated, upgraded, touched in anyway. -All this bliss came to an abrupt end this Friday when I got notification that -Elasticsearch cluster went warm. Well, warm is not that bad right? Wrong! -Quickly after that I got another email which sent chills down my spine. -Cluster is now red. RED! Now, shit really hit the fan! +All this bliss came to an abrupt end this Friday when I got notification that +Elasticsearch cluster went warm. Well, warm is not that bad right? Wrong! +Quickly after that I got another email which sent chills down my spine. Cluster +is now red. RED! Now, shit really hit the fan! -I tried googling what could be the problem and after executing allocation -function noticed that some shards were unassigned and 5 attempts were already -made (which is BTW to my luck the maximum) and that meant I am basically fucked. -They also applied that one should wait for cluster to re-balance itself. So, -I waited. One hour, two hours, several hours. Nothing, still RED. +I tried googling what could be the problem and after executing allocation +function noticed that some shards were unassigned and 5 attempts were already +made (which is BTW to my luck the maximum) and that meant I am basically fucked. +They also applied that one should wait for cluster to re-balance itself. So, I +waited. One hour, two hours, several hours. Nothing, still RED. -The strangest thing about it all was, that queries were still being fulfilled. -Data was coming out. On the outside it looked like nothing was wrong but -everybody that would look at the cluster would know immediately that something +The strangest thing about it all was, that queries were still being fulfilled. +Data was coming out. On the outside it looked like nothing was wrong but +everybody that would look at the cluster would know immediately that something was very very wrong and we were living on borrowed time here. -> **Please, DO NOT do what I did.** Seriously! Please ask someone on official -forums or if you know an expert please consult him. There could be million of -reasons and these solution fit my problem. Maybe in your case it would -disastrous. I had all the data backed up and even if I would fail spectacularly -I would be able to restore the data. It would be a huge pain and I would -loose couple of days but I had a plan B. +> **Please, DO NOT do what I did.** Seriously! Please ask someone on official +forums or if you know an expert please consult him. There could be million of +reasons and these solution fit my problem. Maybe in your case it would +disastrous. I had all the data backed up and even if I would fail spectacularly +I would be able to restore the data. It would be a huge pain and I would loose +couple of days but I had a plan B. Executing allocation and told me what the problem was but no clear solution yet. @@ -39,14 +39,14 @@ Executing allocation and told me what the problem was but no clear solution yet. GET /_cat/allocation?format=json ``` -I got a message that `ALLOCATION_FAILED` with additional info -`failed to create shard, failure ioexception[failed to obtain in-memory shard lock]`. -Well splendid! I must also say that our cluster is capable more than enough -to handle the traffic. Also JVM memory pressure never was an issue. So what -happened really then? +I got a message that `ALLOCATION_FAILED` with additional info `failed to create +shard, failure ioexception[failed to obtain in-memory shard lock]`. Well +splendid! I must also say that our cluster is capable more than enough to handle +the traffic. Also JVM memory pressure never was an issue. So what happened +really then? -I tried also re-routing failed ones with no success due to AWS restrictions -on having managed Elasticsearch cluster (they lock some of the functions). +I tried also re-routing failed ones with no success due to AWS restrictions on +having managed Elasticsearch cluster (they lock some of the functions). ```yaml POST /_cluster/reroute?retry_failed=true @@ -60,10 +60,10 @@ I got a message that significantly reduced my options. } ``` -After that I went on a hunt again. I won't bother you with all the details -because hours/days went by until I was finally able to re-index the problematic -index and hoped for the best. Until that moment even re-indexing was giving -me errors. +After that I went on a hunt again. I won't bother you with all the details +because hours/days went by until I was finally able to re-index the problematic +index and hoped for the best. Until that moment even re-indexing was giving me +errors. ```yaml POST _reindex @@ -77,8 +77,8 @@ POST _reindex } ``` -I needed to do this multiple times to get all the documents re-indexed. Then -I dropped the original one with the following command. +I needed to do this multiple times to get all the documents re-indexed. Then I +dropped the original one with the following command. ```yaml DELETE /myindex @@ -98,10 +98,10 @@ POST _reindex } ``` -On the surface it looks like all is working but I have a long road in front -of me to get all the things working again. Cluster now shows that it is in -Green mode but I am also getting a notification that the cluster has -processing status which could mean million of things. +On the surface it looks like all is working but I have a long road in front of +me to get all the things working again. Cluster now shows that it is in Green +mode but I am also getting a notification that the cluster has processing status +which could mean million of things. Godspeed! diff --git a/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md b/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md index 47b95d5..daebb4c 100644 --- a/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md +++ b/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md @@ -5,96 +5,95 @@ date: 2020-03-30T12:00:00+02:00 draft: false --- -Previous project I was working on was being coded in [Golang](https://golang.org/). -Also was my first project using it. And damn, that was an awesome experience. -The whole thing is just superb. From how errors are handled. The C-like way -you handle compiling. The way the language is structured making it incredibly -versatile and easy to learn. - -It may cause some pain for somebody that is not used of using interfaces to map -JSON and doing the recompilation all the time. But we have tools like -[entr](http://eradman.com/entrproject/) and [make](https://www.gnu.org/software/make/) -to fix that. - -But we are not here to talk about my undying love for **Golang**. Only in some -way we probably should. It is an excellent example of how modern language -should be designed. And because I have used it extensively in the last couple -of years this probably taints my views of other languages. And is doing me a -great disservice. Nevertheless, here we are. - -About two years ago I started flirting with [Node.js](https://nodejs.org/en/) -for a project I started working on. What I wanted was to have things written -in a language that is widely used, and we could get additional developers for. -As much as **Golang** is amazing it's really hard to get developers for it. -Even now. And after playing around with it for a week I felt in love with the -speed of iteration and massive package ecosystem. Do you want SSO? You got it! -Do you want some esoteric library for something? There is a strong chance -somebody wrote it. It is so extensive that you find yourself evaluating -packages based on **GitHub stars** and number of contributors. You get -swallowed by the vanity metrics and that potentially will become the downfall -of Node.js. - -Because of the sheer amount of choice I often got anxiety when choosing -libraries. Will I choose the correct one? Is this library something that will -be supported for a foreseeable future or not? I am used of using libraries that -are being in development for 10 years plus (Python, C) and that gave me some -sort of comfort. And it is probably unfair to Node.js and community to expect -same dedication. - -Moving forward ... Work started and things were great. -**Speed of iteration was insane**. For some feature that I would need a day -in Golang only took me hour or two. I became lazy! Using packages all over -the place. Falling into the same trap as others. Packages on top of packages. -And [npm](https://www.npmjs.com/) didn't help at all. The way that the package -manager works is just horrendous. And not allowing to have node_modules outside -the project is also the stupidest idea ever. - -So at that point I started feeling the technical debt that comes with Node.js -and the whole ecosystem. What nobody tells you is that -**structuring large Node.js apps** is more problematic than one would think. -And going microservice for every single thing is also a bad idea. The amount -of networking you introduce with that approach always ends up being a pain in -the ass. And I don't even want to go into system administration here. The -overhead is insane. Package-lock.json made many days feel like living hell -for me. And I would eat the cost of all this if it meant for better development +Previous project I was working on was being coded in +[Golang](https://golang.org/). Also was my first project using it. And damn, +that was an awesome experience. The whole thing is just superb. From how errors +are handled. The C-like way you handle compiling. The way the language is +structured making it incredibly versatile and easy to learn. + +It may cause some pain for somebody that is not used of using interfaces to map +JSON and doing the recompilation all the time. But we have tools like +[entr](http://eradman.com/entrproject/) and +[make](https://www.gnu.org/software/make/) to fix that. + +But we are not here to talk about my undying love for **Golang**. Only in some +way we probably should. It is an excellent example of how modern language should +be designed. And because I have used it extensively in the last couple of years +this probably taints my views of other languages. And is doing me a great +disservice. Nevertheless, here we are. + +About two years ago I started flirting with [Node.js](https://nodejs.org/en/) +for a project I started working on. What I wanted was to have things written in +a language that is widely used, and we could get additional developers for. As +much as **Golang** is amazing it's really hard to get developers for it. Even +now. And after playing around with it for a week I felt in love with the speed +of iteration and massive package ecosystem. Do you want SSO? You got it! Do you +want some esoteric library for something? There is a strong chance somebody +wrote it. It is so extensive that you find yourself evaluating packages based on +**GitHub stars** and number of contributors. You get swallowed by the vanity +metrics and that potentially will become the downfall of Node.js. + +Because of the sheer amount of choice I often got anxiety when choosing +libraries. Will I choose the correct one? Is this library something that will be +supported for a foreseeable future or not? I am used of using libraries that are +being in development for 10 years plus (Python, C) and that gave me some sort of +comfort. And it is probably unfair to Node.js and community to expect same +dedication. + +Moving forward ... Work started and things were great. **Speed of iteration was +insane**. For some feature that I would need a day in Golang only took me hour +or two. I became lazy! Using packages all over the place. Falling into the same +trap as others. Packages on top of packages. And [npm](https://www.npmjs.com/) +didn't help at all. The way that the package manager works is just +horrendous. And not allowing to have node_modules outside the project is also +the stupidest idea ever. + +So at that point I started feeling the technical debt that comes with Node.js +and the whole ecosystem. What nobody tells you is that **structuring large +Node.js apps** is more problematic than one would think. And going microservice +for every single thing is also a bad idea. The amount of networking you +introduce with that approach always ends up being a pain in the ass. And I don't +even want to go into system administration here. The overhead is +insane. Package-lock.json made many days feel like living hell for me. And I +would eat the cost of all this if it meant for better development experience. Well, it didn't. -The **lack of Typescript** support in the interpreter is still mind boggling -to me. Why haven't they added native support yet for this is beyond me?! That -would have solved so many problems. Lack of type safety became a problem -somewhere in the middle of the project where the codebase was sufficiently -large enough to present problems. We started adding arguments to functions -and there was **no way to implicitly define argument types**. And because at -that point there were a lot of functions, it became impossible to know what -each one accepts, development became more and more trial and error based. - -I tried **implementing Typescript**, but that would present a large refactor -that we were not willing to do at that point. The benefits were not enough. -I also tried [Flow - static type checker](https://flow.org/) but implementation -was also horrible. What Typescript and Flow forces you is to have src folder -and then **transpile** your code into dist folder and run it with node. WTH is -that all about. Why can't this be done in memory or some virtual file system? -Why? I see no reason why this couldn't be done like this. But it is what it is. -I abandoned all hope for static type checking. - -One of the problems that resulted from not having interfaces or types was -inability to model out our data from **Elasticsearch**. I could have done -a **pedestrian implementation** of it, but there must be a better way of doing -this without resorting to some hack basically. Or maybe I haven't found a +The **lack of Typescript** support in the interpreter is still mind boggling to +me. Why haven't they added native support yet for this is beyond me?! That would +have solved so many problems. Lack of type safety became a problem somewhere in +the middle of the project where the codebase was sufficiently large enough to +present problems. We started adding arguments to functions and there was **no +way to implicitly define argument types**. And because at that point there were +a lot of functions, it became impossible to know what each one accepts, +development became more and more trial and error based. + +I tried **implementing Typescript**, but that would present a large refactor +that we were not willing to do at that point. The benefits were not enough. I +also tried [Flow - static type checker](https://flow.org/) but implementation +was also horrible. What Typescript and Flow forces you is to have src folder and +then **transpile** your code into dist folder and run it with node. WTH is that +all about. Why can't this be done in memory or some virtual file system? Why? I +see no reason why this couldn't be done like this. But it is what it is. I +abandoned all hope for static type checking. + +One of the problems that resulted from not having interfaces or types was +inability to model out our data from **Elasticsearch**. I could have done a +**pedestrian implementation** of it, but there must be a better way of doing +this without resorting to some hack basically. Or maybe I haven't found a solution, which is also a possibility. I have looked, though. No juice! **Error handling?** Is that a joke? -Thank god for **await/async**. Without it, I would have probably just abandoned -the whole thing and went with something else like Python. That's all I am -going to say about this :) +Thank god for **await/async**. Without it, I would have probably just abandoned +the whole thing and went with something else like Python. That's all I am going +to say about this :) -I started asking myself a question if Node.js is actually ready to be used in -a **large scale applications**? And this was a totally wrong question. What I -should have been asking myself was, how to use Node.js in large scale -application. And you don't get this in **marketing material** for Express or -Koa etc. They never tell you this. Making Node.js scale on infrastructure or -in codebase is really **more of an art than a science**. And just like with the +I started asking myself a question if Node.js is actually ready to be used in a +**large scale applications**? And this was a totally wrong question. What I +should have been asking myself was, how to use Node.js in large scale +application. And you don't get this in **marketing material** for Express or Koa +etc. They never tell you this. Making Node.js scale on infrastructure or in +codebase is really **more of an art than a science**. And just like with the whole JavaScript ecosystem: - impossible to master, @@ -103,10 +102,9 @@ whole JavaScript ecosystem: - error handling is a joke, - standards? What standards? -But on the other hand. As I did, you will also learn to love it. Learn to use -it quickly and do impossible things in crazy limited time. +But on the other hand. As I did, you will also learn to love it. Learn to use it +quickly and do impossible things in crazy limited time. I hate to admit it. But I love Node.js. Dammit, I love it :) 2023 Update: I hate Node.js! - diff --git a/content/posts/2020-05-05-remote-work.md b/content/posts/2020-05-05-remote-work.md index 54a7d1b..90fca24 100644 --- a/content/posts/2020-05-05-remote-work.md +++ b/content/posts/2020-05-05-remote-work.md @@ -5,29 +5,29 @@ date: 2020-05-05T12:00:00+02:00 draft: false --- -I have been working remotely for the past 5 years. I love it. Love the freedom +I have been working remotely for the past 5 years. I love it. Love the freedom and make your schedule thingy. ## You work more not less I've heard from people things like: "Oh, you are so lucky, working from home, -having all the free time you want". It was obvious they had no clue what means +having all the free time you want". It was obvious they had no clue what means working remotely. They had this romantic idea of remote work. You can watch TV -whenever you like, you can go outside for a picnic if you want and stuff like +whenever you like, you can go outside for a picnic if you want and stuff like that. -This may be true if you work a day or two in a week from home. But if you go -completely remote all these changes completely. I take some time to acclimate +This may be true if you work a day or two in a week from home. But if you go +completely remote all these changes completely. I take some time to acclimate but then you start feeling the consequences of going fully remote. And it's not all rainbows and unicorns. Rather the opposite. ## Feeling lost At first, I remembered I felt lost. I was not used to this kind of environment. -It felt disoriented and a part of you that is used to procrastinate turns on. +It felt disoriented and a part of you that is used to procrastinate turns on. You start thinking of a workday as a whole day. And soon this idea of "I can do -this later" starts creeping in. Well, I have the whole day ahead of me. I can -do this a bit later. +this later" starts creeping in. Well, I have the whole day ahead of me. I can do +this a bit later. ## Hyper-performance @@ -35,36 +35,37 @@ As a direct result, you become more focused on your work since you don't have all the interruptions common in the workplace. And you can quickly get used to this hyper-performance. But this mode requires also a lot of peace and quiet. -And here we come to the ugly parts of all this. **People rarely have the self-control** -to not waste other people's time. It is paralyzing when people start calling -you, sending you chat messages, etc. The thing is, that when I achieve this -hyper-performance mode I am completely embroiled in the problem I am solving -and this kind of interruptions mess with your head. I need an hour at least to -get back in the zone. Sometimes not achieving the same focus the whole day. +And here we come to the ugly parts of all this. **People rarely have the +self-control** to not waste other people's time. It is paralyzing when people +start calling you, sending you chat messages, etc. The thing is, that when I +achieve this hyper-performance mode I am completely embroiled in the problem I +am solving and this kind of interruptions mess with your head. I need an hour at +least to get back in the zone. Sometimes not achieving the same focus the whole +day. I know that life is not how you want it to be and takes its route but from what -I've learned this kind of interruptions can be avoided in 90% of the case -easily just by closing any chat programs and putting your phone in a drawer. +I've learned this kind of interruptions can be avoided in 90% of the case easily +just by closing any chat programs and putting your phone in a drawer. ## Suggestion to all the new remote workers -- Stop wasting other people's time. You don't bother people at their desks - in the office either. -- Do not replace daily chats in the hallways with instant messaging software. +- Stop wasting other people's time. You don't bother people at their desks in + the office either. +- Do not replace daily chats in the hallways with instant messaging software. It will only interrupt people. Nothing good will come of it. -- Set your working hours and try to not allow it to bleed outside these +- Set your working hours and try to not allow it to bleed outside these boundaries and maintain your routine. -- Be prepared that hours will be longer regardless of your good intentions - and your well thought of routine. -- Try to be hyper-focused and do only one thing at the time. Multitasking is - the enemy of progress. +- Be prepared that hours will be longer regardless of your good intentions and + your well thought of routine. +- Try to be hyper-focused and do only one thing at the time. Multitasking is the + enemy of progress. - Avoid long meetings and if possible eliminate them. Rather take time to write them out and allow others to respond in their own time. Meetings are usually a - large waste of time and most of the people attending them are there just + large waste of time and most of the people attending them are there just because the manager said so. -- The software will not solve your problems. And throwing money at problems neither. -- If you are in a managerial position don't supervise any single minute of - workers. They are probably giving you more hours anyways. Track progress +- The software will not solve your problems. And throwing money at problems + neither. +- If you are in a managerial position don't supervise any single minute of + workers. They are probably giving you more hours anyways. Track progress weekly not daily. You hired them and give them the benefit of the doubt that they will deliver what you agreed upon. - diff --git a/content/posts/2020-08-15-systemd-disable-wake-onmouse.md b/content/posts/2020-08-15-systemd-disable-wake-onmouse.md index fabdc32..55086b1 100644 --- a/content/posts/2020-08-15-systemd-disable-wake-onmouse.md +++ b/content/posts/2020-08-15-systemd-disable-wake-onmouse.md @@ -5,39 +5,41 @@ date: 2020-08-15T12:00:00+02:00 draft: false --- -I recently bought [ThinkPad X220](https://www.laptopmag.com/reviews/laptops/lenovo-thinkpad-x220) -just as a joke on eBay to test Linux distributions and play around with things -and not destroy my main machine. Little to my knowledge I felt in love with it. -Man, they really made awesome machines back then. +I recently bought [ThinkPad +X220](https://www.laptopmag.com/reviews/laptops/lenovo-thinkpad-x220) just as a +joke on eBay to test Linux distributions and play around with things and not +destroy my main machine. Little to my knowledge I felt in love with it. Man, +they really made awesome machines back then. After changing disk that came with it to SSD and installing Ubuntu to test if  -everything works I noticed that even after a single touch of my external mouse +everything works I noticed that even after a single touch of my external mouse the system would wake up from sleep even though the lid was shut down. -I wouldn't even noticed it if laptop didn't have -[LED sleep indicator](https://support.lenovo.com/lk/en/solutions/~/media/Images/ContentImages/p/pd025386_x1_status_03.ashx?w=426&h=262). -I already had a bad experience with Linux and it's power management. I had a -[Dell Inspiron 7537](https://www.pcmag.com/reviews/dell-inspiron-15-7537) laptop -with a touchscreen and while traveling it decided to wake up and started cooking +I wouldn't even noticed it if laptop didn't have [LED +sleep indicator](https://support.lenovo.com/lk/en/solutions/~/media/Images/ContentImages/p/pd025386_x1_status_03.ashx?w=426&h=262). +I already had a bad experience with Linux and it's power management. I had a +[Dell Inspiron 7537](https://www.pcmag.com/reviews/dell-inspiron-15-7537) laptop +with a touchscreen and while traveling it decided to wake up and started cooking in my backpack to the point that the digitizer responsible for touch actually glue off and the whole screen got wrecked. So, I am a bit touchy about this. -I went on solution hunting and to my surprise there is no easy way to disable +I went on solution hunting and to my surprise there is no easy way to disable specific devices to perform wake up. Why is this not under the power management  tab in setting is really strange. -After googling for a solution I found [this nice article describing the solution](https://codetrips.com/2020/03/18/ubuntu-disable-mouse-wake-from-suspend/) -that worked for me. The only problem with this solution was that he added his -solution to `.bashrc` and this triggers `sudo` that asks for a password each -time new terminal is opened, which get annoying quickly since I open a lot of +After googling for a solution I found [this nice article describing the +solution](https://codetrips.com/2020/03/18/ubuntu-disable-mouse-wake-from-suspend/) +that worked for me. The only problem with this solution was that he added his +solution to `.bashrc` and this triggers `sudo` that asks for a password each +time new terminal is opened, which get annoying quickly since I open a lot of terminals all the time. -I followed his instructions and got to solution -`sudo sh -c "echo 'disabled' > /sys/bus/usb/devices/2-1.1/power/wakeup"`. +I followed his instructions and got to solution `sudo sh -c "echo 'disabled' > +/sys/bus/usb/devices/2-1.1/power/wakeup"`. -I created a system service file `sudo nano /etc/systemd/system/disable-mouse-wakeup.service` -and removed `sudo` and replaced `sh` with `/usr/bin/sh` and pasted all that -in `ExecStart`. +I created a system service file `sudo nano +/etc/systemd/system/disable-mouse-wakeup.service` and removed `sudo` and +replaced `sh` with `/usr/bin/sh` and pasted all that in `ExecStart`. ```ini [Unit] @@ -68,4 +70,3 @@ This will permanently disable that device from wakeing up you computer on boot. If you have many devices you would like to surpress from waking up your machine I would create a shell script and call that instead of direclty doing it in service file. - diff --git a/content/posts/2020-09-06-esp-and-micropython.md b/content/posts/2020-09-06-esp-and-micropython.md index ac79a6d..91a04ad 100644 --- a/content/posts/2020-09-06-esp-and-micropython.md +++ b/content/posts/2020-09-06-esp-and-micropython.md @@ -7,14 +7,16 @@ draft: false ## Introduction -A while ago I bought some [ESP8266](https://www.espressif.com/en/products/socs/esp8266) -and [ESP32](https://www.espressif.com/en/products/socs/esp32) dev boards to -play around with and I finally found a project to try it out. +A while ago I bought some +[ESP8266](https://www.espressif.com/en/products/socs/esp8266) and +[ESP32](https://www.espressif.com/en/products/socs/esp32) dev boards to play +around with and I finally found a project to try it out. -For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32) -but I could easily choose [ESP8266](https://www.espressif.com/en/products/socs/esp8266). -This guide contains which tools I use and how I prepared my workspace to code -for [ESP8266](https://www.espressif.com/en/products/socs/esp8266). +For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32) +but I could easily choose +[ESP8266](https://www.espressif.com/en/products/socs/esp8266). This guide +contains which tools I use and how I prepared my workspace to code for +[ESP8266](https://www.espressif.com/en/products/socs/esp8266). ![ESP8266 and ESP32 boards](/assets/esp8366-micropython/boards.jpg) @@ -29,16 +31,18 @@ mine and once I replaced it everything started to work. ## Flashing the SOC -Plug your ESP8266 to USB port and check if the device was recognized with +Plug your ESP8266 to USB port and check if the device was recognized with executing `dmesg | grep ch341-uart`. -Then check if the device is available under `/dev/` by running `ls /dev/ttyUSB*`. +Then check if the device is available under `/dev/` by running `ls +/dev/ttyUSB*`. > **Linux users**: if a device is not available be sure you are in `dialout` > group. You can check this by executing `groups $USER`. You can add a user to > `dialout` group with `sudo adduser $USER dialout`. -After these conditions are meet go to the navigate to [https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/) +After these conditions are meet go to the navigate to +[https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/) and download `esp8266-20200902-v1.13.bin`. ```sh @@ -48,14 +52,15 @@ cd esp8266-test wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin ``` -After obtaining firmware we will need some tooling to flash the firmware to -the board. +After obtaining firmware we will need some tooling to flash the firmware to the +board. ```sh sudo pip3 install esptool ``` -You can read more about `esptool` at [https://github.com/espressif/esptool/](https://github.com/espressif/esptool/). +You can read more about `esptool` at +[https://github.com/espressif/esptool/](https://github.com/espressif/esptool/). Before flashing the firmware we need to erase the flash on device. Substitute `USB0` with the device listed in output of `ls /dev/ttyUSB*`. @@ -70,8 +75,8 @@ If flash was successfully erased it is now time to flash the new firmware to it. esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin ``` -If everything went ok you can try accessing MicroPython REPL with ` -screen /dev/ttyUSB0 115200` or `picocom /dev/ttyUSB0 -b115200`. +If everything went ok you can try accessing MicroPython REPL with ` screen +/dev/ttyUSB0 115200` or `picocom /dev/ttyUSB0 -b115200`. > Sometimes you will need to press `ENTER` in `screen` or `picocom` to access > REPL. @@ -83,7 +88,7 @@ When you are in REPL you can test if all is working properly following steps. > machine.freq() ``` -This should output a number representing a frequency of the CPU (mine was +This should output a number representing a frequency of the CPU (mine was `80000000`). When you are in `screen` or `picocom` these can help you a bit. @@ -130,7 +135,7 @@ ampy --delay 2 --port /dev/ttyUSB0 cat boot.py ### rshell -Even though `ampy` is a cool tool I opted with `rshell` in the end since it's +Even though `ampy` is a cool tool I opted with `rshell` in the end since it's much more polished and feature rich. ```bash @@ -144,9 +149,9 @@ Now that `rshell` is installed we can connect to the board. rshell --buffer-size=30 -p /dev/ttyUSB0 -a ``` -This will open a shell inside bash and from here you can execute multiple -commands. You can check what is supported with `help` once you are inside of -a shell. +This will open a shell inside bash and from here you can execute multiple +commands. You can check what is supported with `help` once you are inside of a +shell. ```bash m@turing ~/Junk/esp8266-test @@ -177,8 +182,8 @@ Use Control-D (or the exit command) to exit rshell. #### Moving files to flash -To avoid copying files all the time I used `rsync` function from the -inside of `rshell`. +To avoid copying files all the time I used `rsync` function from the inside of +`rshell`. ```bash rsync . /pyboard @@ -186,11 +191,11 @@ rsync . /pyboard #### Executing scripts -It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` -and there is a better way of testing local scripts on remote device. +It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` and +there is a better way of testing local scripts on remote device. -Lets assume we have `src/freq.py` file that displays CPU frequency of a -remote device. +Lets assume we have `src/freq.py` file that displays CPU frequency of a remote +device. ```py # src/freq.py @@ -218,4 +223,3 @@ repl - https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/ - http://docs.micropython.org/en/latest/esp8266/quickref.html - diff --git a/content/posts/2020-09-08-bind-warning-on-login.md b/content/posts/2020-09-08-bind-warning-on-login.md index d5d725e..113c67b 100644 --- a/content/posts/2020-09-08-bind-warning-on-login.md +++ b/content/posts/2020-09-08-bind-warning-on-login.md @@ -5,19 +5,18 @@ date: 2020-09-08T12:00:00+02:00 draft: false --- -Recently I moved back to [bash](https://www.gnu.org/software/bash/) as my -default shell. I was previously using [fish](https://fishshell.com/) and got -used to the cool features it has. But, regardless of that, I wanted to move to -a more standard shell because I was hopping back and forth with exporting +Recently I moved back to [bash](https://www.gnu.org/software/bash/) as my +default shell. I was previously using [fish](https://fishshell.com/) and got +used to the cool features it has. But, regardless of that, I wanted to move to a +more standard shell because I was hopping back and forth with exporting variables and stuff like that which got pretty annoying. -So I embarked on a mission to make [bash](https://www.gnu.org/software/bash/) +So I embarked on a mission to make [bash](https://www.gnu.org/software/bash/) more like [fish](https://fishshell.com/) and in the process found that I really missed autosuggest with TAB on changing directories. -I found a nice alternative that emulates [zsh](http://zsh.sourceforge.net/) -like autosuggestion and autocomplete so I added the following to my `.bashrc` -file. +I found a nice alternative that emulates [zsh](http://zsh.sourceforge.net/) like +autosuggestion and autocomplete so I added the following to my `.bashrc` file. ```bash bind "TAB:menu-complete" @@ -27,15 +26,16 @@ bind "set menu-complete-display-prefix on" bind '"\e[Z":menu-complete-backward' ``` -I haven't noticed anything wrong with this and all was working fine until I +I haven't noticed anything wrong with this and all was working fine until I restarted my machine and then I got this error. ![Profile bind error](/assets/profile-bind-error/error.jpg) -When I pressed OK, I got into the [Gnome shell](https://wiki.gnome.org/Projects/GnomeShell) -and all was working fine, but the error was still bugging me. I started looking -for the reason why this is happening and found a solution to this error on -[Remote SSH Commands - bash bind warning: line editing not enabled](https://superuser.com/a/892682). +When I pressed OK, I got into the [Gnome +shell](https://wiki.gnome.org/Projects/GnomeShell) and all was working fine, but +the error was still bugging me. I started looking for the reason why this is +happening and found a solution to this error on [Remote SSH Commands - bash bind +warning: line editing not enabled](https://superuser.com/a/892682). So I added a simple `if [ -t 1 ]` around `bind` statements to avoid running commands that presume the session is interactive when it isn't. @@ -51,4 +51,3 @@ fi ``` After logging out and back in the problem was gone. - diff --git a/content/posts/2020-09-09-digitalocean-sync.md b/content/posts/2020-09-09-digitalocean-sync.md index 2eeea2e..aa3cce4 100644 --- a/content/posts/2020-09-09-digitalocean-sync.md +++ b/content/posts/2020-09-09-digitalocean-sync.md @@ -5,25 +5,25 @@ date: 2020-09-09T12:00:00+02:00 draft: false --- -I've been using [Dropbox](https://www.dropbox.com/) for probably **10+ years** -now and I-ve became so used to it that it runs in the background that I don't +I've been using [Dropbox](https://www.dropbox.com/) for probably **10+ years** +now and I-ve became so used to it that it runs in the background that I don't even imagine a world without it. But it's not without problems. -At first I had problems with `.venv` environments for Python and the only -solution for excluding synchronization for this folder was to manually exclude -a specific folder which is not really scalable. FYI, my whole project folder is -synced on [Dropbox](https://www.dropbox.com/). This of course introduced a lot -of syncing of files and folders that are not needed or even break things on -other machines. In the case of **Python**, I couldn't use that on my second -machine. I needed to delete `.venv` folder and pip it again which synced files +At first I had problems with `.venv` environments for Python and the only +solution for excluding synchronization for this folder was to manually exclude a +specific folder which is not really scalable. FYI, my whole project folder is +synced on [Dropbox](https://www.dropbox.com/). This of course introduced a lot +of syncing of files and folders that are not needed or even break things on +other machines. In the case of **Python**, I couldn't use that on my second +machine. I needed to delete `.venv` folder and pip it again which synced files again to the main machine. This was very frustrating. **Nodejs** handles this much nicer and I can just run the scripts without deleting `node_modules` again and reinstalling. However, `node_modules` is a beast of its own. It creates so -many files that OS has a problem counting them when you check the folder +many files that OS has a problem counting them when you check the folder contents for size. -I wanted something similar to Dropbox. I could without the instant syncing -but it would need to be fast and had the option for me to exclude folders like +I wanted something similar to Dropbox. I could without the instant syncing but +it would need to be fast and had the option for me to exclude folders like `node_modules, .venv, .git` and folders like that. I went on a hunt for an alternative to [Dropbox](https://www.dropbox.com/) @@ -33,48 +33,51 @@ and found: - [Sync.com](https://sync.com) - [Box](https://www.box.com/) -You know, the usual list of suspects. I didn't include [Google drive](https://drive.google.com) -or [One drive](https://onedrive.live.com/) since they are even more draconian -than Dropbox. +You know, the usual list of suspects. I didn't include [Google +drive](https://drive.google.com) or [One drive](https://onedrive.live.com/) +since they are even more draconian than Dropbox. > All this does not stem from me being paranoid but recently these companies > have became more and more aggressive and they keep violating our privacy when > they share our data with 3rd party services. It is getting out of control. -So, my main problem was still there. No way of excluding a specific folder -from syncing. And before we go into "*But you have git, isn't that enough?*", -I must say, that many of the files (PDFs, spreadsheets, etc) I have in a `git` -repo don't get pushed upstream to Git and I still want to have them synced -across my computers. +So, my main problem was still there. No way of excluding a specific folder from +syncing. And before we go into "*But you have git, isn't that enough?*", I must +say, that many of the files (PDFs, spreadsheets, etc) I have in a `git` repo +don't get pushed upstream to Git and I still want to have them synced across my +computers. -I initially wanted to use [rsync](https://linux.die.net/man/1/rsync) but I -would need to then have a remote VPS or transfer between my computers directly. -I wanted a solution where all my files could be accessible to me without my +I initially wanted to use [rsync](https://linux.die.net/man/1/rsync) but I would +need to then have a remote VPS or transfer between my computers directly. I +wanted a solution where all my files could be accessible to me without my machine. -> **WARNING: This solution will cost you money!** DigitalOcean Spaces are $5 -per month and there are some bandwidth limitations and if you go beyond that -you get billed additionally. +> **WARNING: This solution will cost you money!** DigitalOcean Spaces are $5 per +month and there are some bandwidth limitations and if you go beyond that you get +billed additionally. -Then I remembered that I could use something like [S3](https://en.wikipedia.org/wiki/Amazon_S3) -since it has versioning and is fully managed. I didn't want to go down the AWS -rabbit hole with this so I choose [DigitalOcean Spaces](https://www.digitalocean.com/products/spaces/). +Then I remembered that I could use something like +[S3](https://en.wikipedia.org/wiki/Amazon_S3) since it has versioning and is +fully managed. I didn't want to go down the AWS rabbit hole with this so I +choose [DigitalOcean Spaces](https://www.digitalocean.com/products/spaces/). -Then I needed a command-line tool to sync between source and target. I found -this nice tool [s3cmd](https://s3tools.org/s3cmd) and it is in the Ubuntu +Then I needed a command-line tool to sync between source and target. I found +this nice tool [s3cmd](https://s3tools.org/s3cmd) and it is in the Ubuntu repositories. ```bash sudo apt install s3cmd ``` -After installation will I create a new Space bucket on DigitalOcean. Remember -the zone you will choose because you will need it when you will configure `s3cmd`. +After installation will I create a new Space bucket on DigitalOcean. Remember +the zone you will choose because you will need it when you will configure +`s3cmd`. -Then I visited [Digitalocean Applications & API](https://cloud.digitalocean.com/account/api/tokens) -and generated **Spaces access keys**. Save both key and secret somewhere safe -because when you will leave the page secret will not be available anymore to -you and you will need to re-generate it. +Then I visited [Digitalocean Applications & +API](https://cloud.digitalocean.com/account/api/tokens) and generated **Spaces +access keys**. Save both key and secret somewhere safe because when you will +leave the page secret will not be available anymore to you and you will need to +re-generate it. ```bash # enter your key and secret and correct endpoint @@ -101,10 +104,8 @@ When syncing int he other direction you will need to change the order of the I am planning to implement some sort of a `.ignore` file that will enable me to have a project-specific exclude options. -I am currently running this every hour as a cronjob which is perfectly fine -for now when I am testing how this whole thing works and how it all will turn -out. +I am currently running this every hour as a cronjob which is perfectly fine for +now when I am testing how this whole thing works and how it all will turn out. I have also created a small Gnome extension which is still very unstable, but when/if this whole experiment pays of I will share on Github. - diff --git a/content/posts/2021-01-24-replacing-dropbox-with-s3.md b/content/posts/2021-01-24-replacing-dropbox-with-s3.md index 0253368..4c6b33e 100644 --- a/content/posts/2021-01-24-replacing-dropbox-with-s3.md +++ b/content/posts/2021-01-24-replacing-dropbox-with-s3.md @@ -5,27 +5,30 @@ date: 2021-01-24T12:00:00+02:00 draft: false --- -A few months ago I experimented with DigitalOcean spaces as my backup solution -that could [replace Dropbox eventually](/digitalocean-spaces-to-sync-between-computers.html). -That solution worked quite nicely, and I was amazed how smashing together a -couple of existing solutions would work this fine. - -I have been running that solution in the background for a couple of months now -and kind of forgot about it. But recent developments around deplatforming and -having us people hostages of technology and big companies speed up my goals to -become less dependent on [Google](https://edition.cnn.com/2020/12/17/tech/google-antitrust-lawsuit/index.html), -[Dropbox](https://www.pcworld.com/article/2048680/dropbox-takes-a-peek-at-files.html) +A few months ago I experimented with DigitalOcean spaces as my backup solution +that could [replace Dropbox +eventually](/digitalocean-spaces-to-sync-between-computers.html). That solution +worked quite nicely, and I was amazed how smashing together a couple of existing +solutions would work this fine. + +I have been running that solution in the background for a couple of months now +and kind of forgot about it. But recent developments around deplatforming and +having us people hostages of technology and big companies speed up my goals to +become less dependent on +[Google](https://edition.cnn.com/2020/12/17/tech/google-antitrust-lawsuit/index.html), +[Dropbox](https://www.pcworld.com/article/2048680/dropbox-takes-a-peek-at-files.html) etc and take back some control. -I am not a conspiracy theory nut, but to be honest, what these companies are -doing lately is out of control. It is a matter of principle at this point. I -have almost completely degoogled my life all the way from ditching Gmail, -YouTube and most of the services surrounding Google. And I must tell you, I -feel so good. I haven't felt this way for a long time. +I am not a conspiracy theory nut, but to be honest, what these companies are +doing lately is out of control. It is a matter of principle at this point. I +have almost completely degoogled my life all the way from ditching Gmail, +YouTube and most of the services surrounding Google. And I must tell you, I feel +so good. I haven't felt this way for a long time. **Anyways. Let's get to the meat of things.** -Before you continue you should read my post about [syncing to Dropbox](/digitalocean-spaces-to-sync-between-computers.html). +Before you continue you should read my post about [syncing to +Dropbox](/digitalocean-spaces-to-sync-between-computers.html). > Also to note, I am using Linux on my machine with Gnome desktop environment. This should work on MacOS too. To use this on Windows I suggest using @@ -34,7 +37,7 @@ or [Cygwin](https://www.cygwin.com/). ## Folder structure -I liked structure from Dropbox. One folder where everything is located and +I liked structure from Dropbox. One folder where everything is located and synced. So, that's why adopted this also for my sync setup. ```go @@ -45,11 +48,10 @@ synced. So, that's why adopted this also for my sync setup. ↳ projects ``` -All of my code is located in `~/Vault/projects` folder. And most of the -projects are Git repositories. I do not use this sync method for backup per -see but in case I reinstall my machine I can easily recreate all the important -folder structure with one quick command. No external drives needed that can -fail etc. +All of my code is located in `~/Vault/projects` folder. And most of the projects +are Git repositories. I do not use this sync method for backup per see but in +case I reinstall my machine I can easily recreate all the important folder +structure with one quick command. No external drives needed that can fail etc. ## Sync script @@ -86,8 +88,8 @@ notify-send \ "Vault sync succeded at `date +"%D %T"`" ``` -This script also backups some of the dotfiles I use and sends notification to -Gnome notification center. It is a straightforward solution. Nothing special +This script also backups some of the dotfiles I use and sends notification to +Gnome notification center. It is a straightforward solution. Nothing special going on. > One obvious benefit of this is that I can omit syncing Node's `node_modules` @@ -99,14 +101,13 @@ You can use this script in a combination with [Cron](https://en.wikipedia.org/wi 0 2 * * * sh ~/Vault/bin/vault-backup.sh ``` -When you start syncing your local stuff with a remote server you can review -your items on DigitalOcean. +When you start syncing your local stuff with a remote server you can review your +items on DigitalOcean. ![Dropbox Spaces](/assets/dropbox-sync/dropbox-spaces.png) -I have been using this script now for quite some time, and it's working +I have been using this script now for quite some time, and it's working flawlessly. I also uninstalled Dropbox and stopped using it completely. -All I need to do is write a Bash script that does the reverse and downloads -from remote server to local folder. This could be another post. - +All I need to do is write a Bash script that does the reverse and downloads from +remote server to local folder. This could be another post. diff --git a/content/posts/2021-01-25-goaccess.md b/content/posts/2021-01-25-goaccess.md index efbd175..1b6a330 100644 --- a/content/posts/2021-01-25-goaccess.md +++ b/content/posts/2021-01-25-goaccess.md @@ -7,16 +7,16 @@ draft: false ## Introduction -I know! You cannot simply replace Google Analytics with parsing access logs and -displaying a couple of charts. But to be honest, I actually never used Google -Analytics to the fullest extent and was usually interested in seeing page -hits and which pages were visited most often. +I know! You cannot simply replace Google Analytics with parsing access logs and +displaying a couple of charts. But to be honest, I actually never used Google +Analytics to the fullest extent and was usually interested in seeing page hits +and which pages were visited most often. -I recently moved my blog from Firebase to a VPS and also decided to remove -Google Analytics tracking code from the site since its quite malicious and -tracks users across other pages also and is creating a profile of a user, and -I've had it. But I also need some insight of what is happening on a server -and which content is being read the most etc. +I recently moved my blog from Firebase to a VPS and also decided to remove +Google Analytics tracking code from the site since its quite malicious and +tracks users across other pages also and is creating a profile of a user, and +I've had it. But I also need some insight of what is happening on a server and +which content is being read the most etc. I have looked at many existing solutions like: @@ -24,18 +24,18 @@ I have looked at many existing solutions like: - [Freshlytics](https://github.com/sheshbabu/freshlytics) - [Matomo](https://matomo.org/) -But the more I looked at them the more I noticed that I am replacing one evil -with another one. Don't get me wrong. Some of these solutions are absolutely -fantastic but would require installation of databases and something like PHP -or Node. And I was not ready to put those things on my fresh server. Also -having Docker installed is out of the question. +But the more I looked at them the more I noticed that I am replacing one evil +with another one. Don't get me wrong. Some of these solutions are absolutely +fantastic but would require installation of databases and something like PHP or +Node. And I was not ready to put those things on my fresh server. Also having +Docker installed is out of the question. ## Opting for log parsing -So, I defaulted to parsing already existing logs and generating HTML reports +So, I defaulted to parsing already existing logs and generating HTML reports from this data. -I found this amazing software [GoAccess](https://goaccess.io/) which provides +I found this amazing software [GoAccess](https://goaccess.io/) which provides all the functionalities I need, and it's a single binary. Written in Go. GoAccess can be used in two different modes. @@ -46,15 +46,16 @@ GoAccess can be used in two different modes. ![GoAccess HTML](/assets/goaccess/goaccess-dash-html.png)
Running in a browser
-I, however, need this to run in a browser. So, the second option is the way -to go. The Idea is to periodically run cronjob and export this report into a -folder that gets then server by Nginx behind a Basic authentication. +I, however, need this to run in a browser. So, the second option is the way to +go. The Idea is to periodically run cronjob and export this report into a folder +that gets then server by Nginx behind a Basic authentication. ## Getting Nginx ready -I choose Ubuntu on [DigitalOcean](https://www.digitalocean.com/). First I -installed [Nginx](https://nginx.org/en/), and [Letsencrypt](https://letsencrypt.org/getting-started/) -certbot and all the necessary dependencies. +I choose Ubuntu on [DigitalOcean](https://www.digitalocean.com/). First I +installed [Nginx](https://nginx.org/en/), and +[Letsencrypt](https://letsencrypt.org/getting-started/) certbot and all the +necessary dependencies. ```sh # log in as root user @@ -90,26 +91,25 @@ server { } ``` -Now we check if the configuration is ok. We can do this with `nginx -t`. If -all is ok, we can restart Nginx with `service nginx restart`. +Now we check if the configuration is ok. We can do this with `nginx -t`. If all +is ok, we can restart Nginx with `service nginx restart`. -After all that you should add A record for this domain that points to IP of -a droplet. +After all that you should add A record for this domain that points to IP of a +droplet. -Before enabling SSL you should test if DNS records have propagated with -`curl stats.domain.com`. +Before enabling SSL you should test if DNS records have propagated with `curl +stats.domain.com`. -Now, it's time to provision TLS certificate. To achieve this, you execute command -`certbot --nginx`. Follow the wizard and when you are asked about redirection -always choose 2 (always redirect to HTTPS). +Now, it's time to provision TLS certificate. To achieve this, you execute +command `certbot --nginx`. Follow the wizard and when you are asked about +redirection always choose 2 (always redirect to HTTPS). -When this is done you can visit https://stats.domain.com and you should get 404 +When this is done you can visit https://stats.domain.com and you should get 404 not found error which is correct. - ## Getting GoAccess ready -If you are using Debian like system GoAccess should be available in repository. +If you are using Debian like system GoAccess should be available in repository. Otherwise refer to the official website. ```sh @@ -148,19 +148,19 @@ goaccess \ rm /var/log/nginx/access-all.log ``` -Because after a while nginx creates multiple files with access logs we use -[`zcat`](https://linux.die.net/man/1/zcat) to extract Gziped contents and -create a file that has all the access logs. After this file is used we -delete it. +Because after a while nginx creates multiple files with access logs we use +[`zcat`](https://linux.die.net/man/1/zcat) to extract Gziped contents and create +a file that has all the access logs. After this file is used we delete it. -If you want to exclude your home IP's result look at the `--exclude-ip` option -in script and instead of `0.0.0.0` add your own home IP address. You can find -your home IP by executing `curl ifconfig.me` from your local machine and NOT +If you want to exclude your home IP's result look at the `--exclude-ip` option +in script and instead of `0.0.0.0` add your own home IP address. You can find +your home IP by executing `curl ifconfig.me` from your local machine and NOT from the droplet. -Test the script by executing `sh /var/www/html/stats.domain.com/generate-stats.sh` -and then checking `https://stats.domain.com`. If you can see stats instead of -404 than you are set. +Test the script by executing `sh +/var/www/html/stats.domain.com/generate-stats.sh` and then checking +`https://stats.domain.com`. If you can see stats instead of 404 than you are +set. It's time to add this script to cron with `cron -e`. @@ -170,16 +170,17 @@ It's time to add this script to cron with `cron -e`. ## Securing with Basic authentication -You probably don't want stats to be publicly available, so we should create a +You probably don't want stats to be publicly available, so we should create a user and a password for Basic authentication. First we create a password for a user `stats` with `htpasswd -c /etc/nginx/.htpasswd stats`. -Now we update config file with `nano /etc/nginx/sites-available/stats.domain.com`. -You probably noticed that the file looks a bit different from before. This is -because `certbot` added additional rules for SSL. +Now we update config file with `nano +/etc/nginx/sites-available/stats.domain.com`. You probably noticed that the +file looks a bit different from before. This is because `certbot` added +additional rules for SSL. -Your location portion the config file should now look like. You should add +Your location portion the config file should now look like. You should add `auth_basic` and `auth_basic_user_file` lines to the file. ```nginx @@ -190,12 +191,12 @@ location / { } ``` -Test if config is still ok with `nginx -t` and if it is you can restart -Nginx with `service nginx restart`. +Test if config is still ok with `nginx -t` and if it is you can restart Nginx +with `service nginx restart`. -If you now visit `https://stats.domain.com` you should be prompted for username +If you now visit `https://stats.domain.com` you should be prompted for username and password. If not, try reopening your browser. -That is all. You now have analytics for your server that gets refreshed every -10 minutes. +That is all. You now have analytics for your server that gets refreshed every 10 +minutes. diff --git a/content/posts/2021-06-26-simple-world-clock.md b/content/posts/2021-06-26-simple-world-clock.md index f42af11..ed248dd 100644 --- a/content/posts/2021-06-26-simple-world-clock.md +++ b/content/posts/2021-06-26-simple-world-clock.md @@ -5,29 +5,32 @@ date: 2021-06-26T12:00:00+02:00 draft: false --- -Our team is spread across the world, from the USA all the way to Australia, -so having some sort of world clock makes sense. +Our team is spread across the world, from the USA all the way to Australia, so +having some sort of world clock makes sense. -Currently, I am using an extension for Gnome called -[Timezone extension](https://extensions.gnome.org/extension/2657/timezones-extension/), +Currently, I am using an extension for Gnome called [Timezone +extension](https://extensions.gnome.org/extension/2657/timezones-extension/), and it serves the purpose quite well. -But I also have a bunch of electronics that I bought through the time, and I -am not using any of them, and it's time to stop hording this stuff and use it -in a project. +But I also have a bunch of electronics that I bought through the time, and I am +not using any of them, and it's time to stop hording this stuff and use it in a +project. -A while ago I bought a small eInk display -[Inky pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) -and I have a bunch of [Raspberry Pi's Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) -lying around that I really need to use. +A while ago I bought a small eInk display [Inky +pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) and I +have a bunch of [Raspberry Pi's +Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) lying around that +I really need to use. ![Inky pHAT, Raspberry Pi Zero](/assets/world-clock/hardware.jpg) -Since the Inky [Inky pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) -is essentially a HAT, it can easily be added on top of the -[Raspberry Pi Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/). +Since the Inky [Inky +pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) is +essentially a HAT, it can easily be added on top of the [Raspberry Pi +Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/). -First, I installed the necessary software on Raspberry Pi with `pip3 install inky`. +First, I installed the necessary software on Raspberry Pi with `pip3 install +inky`. And then I created a file `clock.py` in home directory `/home/pi`. @@ -76,10 +79,11 @@ board.set_image(img) board.show() ``` -And because eInk displays are rather slow to refresh and the clock requires +And because eInk displays are rather slow to refresh and the clock requires refreshing only once a minute, this can be done through cronjob. -Before we add this job to cron we need to make `clock.py` executable with `chmod +x clock.py`. +Before we add this job to cron we need to make `clock.py` executable with `chmod ++x clock.py`. Then we add a cronjob with `crontab -e`. @@ -91,13 +95,13 @@ So, we end up with a result like this. ![World Clock](/assets/world-clock/world-clock.jpg) -And for the enclosure that can be 3D printed, but I haven't yet something like +And for the enclosure that can be 3D printed, but I haven't yet something like this can be used. -You can download my [STL file for the enclosure here](/assets/world-clock/enclosure.stl), -but make sure that dimensions make sense and also opening for USB port should -be added or just use a drill and some hot glue to make it stick in the -enclosure. +You can download my [STL file for the enclosure +here](/assets/world-clock/enclosure.stl), but make sure that dimensions make +sense and also opening for USB port should be added or just use a drill and some +hot glue to make it stick in the enclosure. diff --git a/content/posts/2021-07-30-from-internet-consumer-to-full-hominum-again.md b/content/posts/2021-07-30-from-internet-consumer-to-full-hominum-again.md index 27e0905..31a2ea0 100644 --- a/content/posts/2021-07-30-from-internet-consumer-to-full-hominum-again.md +++ b/content/posts/2021-07-30-from-internet-consumer-to-full-hominum-again.md @@ -12,93 +12,91 @@ I was pleasantly surprised that the transition went so smoothly. Even better, it brought many benefits to my life. Such as increased focus, less stress about trivial things, etc. -It all started with me doing small changes like unsubscribing from emails that -I have either subscribed to by accepting terms and conditions. Or even some -more malicious emails that I was getting because I was on a shared mailing -list. And the later ones I hate the most of all. How the hell do they keep -sharing my email and sending me unsolicited emails and get away with it? I -have a suspicion that these marketing people share an Excel file between them -and keep resubscribing me when they import lists into Mailchimp or similar -software. +It all started with me doing small changes like unsubscribing from emails that I +have either subscribed to by accepting terms and conditions. Or even some more +malicious emails that I was getting because I was on a shared mailing list. And +the later ones I hate the most of all. How the hell do they keep sharing my +email and sending me unsolicited emails and get away with it? I have a suspicion +that these marketing people share an Excel file between them and keep +resubscribing me when they import lists into Mailchimp or similar software. It's fascinating to see how much crap you get subscribed to when you are not -paying attention. It got so bad that my primary Gmail address is a full of junk +paying attention. It got so bad that my primary Gmail address is a full of junk and need constant monitoring and cleaning up. And because I want to have Inbox Zero, this presents an additional problem for me. -The stress that email presented for me didn't occur to me for a long time. I -was noticing that I was unable to go through one single hour without -hysterically refreshing email. And if somebody wrote me something, I needed -to see it right then, even though I didn't immediately reply to it. I can -only describe this with FOMO (fear of missing out). I have no other explanation -than that. It was crippling, and I was constantly context switching, which I -will address further down this post in more details. +The stress that email presented for me didn't occur to me for a long time. I was +noticing that I was unable to go through one single hour without hysterically +refreshing email. And if somebody wrote me something, I needed to see it right +then, even though I didn't immediately reply to it. I can only describe this +with FOMO (fear of missing out). I have no other explanation than that. It was +crippling, and I was constantly context switching, which I will address further +down this post in more details. -This was one of the reasons why I spawned up my personal email server, and I -am using it now as my primary and person email. I still have Gmail as my “junk” -email that I use for throw away stuff. I log in to Gmail once a week and check -if there are any important emails that I got, but apart from that, it's -sitting dormant and collecting dust. +This was one of the reasons why I spawned up my personal email server, and I am +using it now as my primary and person email. I still have Gmail as my “junk” +email that I use for throw away stuff. I log in to Gmail once a week and check +if there are any important emails that I got, but apart from that, it's sitting +dormant and collecting dust. -The more I was watching the world loose it's self with allowing anti freedom -things to happen to it, the more I started to realize that something has to -change. I don't have the power to change the world. And I also don't have a -grandiose opinion of myself to even think to try it. But what I can do is to -not subscribe to this consumer way of thinking. I will not be complicit in -this. My moral and ethical stances won't allow it. So, this brings us to the -second part of my journey. +The more I was watching the world loose it's self with allowing anti freedom +things to happen to it, the more I started to realize that something has to +change. I don't have the power to change the world. And I also don't have a +grandiose opinion of myself to even think to try it. But what I can do is to not +subscribe to this consumer way of thinking. I will not be complicit in this. My +moral and ethical stances won't allow it. So, this brings us to the second part +of my journey. -I was using all these 3rd party services because I was either lazy or OK with +I was using all these 3rd party services because I was either lazy or OK with the drawbacks of them. I watched these services and companies became more and -more evil. It is evil if you sell your user's data in this manner. Nobody reads privacy policies and everybody is OK with accepting them, and they pray on that +more evil. It is evil if you sell your user's data in this manner. Nobody reads flaw in human nature. I really hate the hypocrisy they manage to muster. These -companies prey on our laziness, and we are at fault here. Nobody else. And I -truly understand the reasons why we rather accept and move on, and not object -and have our lives a little more difficult. They have perfected this through +companies prey on our laziness, and we are at fault here. Nobody else. And I +truly understand the reasons why we rather accept and move on, and not object +and have our lives a little more difficult. They have perfected this through years of small changes that make us a little more dependent on them. You could -not convince a person to give away all his rights and data in one day. This was -gradual and slow. And it caught us all in surprise. When I really stopped and -thought about it, I felt repulsed. By really stopping and thinking about it, -I really mean stopping and thinking about it. Thoroughly and in depth. +not convince a person to give away all his rights and data in one day. This was +gradual and slow. And it caught us all in surprise. When I really stopped and +thought about it, I felt repulsed. By really stopping and thinking about it, I +really mean stopping and thinking about it. Thoroughly and in depth. -Each step I took depleted my character a bit more. Like I was trading myself -bit by bit without understanding what it all meant. What it meant to be a full +Each step I took depleted my character a bit more. Like I was trading myself bit +by bit without understanding what it all meant. What it meant to be a full person, not divided by all this bought attention they want from me. They don't -just get your data, but they also take your attention away from you. They +just get your data, but they also take your attention away from you. They scatter your and go with the divide and conquer tactic from there. And a person divided is a person not fully there. Not at the moment. Not alive fully. -I was unable to form long thoughts. Well, I thought I was. But now that I see +I was unable to form long thoughts. Well, I thought I was. But now that I see what being a full person is again, I can see that I was not at my 100% back then. -A revolt was inevitable. There was no other way of continuing my story without -it. Without taking back my attention, my thoughts, my time, and my privacy, +A revolt was inevitable. There was no other way of continuing my story without +it. Without taking back my attention, my thoughts, my time, and my privacy, regardless of how too late it maybe is. -This has nothing to do with conspiracy theories. Even less with changing the -world. All I wanted was to get my life back in order and not waste the energy +This has nothing to do with conspiracy theories. Even less with changing the +world. All I wanted was to get my life back in order and not waste the energy that could be spent in other, better places. I started reading more. I can focus now fully on things I work on. Furthermore, I have the mental acuity that I never had before. My mind feels sharp. I don't -get angry so much. I can cherish the finer things in life now without the need +get angry so much. I can cherish the finer things in life now without the need to interpret them intellectually. Not only that, but I have a feeling of -belonging again. Sense of purpose has returned with a vengeance. And I can -now help people without depleting myself. +belonging again. Sense of purpose has returned with a vengeance. And I can now +help people without depleting myself. -The last step so far was to finish closing all the remaining online accounts +The last step so far was to finish closing all the remaining online accounts that I still had. And when I was thinking what value they bring me, I wasn't -surprised that the answer was none. I wasn't logging in them and using them. -I stopped being afraid of FOMO. If somebody wants to get in contact me, they -will find a way. I am one search away. - -We are not beholden to anybody. Our lives are our own. So dare yourself to -delete Facebook, LinkedIn. To unsubscribe. Dare yourself to take your time -and attention back. Use that time and energy to go for a walk without thinking -about work. Read a book instead of reading comment on social media that you -will forget in an hour. Enrich your life instead of wasting it. It only -requires a small step. And you will feel the benefits immediately. Lose the -weight of the world that is crushing you without your consent. +surprised that the answer was none. I wasn't logging in them and using them. I +stopped being afraid of FOMO. If somebody wants to get in contact me, they will +find a way. I am one search away. +We are not beholden to anybody. Our lives are our own. So dare yourself to +delete Facebook, LinkedIn. To unsubscribe. Dare yourself to take your time and +attention back. Use that time and energy to go for a walk without thinking about +work. Read a book instead of reading comment on social media that you will +forget in an hour. Enrich your life instead of wasting it. It only requires a +small step. And you will feel the benefits immediately. Lose the weight of the +world that is crushing you without your consent. diff --git a/content/posts/2021-12-03-debian-based-riced-up-distribution-for-developers.md b/content/posts/2021-12-03-debian-based-riced-up-distribution-for-developers.md index b8d93a6..0755282 100644 --- a/content/posts/2021-12-03-debian-based-riced-up-distribution-for-developers.md +++ b/content/posts/2021-12-03-debian-based-riced-up-distribution-for-developers.md @@ -7,32 +7,33 @@ draft: false ## Introduction -I have been using [Ubuntu](https://ubuntu.com/) for quite a longtime now. I -have used [Debian](https://www.debian.org/) in the past and [Manjaro](https://manjaro.org/). -Also had [Arch](https://archlinux.org/) for some time and even ran -[Gentoo](https://www.gentoo.org/) way back. +I have been using [Ubuntu](https://ubuntu.com/) for quite a longtime now. I have +used [Debian](https://www.debian.org/) in the past and +[Manjaro](https://manjaro.org/). Also had [Arch](https://archlinux.org/) for +some time and even ran [Gentoo](https://www.gentoo.org/) way back. What I learned from all this is that I prefer running a bit older versions and -having them be stable than run bleeding edge rolling release. For that reason, -I stuck with Ubuntu for a couple of years now. I am also at a point in my life -where I just don't care what is cool or hip anymore. I just want a stable -system that doesn't get in my way. +having them be stable than run bleeding edge rolling release. For that reason, I +stuck with Ubuntu for a couple of years now. I am also at a point in my life +where I just don't care what is cool or hip anymore. I just want a stable system +that doesn't get in my way. -During all this, I noticed that these distributions were getting very bloated +During all this, I noticed that these distributions were getting very bloated and a lot of software got included that I usually uninstall on fresh -installation. Maybe this is my OCD speaking, but why do I have to give fresh -installation min 1 GB of ram out of the box just to have a blank screen in -front of me? I get it, there are many things included in the distro to make my -life easier. I understand. But at this point I have a feeling that modern Linux -distributions are becoming similar to [Node.js project with node_modules](https://devhumor.com/content/uploads/images/August2017/node-modules.jpg). -Just a crazy number of packages serving very little or no purpose, just +installation. Maybe this is my OCD speaking, but why do I have to give fresh +installation min 1 GB of ram out of the box just to have a blank screen in front +of me? I get it, there are many things included in the distro to make my life +easier. I understand. But at this point I have a feeling that modern Linux +distributions are becoming similar to [Node.js project with +node_modules](https://devhumor.com/content/uploads/images/August2017/node-modules.jpg). +Just a crazy number of packages serving very little or no purpose, just supporting other software. I felt I needed a fresh start. To start over with something minimal and clean. Something that would put a little more joy into using a computer again. -For the first version, I wanted to target the following machines I have at -home that I want this thing to work on. +For the first version, I wanted to target the following machines I have at home +that I want this thing to work on. ```yaml # My main stationary work machine @@ -52,11 +53,11 @@ Memory: 15891MiB ## How should I approach this? -I knew I wanted to use [minimal Debian netinst ](https://www.debian.org/CD/netinst/) -for the base to give myself a head start. No reason to go through changing the -installer and also testing all that behemoth of a thing. So, some sort of -ricing was the only logical option to get this thing of the grounds somewhat -quickly. +I knew I wanted to use [minimal Debian netinst +](https://www.debian.org/CD/netinst/) for the base to give myself a head +start. No reason to go through changing the installer and also testing all that +behemoth of a thing. So, some sort of ricing was the only logical option to get +this thing of the grounds somewhat quickly. > **What is ricing anyway?** > The term “RICE” stands for Race Inspired Cosmetic Enhancement. A group of @@ -66,9 +67,9 @@ quickly. > than others... For more information, read this article > [What in the world is ricing!?](https://pesos.github.io/2020/07/14/what-is-ricing.html). -I didn't want this to just be a set of config files for theming purpose. I +I didn't want this to just be a set of config files for theming purpose. I wanted this to include a set of pre-installed tools and services that are being -used all the time by a modern developer. Theming is just a tiny part of it. +used all the time by a modern developer. Theming is just a tiny part of it. Fonts being applied across the distro and things like that. First, I choose terminal installer and left it to load additional components. @@ -87,10 +88,9 @@ downloaded from the internet during installation. ![](/assets/dfd-rice/install-02.png) - -I opted out of the popularity contest, and **now comes the important part**. -Uncheck all the boxes in Software selection and only leave 'standard system -utilities'. I also left an SSH server, so I was able to log in to the machine +I opted out of the popularity contest, and **now comes the important part**. +Uncheck all the boxes in Software selection and only leave 'standard system +utilities'. I also left an SSH server, so I was able to log in to the machine from my main PC. ![](/assets/dfd-rice/install-03.png) @@ -100,50 +100,49 @@ system. ![](/assets/dfd-rice/install-04.png) -That concluded the installation of base Debian and after restarting the -computer I was prompted with the login screen. +That concluded the installation of base Debian and after restarting the computer +I was prompted with the login screen. ![](/assets/dfd-rice/install-05.png) Now that I had the base installation, it was time to choose what software do I -want to include in this so-called distribution. I wanted out of the box +want to include in this so-called distribution. I wanted out of the box developer experience, so I had plenty to choose. Let's not waste time and go through the list. ## Desktop environments -I have been using [Gnome](https://www.gnome.org/) for my whole Linux life. -From version 2 forward. It's been quite a ride. I hated version 3 when it -came out and replaced version 2. But I got used to it. And now with version -40+ they also made couple of changes which I found both frustrating and -presently surprised. +I have been using [Gnome](https://www.gnome.org/) for my whole Linux life. From +version 2 forward. It's been quite a ride. I hated version 3 when it came out +and replaced version 2. But I got used to it. And now with version 40+ they also +made couple of changes which I found both frustrating and presently surprised. -The amount of vertical space you loose because of the beefy title bars on -windows is ridiculous. And then in case of [Tilix](https://gnunn1.github.io/tilix-web/) -you also have tabs, and you are 100px deep. Vertical space is one of the most -important things for a developer. The more real estate you have, the more -code you can have in a viewport. +The amount of vertical space you loose because of the beefy title bars on +windows is ridiculous. And then in case of +[Tilix](https://gnunn1.github.io/tilix-web/) you also have tabs, and you are +100px deep. Vertical space is one of the most important things for a +developer. The more real estate you have, the more code you can have in a +viewport. -But on the other hand, I still love how Gnome feels and looks. I gotta give -them that. They really are trying to make Gnome feel unified and modern. +But on the other hand, I still love how Gnome feels and looks. I gotta give them +that. They really are trying to make Gnome feel unified and modern. -Regardless of all the nice things Gnome has, I was looking at the tiling -window managers for some time, but never had the nerve to actually go with -it. But now was the ideal time to give it a go. No guts, no glory kind of -a thing. +Regardless of all the nice things Gnome has, I was looking at the tiling window +managers for some time, but never had the nerve to actually go with it. But now +was the ideal time to give it a go. No guts, no glory kind of a thing. One of the requirements for me was easy custom layouts because I use a really -strange monitor with aspect ratio of 32:9. So relying on included layouts -most of them have is a non-starter. +strange monitor with aspect ratio of 32:9. So relying on included layouts most +of them have is a non-starter. -What I was doing in Gnome was having windows in a layout like the diagram -below. This is my common practice. And if you look at it you can clearly see -I was replicating tiling window manager setup in Gnome. +What I was doing in Gnome was having windows in a layout like the diagram +below. This is my common practice. And if you look at it you can clearly see I +was replicating tiling window manager setup in Gnome. ![](/assets/dfd-rice/layout.png) -That made me look into a bunch of tiling window managers and then tested them +That made me look into a bunch of tiling window managers and then tested them out. Candidates I was looking at were: - [i3](https://i3wm.org/) @@ -154,18 +153,20 @@ out. Candidates I was looking at were: - [Qtile](http://www.qtile.org/) - [dwm](https://dwm.suckless.org/) -You can also check article [13 Best Tiling Window Managers for Linux](https://www.tecmint.com/best-tiling-window-managers-for-linux/) -I was referencing while testing them out. +You can also check article [13 Best Tiling Window Managers for +Linux](https://www.tecmint.com/best-tiling-window-managers-for-linux/) I was +referencing while testing them out. -While all of them provided what I needed, I liked i3 the most. What particular -caught my eye was the ease to use and tree based layouts which allows flexible +While all of them provided what I needed, I liked i3 the most. What particular +caught my eye was the ease to use and tree based layouts which allows flexible layouts. I know others can be set up also to have custom layouts other than spiral, dwindle etc. I think i3 is a good entry-level window manager for somebody like me. ## Batteries included -The source for the whole thing is located on Github https://github.com/mitjafelicijan/dfd-rice. +The source for the whole thing is located on Github +https://github.com/mitjafelicijan/dfd-rice. Currenly included: @@ -193,7 +194,7 @@ Currenly included: - `docker` (with docker-compose) - `ansible` -Install script also allows you to install only specific packages (example for: +Install script also allows you to install only specific packages (example for: essentials ohmybash docker rust). ```sh @@ -202,10 +203,10 @@ su - root \ essentials ohmybash docker rust ``` -Currently, most of these recipes use what Debian and this is totally fine with -me since I never use bleeding edge features of a package. But if something -major would come to light, I will replace it with a possible compilation -script or something similar. +Currently, most of these recipes use what Debian and this is totally fine with +me since I never use bleeding edge features of a package. But if something major +would come to light, I will replace it with a possible compilation script or +something similar. This is some of the output from the installation script. @@ -232,11 +233,11 @@ systemctl status docker --no-pager ### Making bash pretty -I really like [Oh My Zsh](https://ohmyz.sh/), but I don't like zsh shell. -When I used it, I constantly needed to be aware of it and running bash scripts -was a pain. So, I was really delighted when I found out that a version for -bash existed called [Oh My Bash](https://ohmybash.nntoan.com/). Let's take a -look at the recipe for installing it. +I really like [Oh My Zsh](https://ohmyz.sh/), but I don't like zsh shell. When +I used it, I constantly needed to be aware of it and running bash scripts was a +pain. So, I was really delighted when I found out that a version for bash +existed called [Oh My Bash](https://ohmybash.nntoan.com/). Let's take a look at +the recipe for installing it. ```sh # ohmybash @@ -246,29 +247,29 @@ T1=${!} wait ${T1} ``` -Because OhMyBash does `exec bash` at the end, this traps our script inside -another shell and our script cannot continue. For that reason, I executed -this in background. But that presents a new problem. Because this is executed -in background, we lose track of progress naturally. And that strange trick -with `T1=${!}` and `wait ${T1}` waits for the background process to finish -before continuing to another task in bash script. +Because OhMyBash does `exec bash` at the end, this traps our script inside +another shell and our script cannot continue. For that reason, I executed this +in background. But that presents a new problem. Because this is executed in +background, we lose track of progress naturally. And that strange trick with +`T1=${!}` and `wait ${T1}` waits for the background process to finish before +continuing to another task in bash script. Check [Multi-Threaded Processing in Bash Scripts](https://www.cloudsavvyit.com/12277/how-to-use-multi-threaded-processing-in-bash-scripts/) for more details. ## Conclusion -Take a look at https://github.com/mitjafelicijan/dfd-rice/blob/develop/tools/install.sh -script to get familiar with it. This is just a first iteration and I will -continue to update it because I need this in my life. +Take a look at +https://github.com/mitjafelicijan/dfd-rice/blob/develop/tools/install.sh script +to get familiar with it. This is just a first iteration and I will continue to +update it because I need this in my life. -The current version boots in 4s to the login prompt, and after you log in, -the desktop environment loads in 2s. So, its fast, very fast. And on clean -boot, I measured ~230 MB of RAM usage. +The current version boots in 4s to the login prompt, and after you log in, the +desktop environment loads in 2s. So, its fast, very fast. And on clean boot, I +measured ~230 MB of RAM usage. -And this is how it looks with two terminals side by side. I really like the +And this is how it looks with two terminals side by side. I really like the simplicity and clean interface. I will polish the colors and stuff like that, but I really do like the results. ![](/assets/dfd-rice/desktop.png) - diff --git a/content/posts/2021-12-25-running-golang-application-as-pid1.md b/content/posts/2021-12-25-running-golang-application-as-pid1.md index e3b7fa2..60d0400 100644 --- a/content/posts/2021-12-25-running-golang-application-as-pid1.md +++ b/content/posts/2021-12-25-running-golang-application-as-pid1.md @@ -7,9 +7,10 @@ draft: false ## Unikernels, kernels, and alike -I have been reading a lot about [unikernernels](https://en.wikipedia.org/wiki/Unikernel) -lately and found them very intriguing. When you push away all the marketing -speak and look at the idea, it makes a lot of sense. +I have been reading a lot about +[unikernernels](https://en.wikipedia.org/wiki/Unikernel) lately and found them +very intriguing. When you push away all the marketing speak and look at the +idea, it makes a lot of sense. > A unikernel is a specialized, single address space machine image constructed > by using library operating systems. ([Wikipedia](https://en.wikipedia.org/wiki/Unikernel)) diff --git a/content/posts/2021-12-30-wap-mobile-web-before-the-web.md b/content/posts/2021-12-30-wap-mobile-web-before-the-web.md index 1ee82b5..6c598fe 100644 --- a/content/posts/2021-12-30-wap-mobile-web-before-the-web.md +++ b/content/posts/2021-12-30-wap-mobile-web-before-the-web.md @@ -7,14 +7,15 @@ draft: false ## A little stroll down the history lane -About two weeks ago, I watched this outstanding documentary on YouTube -[Springboard: the secret history of the first real smartphone](https://www.youtube.com/watch?v=b9_Vh9h3Ohw) -about the history of smartphones and phones in general. It brought back so many -memories. I never had an actual smartphone before the Android. The closest to -smartphone was [Sony Ericsson P1](https://www.gsmarena.com/sony_ericsson_p1-1982.php). -A fantastic phone and I broke it in Prague after a party and that was one of -those rare occasions where I was actually mad at myself. But nevertheless, -after that phone, the next one was an Android one. +About two weeks ago, I watched this outstanding documentary on YouTube +[Springboard: the secret history of the first real +smartphone](https://www.youtube.com/watch?v=b9_Vh9h3Ohw) about the history of +smartphones and phones in general. It brought back so many memories. I never had +an actual smartphone before the Android. The closest to smartphone was [Sony +Ericsson P1](https://www.gsmarena.com/sony_ericsson_p1-1982.php). A fantastic +phone and I broke it in Prague after a party and that was one of those rare +occasions where I was actually mad at myself. But nevertheless, after that +phone, the next one was an Android one. Before that, I only owned normal phones from Nokia and Siemens etc. Nothing special, actually. These are the phones we are talking about. Before 2007. @@ -34,42 +35,42 @@ Let's take a look at these beauties. ## WAP - Wireless Application Protocol -Not that one! We are talking about Wireless Application Protocol and not -Cardi B's song 😃 +Not that one! We are talking about Wireless Application Protocol and not Cardi +B's song 😃 -WAP stands for Wireless Application Protocol. It is a protocol designed for -micro-browsers, and it enables the access of internet in the mobile devices. -It uses the mark-up language WML (Wireless Markup Language and not HTML), WML -is defined as XML 1.0 application. Furthermore, it enables creating web -applications for mobile devices. In 1998, WAP Forum was founded by Ericson, +WAP stands for Wireless Application Protocol. It is a protocol designed for +micro-browsers, and it enables the access of internet in the mobile devices. It +uses the mark-up language WML (Wireless Markup Language and not HTML), WML is +defined as XML 1.0 application. Furthermore, it enables creating web +applications for mobile devices. In 1998, WAP Forum was founded by Ericson, Motorola, Nokia and Unwired Planet whose aim was to standardize the various -wireless technologies via protocols. +wireless technologies via protocols. [(source)](https://www.geeksforgeeks.org/wireless-application-protocol/) -WAP protocol was resulted by the joint efforts of the various members of WAP +WAP protocol was resulted by the joint efforts of the various members of WAP Forum. In 2002, WAP forum was merged with various other forums of the industry, -resulting in the formation of Open Mobile Alliance (OMA). +resulting in the formation of Open Mobile Alliance (OMA). [(source)](https://www.geeksforgeeks.org/wireless-application-protocol/) -These were some wild times. Devices had tiny screens and data transmission rates -were abominable. But they were capable of rendering WML (Wireless Markup -Language). This was very similar to HTML, actually. It is a markup language, +These were some wild times. Devices had tiny screens and data transmission rates +were abominable. But they were capable of rendering WML (Wireless Markup +Language). This was very similar to HTML, actually. It is a markup language, after all. -These pages could be served by [Apache](https://apache.org/) and could be +These pages could be served by [Apache](https://apache.org/) and could be generated by CGI scripts on the backend. The only difference was the limited markup language. ## WML - Wireless Markup Language -Just like web browsers use HTML for content structure, older mobile device -browsers use WML - if you need to support really old mobile phones using WML -browsers, you will need to know about it. WML is XML-based (an XML vocabulary -just like XHTML and MathML, but not HTML) and does not use the same metaphor -as HTML. HTML is a single document with some metadata packed away in the head, -and a body encapsulating the visible page. With WML, the metaphor does not -envisage a page, but rather a deck of cards. A WML file might have several -pages or cards contained within it. +Just like web browsers use HTML for content structure, older mobile device +browsers use WML - if you need to support really old mobile phones using WML +browsers, you will need to know about it. WML is XML-based (an XML vocabulary +just like XHTML and MathML, but not HTML) and does not use the same metaphor as +HTML. HTML is a single document with some metadata packed away in the head, and +a body encapsulating the visible page. With WML, the metaphor does not envisage +a page, but rather a deck of cards. A WML file might have several pages or cards +contained within it. [(source)](https://www.w3.org/wiki/Introduction_to_mobile_web) ```html @@ -82,7 +83,8 @@ pages or cards contained within it. ``` -There is an amazing tutorial on [Tutorialpoint about WML](https://www.tutorialspoint.com/wml/index.htm). +There is an amazing tutorial on [Tutorialpoint about +WML](https://www.tutorialspoint.com/wml/index.htm). ## Converting Digg to WML @@ -166,24 +168,24 @@ with open('www/index.wml', 'w+') as fp: fp.write(html) ``` -This script will create a folder `www` and in the folder `www/images` for +This script will create a folder `www` and in the folder `www/images` for storing resized images. > Be sure you don't use SSL and use just normal HTTP for serving the content. > These old phones will have problems with TLS 1.3 etc. -If you look at the python file, I convert all the images into tiny B&W images. -They should be WBMP (Wireless BitMaP) but I choose JPEGs for this, and it -seems to work properly. +If you look at the python file, I convert all the images into tiny B&W images. +They should be WBMP (Wireless BitMaP) but I choose JPEGs for this, and it seems +to work properly. -Because I currently don't have a phone old enough to test it on, I used an -emulator. And it was really hard to find one. I found [WAP Proof](http://wap-proof.sharewarejunction.com/) -on shareware junction, and it did the job well enough. I will try to find and -actual device to test it on. +Because I currently don't have a phone old enough to test it on, I used an +emulator. And it was really hard to find one. I found [WAP +Proof](http://wap-proof.sharewarejunction.com/) on shareware junction, and it +did the job well enough. I will try to find and actual device to test it on. -If you are using Nginx to serve the contents, add a directive to the hosts file +If you are using Nginx to serve the contents, add a directive to the hosts file that will automatically server `index.wml` file. ```nginx @@ -195,6 +197,5 @@ server { ## Conclusion Well, this was pointless, but very fun! I hope you enjoyed it as much as I did. -I will try to find an old phone to test it on. If you have any questions, -feel free to ask in the comments. - +I will try to find an old phone to test it on. If you have any questions, feel +free to ask in the comments. diff --git a/content/posts/2022-06-30-trying-out-helix-editor.md b/content/posts/2022-06-30-trying-out-helix-editor.md index c1da4a5..23c1cf3 100644 --- a/content/posts/2022-06-30-trying-out-helix-editor.md +++ b/content/posts/2022-06-30-trying-out-helix-editor.md @@ -5,27 +5,27 @@ date: 2022-06-30T12:00:00+02:00 draft: false --- -I have been searching for a lightweight code editor for quite some time. One of -the main reasons was that I wanted something that doesn't burn through CPU and +I have been searching for a lightweight code editor for quite some time. One of +the main reasons was that I wanted something that doesn't burn through CPU and RAM usage is not through the roof. I have been mostly using Visual Studio Code. It's been an outstanding editor. I have no quarrel with it at all. It's just time to spice life up with something new. I have been on this search for a couple of years. I have tried Vim, Neovim, -Emacs, Doom Emacs, Micro and couple more. Among most of them, I liked Micro -and Doom Emacs the most. Micro editor was a little too basic for me. And Doom -Emacs was a bit too hardcore. This does not reflect on any of the editors. It's -just my personal preference. +Emacs, Doom Emacs, Micro and couple more. Among most of them, I liked Micro and +Doom Emacs the most. Micro editor was a little too basic for me. And Doom Emacs +was a bit too hardcore. This does not reflect on any of the editors. It's just +my personal preference. -> I tried Helix Editor about a year ago. But I didn't pay attention to it. -> Tried it and saw it's similar to Vi and just said no. I was premature to +> I tried Helix Editor about a year ago. But I didn't pay attention to it. +> Tried it and saw it's similar to Vi and just said no. I was premature to > dismiss it. -One of the things I actually miss is line wrapping for certain files. When +One of the things I actually miss is line wrapping for certain files. When writing Markdown, line wrapping would be very helpful. Editing such a document -is frustrating to say the least. Some of the Markdown to HTML converters don't -take kindly of new lines between sentences. Not paragraphs, sentences. And I -use Markdown to write this blog you are reading. +is frustrating to say the least. Some of the Markdown to HTML converters don't +take kindly of new lines between sentences. Not paragraphs, sentences. And I use +Markdown to write this blog you are reading. But other than this, I have been extremely satisfied by it. It's been a pleasant surprise. There have been zero issues with the editor. @@ -39,15 +39,14 @@ npm install -g typescript typescript-language-server I am still getting used to the keyboard shortcuts and getting better. What Helix does really well is packing in sane defaults and even though because currently -there is no plugin support I haven't found any need for them. It has all that -you would need. It goes to extreme measures to show a user what is going on -with popups that show you what the keyboard shortcuts are. +there is no plugin support I haven't found any need for them. It has all that +you would need. It goes to extreme measures to show a user what is going on with +popups that show you what the keyboard shortcuts are. And it comes us packed with many [really good themes](https://github.com/helix-editor/helix/wiki/Themes). ![Editor](/assets/helix-editor/editor.png) -It's still young but has this mature feeling to it. It has sane defaults and +It's still young but has this mature feeling to it. It has sane defaults and mimics Vim (works a bit differently, but the overall idea is similar). - diff --git a/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md b/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md index 15bbf2b..e26088b 100644 --- a/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md +++ b/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md @@ -7,37 +7,38 @@ draft: false ## Introduction -Lately, I have been thinking a lot about the nature of life, what are the -foundation blocks of life and things like that. It's remarkable how complex -and on the other hand simple the creation is when you look at it. The miracle -of life keeps us grounded when our imagination goes wild. If the DNA are the -blocks of life, you could consider them to be an API nature provided us to -better understand all of this chaos masquerading as order. - -I have been reading a lot about superintelligence and our somehow misguided -path to create general artificial intelligence. What would the building blocks -or our creation look like? Is the compression really the ultimate storage of -information? Will our creation also ponder this questions when creating new -worlds for themselves, or will we just disappear into the vastness of -possibilities? It is a little offensive that we are playing God whilst being -completely ignorant of our own reality. Who knows! Like many other -breakthroughs, this one will also come at a cost not known to us when it -finally happens. - -To keep things a bit lighter, I decided to convert some popular DNA sequences -into an audio files for us to listen to. I am not the first one, nor I will be -the last one to do this. But it is an interesting exercise in better -understanding the relationship between art and science. Maybe listening to DNA +Lately, I have been thinking a lot about the nature of life, what are the +foundation blocks of life and things like that. It's remarkable how complex and +on the other hand simple the creation is when you look at it. The miracle of +life keeps us grounded when our imagination goes wild. If the DNA are the blocks +of life, you could consider them to be an API nature provided us to better +understand all of this chaos masquerading as order. + +I have been reading a lot about superintelligence and our somehow misguided path +to create general artificial intelligence. What would the building blocks or our +creation look like? Is the compression really the ultimate storage of +information? Will our creation also ponder this questions when creating new +worlds for themselves, or will we just disappear into the vastness of +possibilities? It is a little offensive that we are playing God whilst being +completely ignorant of our own reality. Who knows! Like many other +breakthroughs, this one will also come at a cost not known to us when it finally +happens. + +To keep things a bit lighter, I decided to convert some popular DNA sequences +into an audio files for us to listen to. I am not the first one, nor I will be +the last one to do this. But it is an interesting exercise in better +understanding the relationship between art and science. Maybe listening to DNA instead of parsing it will find a way into better understanding, or at least enjoying the creation and cryptic nature of life. ## DNA encoding and primer example -I have been exploring DNA in the past in my post from about 3 years ago in -[Encoding binary data into DNA sequence](/encoding-binary-data-into-dna-sequence.html) -where I have been converting all sorts of data into DNA sequences. +I have been exploring DNA in the past in my post from about 3 years ago in +[Encoding binary data into DNA +sequence](/encoding-binary-data-into-dna-sequence.html) where I have been +converting all sorts of data into DNA sequences. -This will be a similar exercise but instead of converting to DNA, I will be +This will be a similar exercise but instead of converting to DNA, I will be generating tones from Nucleotides. | Nucleotides | Note | Frequency | @@ -49,12 +50,13 @@ generating tones from Nucleotides. Since we do not have T in equal-tempered scale, I choose D to represent T note. -You can check [Frequencies for equal-tempered scale, A4 = 440 Hz](https://pages.mtu.edu/~suits/notefreqs.html). -For this tuning, we also choose `Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr`. +You can check [Frequencies for equal-tempered scale, A4 = 440 +Hz](https://pages.mtu.edu/~suits/notefreqs.html). For this tuning, we also +choose `Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr`. -Now that we have this out of the way, we can also brush up on the DNA -sequencing a bit. This is a famous quote I also used for the encoding tests, -and it goes like this. +Now that we have this out of the way, we can also brush up on the DNA sequencing +a bit. This is a famous quote I also used for the encoding tests, and it goes +like this. > How wonderful that we have met with a paradox. Now we have some hope of > making progress. @@ -72,16 +74,16 @@ AACCTCACCAAACGGGACAAGATCGCCGGCGGGCTAGTATACAAGAACGCTTGCCAGTAC AACC ``` -This is what we gonna work with to get things rolling forward, when creating +This is what we gonna work with to get things rolling forward, when creating parser and waveform generator. ## Parsing DNA data -This step is rather simple one. All we need to do is parse input DNA sequence in -[FASTA format](https://en.wikipedia.org/wiki/FASTA_format) well known -in [Bioinformatics](https://en.wikipedia.org/wiki/Bioinformatics) to extract -single Nucleotides that will be converted into separate tones based on -equal-tempered scale explained above. +This step is rather simple one. All we need to do is parse input DNA sequence in +[FASTA format](https://en.wikipedia.org/wiki/FASTA_format) well known in +[Bioinformatics](https://en.wikipedia.org/wiki/Bioinformatics) to extract single +Nucleotides that will be converted into separate tones based on equal-tempered +scale explained above. ```python nucleotide_tone_map = { @@ -101,8 +103,9 @@ def generate_from_dna_sequence(sequence): ## Generating sine wave -Because we are essentially creating a long stream of notes we will be appending -sine notes to a global array we will later use for creating a WAV file out of it. +Because we are essentially creating a long stream of notes we will be appending +sine notes to a global array we will later use for creating a WAV file out of +it. ```python import math @@ -118,7 +121,7 @@ def append_sinewave(freq=440.0, duration_milliseconds=500, volume=1.0): return ``` -The sine wave generated here is the standard beep. If you want something more +The sine wave generated here is the standard beep. If you want something more aggressive, you could try a square or saw tooth waveform. ## Generating a WAV file from accumulated sine waves @@ -144,13 +147,13 @@ def save_wav(file_name): wav_file.close() ``` -44100 is the industry standard sample rate - CD quality. If you need to save -on file size, you can adjust it downwards. The standard for low quality is, -8000 or 8kHz. +44100 is the industry standard sample rate - CD quality. If you need to save on +file size, you can adjust it downwards. The standard for low quality is, 8000 or +8kHz. WAV files here are using short, 16 bit, signed integers for the sample size. -So, we multiply the floating-point data we have by 32767, the maximum value -for a short integer. +So, we multiply the floating-point data we have by 32767, the maximum value for +a short integer. > It is theoretically possible to use the floating point -1.0 to 1.0 data > directly in a WAV file, but not obvious how to do that using the wave module @@ -159,8 +162,9 @@ for a short integer. ## Generating Spectograms I have tried two methods of doing this and both were just fine. I however opted -out to use the [SoX - Sound eXchange, the Swiss Army knife of audio manipulation](https://linux.die.net/man/1/sox) -one because it didn't require anything else. +out to use the [SoX - Sound eXchange, the Swiss Army knife of audio +manipulation](https://linux.die.net/man/1/sox) one because it didn't require +anything else. ```shell sox output.wav -n spectrogram -o spectrogram.png @@ -174,8 +178,9 @@ An example spectrogram of Ludwig van Beethoven Symphony No. 6 First movement. ![Ludwig van Beethoven Symphony No. 6 First movement](/assets/dna-synthesized/symphony-no6-1st-movement.png) -The other option could also be in combination with [gnuplot](http://www.gnuplot.info/). -This would require an intermediary step, however. +The other option could also be in combination with +[gnuplot](http://www.gnuplot.info/). This would require an intermediary step, +however. ```shell sox output.wav audio.dat @@ -183,7 +188,8 @@ tail -n+3 audio.dat > audio_only.dat gnuplot audio.gpi ``` -And input file `audio.gpi` that would be passed to gnuplot looks something like this. +And input file `audio.gpi` that would be passed to gnuplot looks something like +this. ``` # set output format and size @@ -214,9 +220,9 @@ plot "audio_only.dat" with lines lt rgb 'red' ## Pre-generated sequences -What I did was take interesting parts from an animal's genome and feed it to a +What I did was take interesting parts from an animal's genome and feed it to a tone generator script. This then generated a WAV file and I converted those to -MP3, so they can be played in a browser. The last step was creating a +MP3, so they can be played in a browser. The last step was creating a spectrogram based on a WAV file. ### Niels Bohr quote @@ -229,8 +235,9 @@ spectrogram based on a WAV file. ### Mouse -This is part of a mouse genome `Mus_musculus.GRCm39.dna.nonchromosomal`. -You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/). +This is part of a mouse genome `Mus_musculus.GRCm39.dna.nonchromosomal`. You +can get [genom data +here](http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/).