Learning

I recently found out that it’s very easy to get lost in the daily challenges of being a freelancer. The lack of real structure around yourself can make it difficult to distinguish code written for work and code written for play. It has become a bit difficult for me to say stop, my work for today is done, without feeling a little guilty about something. It can be how productive I was during the day, or I perceived the quality of the code I wrote.

Those things can be solved by a different mindset and a strong discipline. Work starts and stops at a certain predefined hour, except emergencies. Whatever code I write after or before those hours, it’s playtime.

The other problem I need to solve is, what do I do in my playtime? I like to learn new things, but I also need to become better. Learning something new is quite different from working on your fundamentals. So I chose two courses of actions in my case:

  • Learn a new language: I chose C#.
  • Choose a engaging side project to work on.

There is not really anything crazy behind the C# choice. I love to learn using Treehouse and they have a course on this language, so that’s really all there is to it. It’s also something quite different from Javascript, which is the language I mostly use. I believe it’s always important to explore new things.

Here comes the real problem: what side project to choose? I thought about this quite a bit. I still haven’t found anything serious yet, only a few ideas. But I think I can list a few things that a side project should have in order to become interesting:

  • Be personal. Solve one of your problems. If the project is something you can relate to, it will be easier to motivate yourself to work on it and/or make it better.
  • Be in the realm of possible. This one is about your current skills as a developer and also about being realistic. I love video games, but I don’t believe trying to make the next World of Warcraft could be considered a good side-project.
  • Have a future. It can scale. If more users get to use your project, that would not be a problem.
  • Be open source. Two reasons: you increase the chance of having other people use your project. And it could become easier to find help if you get stuck at one point. It would most likely help with the scalable issue.

So, that is what I think a side project should have to make me work on it on a regular basis. I decided that I wouldn’t start a side project until I become quite sure that I would spend some time on it and be proud of it in the end.

Let me know if you think a side project should have different attributes. How do you choose your side projects?

As always, feel free to share and comment.
Have a nice day!

Read more

Introduction

I recently started to work with a company as a freelancer. As I got access to the source code, I had the chance to look around at what technologies were used and the particular syntax that the software was written into. The software uses Socket.io for most of the communication client-server. But, as I was looking at the packages used and the code, one of those packages was socketio-streams. With this blog post, I’ll give a quick example of how this package works.. Let’s jump into it!

What is it ?

Here is how it is described:

This is the module for bidirectional binary data transfer with Stream API through Socket.IO.

Combining the native Node Stream API with Socket.IO. That sounds promising. One of the advantages of using streams with Sockets is that, if you end having to transfer a lot of data between the client and the server, it can become very slow. Streams, on the other end, listen to a data event, meaning they receive and send data by chunks. Let’s try to build something with it.

We are going to do something very simple, as an example. Let’s say I want users to send my a file and I will receive it and write the content of the file I received into a whole new file.

We will use socket.io-stream to create a new stream on the front-end. That stream will send the data to our back-end who will then write its content to a new file.

First, create a new directory and let’s install what we will need.

npm install express socket.io socket.io-stream

Then, let’s create two files: server.js and client.html

Here is how our server file will look like:

const ss = require('socket.io-stream');
const path = require('path');
const app = require('express')();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const fs = require('fs');

io.on('connection', socket => {
    console.log('connection');
    socket.emit('connected', 'hello World');
    ss(socket).on('file', (stream, data) => {
        stream.pipe(fs.createWriteStream( Date.now() +'.txt'));
    });
});

app.use((req, res) => {
    res.sendFile(path.join(__dirname + '/client.html'));
})

server.listen(3000);

We require our dependencies at the top. We create a server in order to use socket.io. Express will help use send the static html file on the front-end. So, as you can see, socket-stream listen to an event called file, this event will get two different arguments, a stream and the data. We then use the pipe method on that stream to connect it to a writable stream. This new writable stream write our content to a new .txt file. Let’s take a look at the front-end now.

client.html

