Search

7 Ways To Keep Yourself Motivated While Programming

Programming to be honest is not easy. It can be hard especially when you are stuck in a problem, or even when you have a bug and you don’t know a way out of it. I once wrote a project that had 400 lines of code and eventually there was a bug in it. I had to use bisection search to go through each of the lines of code to find out the bug. That one hour of work was very demotivating. You really need to be motivated to be a programmer, even while programming in python which is one of the easiest languages around.

People often ask me: “Nnaemeka David, what do you do to be motivated? Sometimes, it gets hard and frustrating?” So, I decided to write this post on some of the things one can do to get motivated while programming.

programming motivation
 

  1. Be disciplined.

  2. According to some dictionaries, discipline is the practice of obeying rules or a code of behavior. This skill is essential in programming because if you are not disciplined, you will end up in a lot of obstacles to your programming. Disciplining frees up your mind to think about solutions, and not just to rush into putting lines of code on an editor. Discipline makes you set up your programming defensively; you plan ahead for obstacles to your programming when disciplined. Discipline involves understanding the conventions of python as a programming language and following them. They keep you motivated. The style guide for python code, or sometimes called PEP8, is a good resource to instill discipline.

    When I learned programming from Professor Eric Grimm at MIT, (online course), he kept emphasizing on doing tests and setting yourself up for defensive programming before you begin writing code. I have seen the wisdom of that as time goes by. It helps me to debug; and bugs are something you will find all the time.

    If you are not disciplined, you will find yourself looking for a needle in a haystack. That is a very frustrating endeavor.

  3. Start with the bare minimum.

  4. Often beginners to python keep asking the question: Can I learn python in 3 months? What do I do to be a data scientist in the shortest space of time? I always tell anyone that asks me that they should go with the flow. Don’t force it. If you force it and you want to learn everything in the shortest time, you will get disappointed. Start with the bare minimum. Increase your aptitude as time passes by and your confidence increases. Otherwise, when it is 3 months and you discover you have not even scratched the surface of python programming, you will lose motivation. It is similar to when someone is working on the treadmill.

    While working on the treadmill, you don’t just start all at once doing 3 hours at a go. First, you start with five minutes intervals and take breaks. Then, as your body gets used to the routine, you increase the time you spend. So it is with programming in python and any other language. My advice to anyone who wants to take a fast paced approach is that they might be setting themselves up for disappointment. Rather, you take it slowly, one step at a time. Don’t constrain yourself to a time limit, but regularity is the secret to success.

  5. Try the Pomodoro technique.

  6. The Pomodoro technique is a time management technique that encourages you to work using the time you have rather than work against it. For example, say you can spare 30 minutes for programming, what you do is you spend that 30 minutes and set a timer to alert you when the time is up. When it is up, you take a break, and when you can spare another 30 minute you continue again, setting the timer. Many programmers have confessed that the pomodoro technique helps them to be productive. It can also help you.

    As programmers, we spend a lot of time in front of the computer and burn-out can easily set in, causing you to lose motivation. With the pomodoro technique, you will never get burned out because you are pacing yourself and taking breaks that helps you to get refreshed. Pomodoro technique also helps to boost your concentration and focus. There are a lot of softwares that implement the pomodoro technique and you can use them, like the focus booster app that runs on both windows and mac.

    A programming friend of mine on a forum told me that he used the pomodoro technique to learn 3 languages in 2 months. You can try it out yourself.

  7. Set goals.

  8. There is a trite saying that if you fail to plan, you are planning to fail. I have found setting specific goals helpful in helping me to get motivated while programming. But you don’t want to be setting goals you cannot achieve like starting from zero to hero in python in one month. You would be setting up yourself for failure. Set SMART goals, that is, goals that are specific, measurable, achievable, relevant, and time-oriented. After you have achieved one goal, congratulate yourself and move on to the next. Doing this, you will find python programming, or any other programming task, very enjoyable and fun.

    When I started programming, one goal I set is to do one challenge on hackerrank.com on a daily basis. I succeeded in completing the 30 days of code challenge and also doing other challenges. On some days, I would really feel in high spirits, congratulating myself for moving on to the next level. Try it out yourself by signing up at hackerrank.com and take a challenge. If you are a new programmer, take the basic challenge. There are lots of languages to choose from at the website.

  9. Projects, Projects and lots of Projects.

  10. To boost your confidence level and set yourself up for the industry, you can never underestimate the value of doing projects. My advice is that you do projects, more projects and lots of projects. Sign up at github and look for projects to collaborate. There are even projects on github.com that accepts beginners. You could sign up for those if you are new to python programming.

    If you don’t have ideas on what projects to do that would fit your level, just Google it. You will find all sorts of projects that you can choose from on Google; from beginner to expert.

    If you keep going from tutorial to tutorial while on your programming journey, you will be disappointed in record time. You need to learn to practice. That is the secret to being motivated.

  11. Love what you are doing.

  12. You must be passionate about programming, in python or any other language, to survive in this industry. Without passion and love for coding, you would be disappointed in no time. It involves lots of screen time, sometimes it steals the time from your relationships. You could set yourself up for failure if you are doing it for the money because you will encounter a lot of obstacles in the programming journey.

    Love programming. Write a line of code every day. In fact, to be motivated, you must love doing this and if you have read this post this far, I believe you love coding and want to improve. So congratulations.

  13. Start teaching others about programming.

  14. Teaching is a way of imparting knowledge to others. While you are teaching, you are improving your ability to use python and to learn python. Remember, as you are teaching others, you are teaching yourself. You are gaining benefits for yourself that are valuable.

    Also, teaching others imparts other soft skills to you. By teaching others, you gain communication skills and presentation skills. While successfully teaching others, you increase your confidence in using python programming language and you also gain leadership skills. According to glassdoor.com, a job search site, these skills are in high demand in the programming industry.

    If you cannot be part of a class to teach, you can participate in forums to help others. Forums like python-forum.io, freecodecamp.org, and Stackoverflow.com, can be of immense help to you to get teaching opportunities.

