Eduardo Zepeda's latests posts
Categories in Django using ForeignKey to self
- django
- databases
<p>Grouping by categories is quite common in web applications, from movies, courses or any other resource that presents a hierarchical relationship to another object. In Django there are different ways to model these relationships. Probably, the first that will come to your mind ...
Read more
Debounce and Throttle Interactive Explanation
- javascript
<p>Let's do a Debounce vs Throttle. Debounce and throttle are <a class="markdown-link" href="https://coffeebytes.dev/en/python/design-patterns-in-software/">design patterns</a> used to limit the execution of functions, generally they are used to restrict the ...
Read more
How to customize the User model in Django?
- django
<p>In this post I explain three methods to extend or customize Django's <em>User</em> model, without having to rewrite it from scratch, and keeping all <a class="markdown-link" href="https://coffeebytes.dev/en/django/why-should-you-use-django-framework/">Django&rs...
Read more
Differences between Django select_related and prefetch_related
- django
- databases
<p>Django's <em>select_related</em> and <em>prefetch_related</em> methods <strong>are used to reduce the number of queries made to the database</strong>. This translates into response time for each view. In addition, using these methods is one of the <a class="mar...
Read more
Why using React.FC could be a bad practice?
- react
- opinion
<p>When we use Typescript with React and we want to <a class="markdown-link" href="https://coffeebytes.dev/en/react/what-types-to-use-for-react-components-with-children/">pass a children as prop to one of our components</a>, we need to indicate the type. Generally ...
Read more
Go: profiling or basic profiling of CPU usage
- go
<p>In addition to <a class="markdown-link" href="https://coffeebytes.dev/en/go/go-basic-testing-and-coverage/">unit test testing and coverage measurement in go</a>, this programming language is capable of profiling the efficiency of the code by analyzing it in a ve...
Read more
Go: basic testing and coverage
- go
- testing
<p>Go already has a testing module in its standard library that is ready for our use, we just need to import it and use it.</p><p class="message info"> <span><img width="60" height="60" src="https://res.cloudinary.com/dwrscezd2/image/upload/v1717959563/Go_g...
Read more
Go: race conditions on goroutines and mutexes
- go
<p>In past posts I talked a bit about <a class="markdown-link" href="https://coffeebytes.dev/en/go/go-channels-understanding-the-goroutines-deadlocks/">goroutines, deadlocks and channels</a>. But there is another quite interesting issue about goroutines that stands...
Read more
Go: channels, understanding the goroutines deadlocks
- go
<p>When working with channels there is a quite common error that occurs when you are not familiar with the concepts, the error is “<em>fatal error: all goroutines are asleep - deadlock!</em>”. The first time I saw this error I was perplexed and, although I knew how to...
Read more
Go: use of channels to communicate goroutines
- go
<p>So far I have explained how to run a goroutine, execute code concurrently with the goroutines and wait for them to finish executing but our goroutines can't do anything else, they can't cooperate with each other to speed up the processes.</p><p>Imagine you hav...
Read more
But, before we start, let’s see where Django’s User model comes from.
Where does the Django User model come from?
Django’s User model inherits from AbstractUser which, in turn, inherits from the AbstractBaseUser class.
","datePublished":"Wed, 16 Mar 2022 00:00:00 +0000","dateModified":"Wed, 16 Mar 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/django/how-to-customize-the-user-model-in-django/"}},{"@type":"BlogPosting","headline":"Differences between Django select_related and prefetch_related","description":"Django’s select_related and prefetch_related methods are used to reduce the number of queries made to the database. This translates into response time for each view. In addition, using these methods is one of the actions to implement to improve the performance of a Django application
Just consider that there are more important things to optimize other than your app’s performance , but if you insist, dive into annotate and aggregate, and be careful with the nested subqueries of annotate because they can make your django queries go really slow
","datePublished":"Wed, 09 Mar 2022 00:00:00 +0000","dateModified":"Wed, 09 Mar 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/django/differences-between-django-select_related-and-prefetch_related/"}},{"@type":"BlogPosting","headline":"Why using React.FC could be a bad practice?","description":"When we use Typescript with React and we want to pass a children as prop to one of our components , we need to indicate the type. Generally we use the type React.FC, which is short for React.FunctionComponent. With this the Typescript message warning us of a children with type any will disappear.
const Component: React.FC = ({ children }) => {
return (<div>{children}</div>)
}
In addition to allowing us to work with children, React.FC also causes an error if we try to return undefined from our component.
","datePublished":"Wed, 23 Feb 2022 00:00:00 +0000","dateModified":"Wed, 23 Feb 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/react/why-using-react.fc-could-be-a-bad-practice/"}},{"@type":"BlogPosting","headline":"Go: profiling or basic profiling of CPU usage","description":"In addition to unit test testing and coverage measurement in go , this programming language is capable of profiling the efficiency of the code by analyzing it in a very detailed way. This is quite useful to find bottlenecks or very expensive parts of the code, which are called numerous times or whose performance can be improved.
How does Go profiling work internally in GNU/Linux?
GNU/Linux, more specifically GNU, has an alarm signal called SIGPROF , this signal warns when a timer finishes measuring CPU usage and interrupts code execution.
","datePublished":"Wed, 16 Feb 2022 00:00:00 +0000","dateModified":"Wed, 16 Feb 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/go/go-profiling-or-basic-profiling-of-cpu-usage/"}},{"@type":"BlogPosting","headline":"Go: basic testing and coverage","description":"Go already has a testing module in its standard library that is ready for our use, we just need to import it and use it.
Testing preparation in go
For the tests to be carried out we need:
A file ending in _test.go * A file ending in _test.go * Run the command go test.
","datePublished":"Wed, 09 Feb 2022 00:00:00 +0000","dateModified":"Wed, 09 Feb 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/go/go-basic-testing-and-coverage/"}},{"@type":"BlogPosting","headline":"Go: race conditions on goroutines and mutexes","description":"In past posts I talked a bit about goroutines, deadlocks and channels . But there is another quite interesting issue about goroutines that stands out when we use asynchrony and there are many functions accessing data at the same time and. Multiple functions reading and writing the same information can lead to chaotic situations where very strange things can happen.
","datePublished":"Wed, 02 Feb 2022 00:00:00 +0000","dateModified":"Wed, 02 Feb 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/go/go-race-conditions-on-goroutines-and-mutexes/"}},{"@type":"BlogPosting","headline":"Go: channels, understanding the goroutines deadlocks","description":"When working with channels there is a quite common error that occurs when you are not familiar with the concepts, the error is “fatal error: all goroutines are asleep - deadlock!”. The first time I saw this error I was perplexed and, although I knew how to fix it, I didn’t understand why it happened, so in this post I explain why it happens as I would have liked to have read it at the time.
","datePublished":"Wed, 26 Jan 2022 00:00:00 +0000","dateModified":"Wed, 26 Jan 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/go/go-channels-understanding-the-goroutines-deadlocks/"}},{"@type":"BlogPosting","headline":"Go: use of channels to communicate goroutines","description":"So far I have explained how to run a goroutine, execute code concurrently with the goroutines and wait for them to finish executing but our goroutines can’t do anything else, they can’t cooperate with each other to speed up the processes.
Imagine you have a web scrapper that gets data from the internet concurrently; we get the data with goroutines and process it with goroutines. do we have to wait for all the goroutines to finish to use it? Ideally, the goroutines should communicate with each other the data and continue processing.
","datePublished":"Sat, 22 Jan 2022 00:00:00 +0000","dateModified":"Sat, 22 Jan 2022 00:00:00 +0000","author":{"@type":"Person","name":"Eduardo Zepeda"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://coffeebytes.dev/en/go/go-use-of-channels-to-communicate-goroutines/"}}]}