<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
        <input type='file' id="file" />
        <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/socket.io-stream.js"></script>
        <script>
            const socket = io();
            let fileElem = document.getElementById('file');

            socket.on('connected', data => {
                console.log(data);
            });
            fileElem.onchange = e => {
                let file = e.target.files[0];
                let stream = ss.createStream();
                ss(socket).emit('file', stream, {size: file.size});
                let blobStream = ss.createBlobReadStream(file);
                let size = 0;
                blobStream.on('data', chunk => {
                    size += chunk.length;
                    console.log(Math.floor(size / file.size * 100) + '%');
                });

                blobStream.pipe(stream);
                blobStream.on('end' , ()=> {
                    console.log('done');
                });

            }

        </script>
    </body>
</html>

The html is very simple here, just an input that accepts file. I use the CDN service for socket.io and socket.io-stream. You could use require() if you are configured for that.

So, anytime that our file input changes, meaning that we give a new file, we create a new stream thanks to socket.io-stream. Then, we emit the file event. The event can take a few optional parameters. Here, I give a stream parameter, and the file size. Then, I create a read stream thanks to createBlobReadStream . A Blob is everything that is not Javascript data (like a file). I added a little snippet to display the progress of the upload (with on(‘data’) ). Then, we connect this read stream to the stream we created at the beginning (which is also the stream we gave as an argument in our emit event).

And that is pretty much it for our application. You can try it out by running:

node server.js  

You will see that every time you try to upload a new file, the progress will be shown in the console. And you will see a new file appearing in your directory.

Obviously, there are a lot of possibilities to use this. But, I think it is a nice start.

Feel free to ask questions and share!
Have a nice day!

Read more

This blog post is not about any kind of technology, library or language. It is not about the soft skills either. You see, as a football player (the soccer type), I have been practicing the game for nearly 20 years now. If you are engaged in any kind of sport activity or musical activity, chances are that you have been practicing something (as in repeating a move or a drill over and over).

Musicians play their scales or some piece of music as a warm-up exercise or practice. Athletes prepare their bodies for practice or competition. I can name a few drills that I’ve been doing for 20 years as a football player. Drills that are accepted in this sport as must-do to improve. It is expected for an athlete or a musician to spend time by himself or with a team practicing, without the pressure of the competition.

What about programming?

What drills or exercises programmers do, or must do, in order to become more efficient? Is there any warm-ups that programmers do in order to produce right away?

More mental than physical

It is pretty safe to say that being a programmer relies more on mental skills than physical ones. Solving problems with code. Make sure that we communicate clearly to other developers and clients.

On the physical side on things, make sure that your body posture won’t hurt you. Sit comfortably with your back straight. I could probably imagine one aspect that could be improved physically, how fast we type. Typing without looking the keyboard. You can find places to practice this like typingclub. What about your favourite editor shortcuts? Would it be worth it for programmers to spend some time each day or week learning or practicing these shortcuts?

What about the mental things? Do you have any rituals that make you more focus? Things that make you more efficient in solving problems? I do some meditation personally, and I can feel more focus for some time. But the main thing seems to be the complexity of the problem at hand. If a problem is too simple or way too complicated, I will lose my concentration much more easily than if I have a challenging problem, but not TOO challenging. You know, that sweet spot.

So, yeah, those are a couple of thoughts that I had. I am currently reading Peak from Anders Ericsson and Robert Pool about deliberate practice. I’ll probably write a post about what I read and maybe try to design some things that could make me a better programmer.

In the end, I believe that you need to code to become a better programmer. But repeating the things you already know how to do without trying to make it better or even different won’t get you anywhere. It is clear that the notion of feedback, when one is trying to improve, is always essential.

Let me know what you think, what you do to practice, to improve.

Feel free to share and comment.
Have a nice day!

Read more

For a very long time, I’ve always admired people who found their calling. People that just says ‘Well, I just do what I always wanted to do.’ . I was jealous of that. Knowing what is right for you from the start. The headaches you must save yourself if you are that lucky person. So, because I didn’t have that chance, I just though something was wrong with me.

Right? ​NO!