I wish you success in your programming career.

Why Shaving Blades Become Useless After Cutting Human Hair

For a long time scientists have been fascinated with one problem when it concerns blades. Although blades are made of stainless steel and have edges that are razor-sharp, to further strengthen them they are coated with diamond-like carbon, but a material that is 50 times softer than a blade such as a human hair can be able to make the blade useless over time. From a logical point of view, this should not be the case.

 

Intrigued by this problem, the engineers at MIT’s department of Material Science and Engineering have come up with an innovative solution. These engineers concern themselves daily with exploring the microstructure of materials in order to design and make new materials that could be able to have exceptional damage-resistance properties. The lead researcher, Gianluca Roscioli, an MIT graduate student, came up with his idea when he was shaving his own hair.

After noticing that his blades tend to get dull with time after shaving, he decided to take images of the blades after each shaving activity. He took these images with a scanning electron microscope (SEM), scanning the blade’s edge in order to track how the blade wore down over time. What he discovered showed that the process is much more complex than a simple wear over time. He noticed very little wear and rounding out at the edges but instead realized that chips were being formed around certain regions of the razor’s edge. These led him to ask himself: Under what conditions do these chipping take place, and what are the ingredients for a strengthened blade to fail after shaving a material as soft as human hair?

To answer these questions conclusively he built an apparatus that was designed to fit inside an SEM and he used it to take samples of his shaving and that of his colleagues. They found that there were some conditions that might cause the edges of a blade to chip and as the chipping proceeds with time, it will cause the blade to get dull. The conditions depend on the blade’s microstructure. If the blade is heterogeneous or the microscopic structure is not uniform, the blade will be more prone to chipping. Also, the angle at which the cutting was done was found to be significant. Therefore, they found that shaving at right angles were better than lower angles. Finally, the presence of defects in the steel’s microstructure was another factor that played a role in initiating cracks on the blade’s edge. Chipping was found to be more prominent when the human hair met the blade at a weak point in the blade’s heterogeneous structure.

These conditions illustrate a mechanism that is well known in engineering - stress intensification. This is the intensification of the stress applied to a material because the structure of the material has microcracks. Once an initial microcrack has formed, the material’s heterogeneous structure enabled these cracks to easily grow to become chips. Therefore, even though the material might be fifty times stronger than what it is cutting, the heterogeneity of the material can increase the stress on it, making cracks to intensify.

The implications of this discovery is immense. It will save money and costs to the average user of shaving blades because it will offer clues on how the edges of a blade can be preserved, and give manufacturers the opportunity to make better blades or cutting materials by using more homogenous materials.