​Nothing is wrong with me. There is simple explanation to this: Passions are not born, they are cultivated. Nobody wakes up one morning with the perfect career choice in their mind. The path that will be just right for them. Impossible. Some may find the right career path on their first time. But the environment around us defines a lot of things about what we do.
It is the good old nature vs nurture debate. Our genes against what surrounds us.

A-Control

​​The​ assumption that I had before I started reading literature about the subject was: we must have control about our environment (nurture) and close to no control on our genes (nature). Well, that’s actually the opposite. We do not fully control our environment. I am an avid reader, I love it. Why? My mom used to read a lot too. The people, the culture that surrounds us are very likely to shape who we are as human beings. It makes sense. We, as children, must learn from people we interact with. At first, our parents. Then, our teachers and classmates. We are a product of the people we spend time with.
So, when you start playing the piano at 5, become a very good player at 13, and gives breathtaking concerts at 18, what’s going on? We must look at the environment. Are mom and dad musicians? Most likely. Mozart father was a composer that forced him to practice hours on end.

B-Picking the passion

When I look back at my life, nothing tells me that my environment pushed my towards programming. So, how do I explain the fact that I sticked with it?
In the George Leonard’s book Mastery, the author takes about three kinds of people in their path to mastery. The Dabbler, the Obsessive and the Hacker.

The Dabbler loves new things. He is very excited about trying a new sport, a new job, a new career. Getting the fancy stuff to get started. The first lessons are amazing, this IS the right thing for him. Then, he hits a plateau, the excitement fades, and disappear. The Dabbler looks for something new to get excited about.

The Obsessive is different in the way he sees the first plateau or falloff he hits. He doesn’t accept it, he can’t accept it. So he works harder, he must get everything right, right from the start. He stays longer at the office, ignore advice and just keep pushing. He manages to keep the fire alive in short spurts, pushing just one more time. Until he just quits.

Finally, the Hacker is very different. He is perfectly fine is the plateau that he hits. The Hacker gets by, doesn’t have a strong desire to improve. He gets the hang of one thing, and just think that’s all he needs. Every break he can get, he takes. He is fine with other Hackers around him. But if the people around start improving, ouch!

I am a Dabbler. i love trying new things. I tried a LOT of things. I buy the instrument, the books, sign up for that app. Yeah, this is my thing now. I envision myself being an expert at whatever new thing I picked up. I improve! Oh my God, this is it! I found my calling, finally!
Then, the plateau. The initial excitement is no longer here. And I just find something new to do.

This description of the Dabbler hits home for me. And I realised it was not sustainable. So I read more books about talent, finding your calling, having the right path, happiness. One day, I started to teach myself how to code. And I sticked with it. Why?

C-Having something to show

My first attempt at learning how to code was with C. I read that many languages derived from C, it is like the latin of programming languages. I thought, well I must start here. It will give me all the tools necessary to become awesome. So, I picked up Learning C for Dummies. Want to take a wild guess at what happened?

Yeah, I quit after a few weeks. I read about compilation, about the loops, the if-else…
I saw the stuff printed in my terminal… So boring…
Then, I discovered Treehouse and I signed up for the 14 days free trial. And I got into it. A year later, I’m still into it. Why? Because I built something right away.
You see, now, a lot of courses online make you write code right away. And this is so important. You are engaged, you are not drowning in the technical terms. You just do something of value, you feel useful. I made an HTML page! Now that I look back at it, it was nothing. A few tags, a header… But it was all me! I made it work!

Then, we added CSS, a bit of Javascript. An image here. And soon, my very own website was online. I still remember the feeling of wonder and amazement I had when it went live. I couldn’t believe I did this. I couldn’t believe of the road I had travelled. Sure, it was just a website, but it was mine. It wasn’t much, but that little thing was my baby.

This is what you must look for when finding a passion. Look for a teacher, or a course that will engage you in the task. Make you feel useful. Not just bore you with endless theories.

Make sure you build something, even the smallest thing possible!

As always, feel free to share and ask questions!
Have a nice day!

Read more