The engineers have already taken their discovery one step further. They have filed a provisional patent on a process to manipulate steel into a more homogenous form, with the hope that they could use this process to build longer-lasting, and more chip-resistant blades.

Material for this post was taken from the MIT news website.

A Microscopic View Of Python’s Lookbehind and Lookahead Regex Assertions

Any discussion on regular expressions, or regex, is not complete without taking note of the lookaround assertions. Lookaround assertion in regex are assertions that state that at the current position of the string, check whether so and so pattern exists before or after the string. Note that when doing lookarounds, the string used in the lookaround is not consumed and the current position in the string does not change.

Now we will be making use of four types of lookaround assertions in regex today. They are the positive lookbehind, the negative lookbehind, the lookahead, and lastly the negative lookahead assertion.

Python Regex with lookahead and lookbehind assertions
 

The Positive and Negative lookbehind assertions.

In lookbehind assertions, we are only looking for what precedes the current position in the string that we want to match. The pattern in the lookbehind assertion does not participate in the match, or as it is said, is not consumed in the match. It only helps in asserting that the match is true. Lookbehind can be positive or negative. In positive lookbeind assertions, we are asserting that the pattern is present before the string. In negative lookbehind assertions, we are asserting that the pattern is not present before the string.

The syntax for positive lookbehind assertion is (?<=foo) where a match is found if foo precedes the current position of the string that is to be matched and foo ends at the current position.

Let’s illustrate this with some example. For example, let’s assert some currency figures. If we have a string like ‘USD100’ and we only want to match 100. We can assert that USD should come before the number 100 with this code: (?<=USD)\d{3} which states to match a digit consisting of exactly 3 characters which is preceded by the string, USD.

The syntax for the negative lookbehind assertion is (?<!foo) which matches the current position of the string if foo is not before the string. If we could continue with the string, ‘USD100’, then to say that the EURO should not be in the string we could use the code: (?<!EURO)\d{3}. I believe by now you must understand what the pattern represents.

Now, we will go on the the second set of lookaround assertions which are the lookahead assertion and negative lookahead assertion.

The lookahead and negative lookahead assertions.

The lookahead assertions are just the opposite of the lookbehind assertions. The lookahead assertions look for the pattern or non-existence of the pattern ahead of the current position in the string.

The lookahead assertion looks for the existence of the specified pattern from the current position. The syntax of the lookahead assertion is (?=foo) where from the current position of the string we are looking ahead if foo exists. Let’s take our 'USD100' string again. If we want to do a lookahead to see if the number exists after the dollar symbol, we could use the following code: w{3}(?=\d{3}). But the 100 number is not consumed in the match, we are taking out only the USD, just that we only want to assert that the 100 comes after the USD.

The negative lookahead assertion is an opposite of the lookahead assertion. If included in a pattern, it asserts that the pattern in the assertion does not come after the current position in the string. For example, if we have the following string 'USD100' and we want to assert that it is not 'USD200' we could use the following code: \w{3}(?!200). The code states that we are matching any string that has three letters but without 200 following it literally.

So, that is what we can take from the lookaround assertions in python. Now, let’s use our knowledge to solve a problem.

Assuming you are given the following string, rabcdeefgyYhFjkIoomnpOeorteeeeet, and you want to match all substrings of the string that contain 2 or more vowels on the condition that each of the substrings must lie between two consonants and must only contain vowels. How do you go about it.

If you look at the question, it involves lookbehind and lookahead assertions. That is, a consonant must lie before the vowel (lookbehind) and must also lie ahead of the vowels (lookahead). When you understand this, your work is nearly done. Then we must denote what it means to have a consonant. That means, it must be any letter that does not lie within the set of vowels, [aeiou]. We will be doing a case-insensitive match, so we will have to raise the Ignore case flag for the regex search pattern, re.I.

Here is how the code is written:

There is nothing new in the code. I have already explained most of the code in another blog post, entitled: The Big Advantage of Understanding Python Regex Methods.

You can download the script here if you want to take a deeper look at it.

I hope you have a nice day. If you want to keep receiving python updates like this, just subscribe to the blog using your email.

A Game Changing, Innovative, Microscale E-waste Recycling Strategy For The Environment And Manufacturing.

A typical recycling process involves the following – waste is collected, sorted, cleaned and processed, then the processed waste is used to manufacture more of the same product, and the cycle is closed when consumers buy these products. The recycling process depends on the fact that these collected waste are made of the same material. That makes it possible to manufacture new products. Yet, that is not the typical case for e-waste.

E-waste, or electronic products that are no longer working, unwanted, or close to the end of their useful lives, are usually made of heterogeneous materials which cannot be readily separated. Therefore, recycling them and putting them back into the cycle does not seem too commercially profitable for the average manufacturer. Yet, these wastes have to be recycled because if they are put back into the environment, which turns out to be usually the case, the toxic materials contained in them can poison our soil, water, air, or wildlife. 

 

To solve this problem some researchers have developed a selective, small-scale microrecycling strategy which can be used to convert old printed electronic parts like circuit boards and monitors into a new type of strong metal coating. These researchers, Veena Sahajwalla and Rumana Hossain, based their research on the copper and silica that are usually the components of electronic devices. They realized that based on the properties of these compounds they could be extracted from e-waste, then combined at high temperatures, even up to 2,732 F, thereby in the process generating silicon carbide nanowires which can then be processed further to create a durable, new hybrid material that is ideal for protecting metal surfaces.

These technique is innovative and a game changer. This could reduce the number of e-waste that end up in landfills and make it profitable for recycling plants to go into recycling larger amounts of e-waste. Imagine, the typical electronic device like a laptop and a TV screen contains lots of potentially valuable substances that could be used to modify the performance of other materials or used to manufacture new reliable materials. That is what this innovation makes possible. Also, the process, which the researchers have called material microsurgery, could be used to recover a large amount of copper annually for use in industries such as electronic devices, industrial, transportation, and consumer products.

Imagine the number of jobs that could be created in the recycling industry if e-waste was taken out of the ecosystem daily. Imagine what benefits it would bring to our environment not to have to dispose of these devices in landfills where they could percolate back to our water cycle or food.

These material microsurgery technique could also be used to create durable, new hybrid materials that could be used to protect metal surfaces. Yes, and it has been tested. During laboratory experiments it was discovered that the hybrid materials when fixed to steel remain firmly entrenched and when the steel is struck with a nanoscale indenter the hybrid layer does not get detached from the steel but remains firm, showing no signs of cracking or chipping. Further, it was seen to increase the hardness of steel by about 125%.

The potential benefits of this small-scale microrecycling strategy is very high. Thanks to the innovation of these two researchers, we could have a cleaner environment free from e-wastes and making sure more electronic products are not disposed of improperly.

I included this innovation in my blog because of its high potential benefit to mankind. I think this is a problem solved and worthy of being acclaimed.

Materials for this post were taken from a press release by the American Chemical Society, ACS.

Coding Python Functions Converting To Any Base That Fits Your Fancy

Sometimes while doing maths, we are faced with converting from one base to the other. Python is good for occasions like this. That is why I love programming in python. In this post, I will describe two ways you can convert any number in base 10 to any other base.

 

First, the more than one line way.

We will use simple mathematical logic to do the base conversion. In maths when you are converting from base 10 to any other base, what you do is that you repeatedly divide the number by the base, including the quotient, and keep the remainder until the quotient gets to zero. When you get the list of remainders, you then reverse the list and you have your converted number in that base. In this simplistic example that is also what we are going to do. I will be using two built-in functions to carry out this activity.

The first function is the divmod function. The syntax of the divmod function is divmod(numerator, denominator). The denominator divides the numerator. What the function returns is a tuple consisting of the quotient and the remainder. That’s it. So, we will be using this function to repeatedly divide the number and its quotient while returning the quotient and the remainder. The quotient will be checked against a condition that it has not gotten to zero while we will be collecting the remainder in a list. Just like you do in maths. When the quotient gets to zero, the division will end.

Then the second function we will be using is the reversed function. The syntax of the reversed function is reversed(sequence). As the name implies, reversed just takes a sequence and reverses the items in the sequence. So simple.

Now that we have our two handy functions, we are ready to write code that will convert any number to any base. I will call the function we will use for this, converter.

Here is the code:

I want you to note that while appending the remainder to each remainder_digits list, I first converted them to a string. If I did not, reversed would not be able to reverse them. Also in line 6 I used the ‘’.join statement to cast the list to a string.

You can download the script for the code above from here.

That’s the logical way to go about it. Now let me introduce you on how to do it with numpy.

One liner Numpy.

Numpy is fundamental for scientific and mathematical computing in python. As you know we are dealing with mathematical things here; numpy has a handy function for handling it. But I would add that numpy is somewhat of an overkill. The simple method I introduced above for programming it in python is enough. But in case you want something that can do it in one line and faster, then you can use numpy.

First, to use numpy it has to be installed on your machine. You can use the command: pip install numpy to install it on your machine, and if it is already installed, then you are good to go. Next, on your script you need to import numpy into your script using the statement: import numpy.

We will be using the numpy.base_repr function for this conversion. The syntax of the function is numpy.base_repr(number, base=2, padding=0). The only positional argument is the number you want to convert. The next is a keyword argument and this signifies the base you want to be converting to. The default is base 2. Then the next keyword argument is the padding you want for the numbers. The default is 0, that is, don’t pad the result with leading zeros. This is in case you want to pad the results. In case you need a refresher on positional and keyword arguments, you can see this earlier post on keyword and positional arguments.

Now that we have everything set up, let us see the one line of code that can do this for us.

You can download the script for the code above from here.

That’s it. Numpy is just another easier way of doing it with more added functionality. Numpy is beautiful. Note though that this function in numpy can only convert bases from base 2 to base 36. So if you need a base that is higher than 36, you should use the first converter function instead.

If you want to keep receiving python posts like this, just subscribe to this blog using your email. Happy pythoning.

Sweat Based Health Tracker That Is Better Than Anything Known

When Fitbit first came into the market I was wowed. I told myself that was cool. I could track all sorts of things about my health and performance. Along with Fitbit came a host of other gadgets that can help you understand your health status. But they all lacked one quality – they could not replace diagnostic tests required by medical doctors.

Woman with a health tracker on wrist
 

Now, there is a product that can. It is a sweat-based flexible electronic sensing thread that can be sewn into clothing to analyze all sorts of biomarkers and give accurate diagnosis. The threads come equipped with special sensors for collecting sweat while you are walking, running, working, or even watching TV. It then has electronic components that are wirelessly connected to a smartphone for real-time data acquisition and processing. These patches are just great.

They were developed by engineers at Tufts University who saw a need in the market. Present biomarkers could only track heart rate, temperature, glucose levels, walking distance and take only gross measurements. They could not do the real work of replacing laboratory diagnosis required often by doctors when analyzing your health status. So, the engineers decided to concentrate on something that could replace blood diagnosis. They decided on sweat.

Sweat is holistic. If you can detect and track sweat you could detect and track electrolytes in the sweat, like sodium, chloride, and ammonium ions, along with other biomarkers that could be detected for a more accurate analysis while doing it at your comfort. These patches are more accurate than present trackers. They are more indicative of the human health status and could be used for athletic performance measurement, workplace safety, clinical diagnosis, and even managing chronic health conditions.

For example, take the ability to detect sodium in sweat. With these threads on clothing, one could detect when he or she is hydrated or if there was electrolytic imbalance in the body in a matter of seconds. Lactate sensitivity is built into the threads and it can be used to indicate muscle fatigue for athletes or those who do strenuous activities. Cortisol, which is a stress hormone, could be detected in sweat and it can be used to assess emotional stress as well as metabolic and immune functions. The whole range of uses of these threads when sewn into clothing are immense. Their benefits are beyond recount. Even athletes could use the patches sewn into their clothing to monitor their physical exertion and aid them in predicting performance peaks or decline during competition.

The engineers came up with a unique ability to integrate these patches into clothing using flexible threads that were coated with conductor links and these threads are different for detecting different biomarkers that are present in sweat. The threads are then connected to a miniature circuit module linked to microprocessors with wireless capability for real-time communication with a smartphone.

When the engineers were asked why they chose sweat they said it is not only convenient to collect when clothing is on, it is easily accessible, can be collected non-invasively, and it correlates with the samples that could be derived from blood. I think I would love to invest in the company that would make this product commercially viable. It would replace many diagnostic techniques that we have today because sweat is a good surrogate for diagnostic fluid such as blood samples.

During tests it was discovered that the markers were accurate to about 5 to 30 seconds, enough for the real time needs of the average health conscious individual.

This is surely an innovative twist to helping those who are health conscious and individuals with chronic health problems; not to mention athletes who need to monitor all sorts of biological markers for performance enhancement. The engineers solved a problem.

You can read the full report at the Tufts website.

Matched content