Getting shit done

There is nothing more frustrating than having nice ideas and halt your work because you simply, at some point, lack motivation to move forward.

I deal with this kind of situation since I was only 10 years old and started some projects with programming languages. Never finished any of those projects, but learned a lot though.
Not that I am a perfectionist or something like that, but I never had pleasure releasing something that is half-assed. From my point of view, everything can be improved at some point.

The problem with that kind of attitude is that you end up having nothing to show and no feedback from others. Right now I am trying to work on my side projects (even this blog) and release what I can in some way. If there is a window to improve I will do it later, because right now I think it worth more to have something out there (used by someone, to get feedback or for any other purpose) than trying to make something flawless on the first try.

When developing a project you will end up improving your skills (programming, drawing, composing, painting) over time and something done like 12 months ago will look like shit because you got better. My point is: release. If someone criticise you try to look what he did, his projects, his skills. Is he that good? In my opinion, people who are really good don’t smother who is beginning.

So… that is how I am trying to deal with all the things now. I am trying to get shit done. That is how I am dealing with my motivation.

Other than that I try to work with a schedule, goals, tasks and deadlines. That helps to keep track of my things and it’s satisfying to see how it improve.

Organizing electronics parts – Resistors

In order to have electronics parts ready to use in my projects I started to order batches from China. They have the same quality of the components sold here in Brazil and are a lot cheaper.

I purchased 2500 resistors (50 pieces in 50 different values). On my first projects I struggled to find the right values due to ugly handwriting in the tape connecting the resistors. I decided to buy some resealable plastic bags (also from China) and classify every single value.

img_20161010_015118826
ice cream plastic container and sharpies

My decision was simple and efficient: crepe masking tape and permanent markers. To help finding the values I created four different ranges for the values and defined a color flag to each range. After all that classification I put all the plastic bags in a container.

TResistors in ziplocksoday it’s very easy to source the resistors for new projects. I use the ziplock bags left over in the same way with the sourced components with a label with the project name.

Parsing websites with curl and phpQuery

A while ago I had to crawl some websites to gather information about products. In the past I’ve used RegExp to parse the HTML, knowing it’s not the best method, but I just felt that PHP’s DOMDocument was clumsy.

I started coding the crawler with CakePHP 2.5.x and the following classes: electrolinux/phpquery and php-curl-class/php-curl-class.

The php-curl-class is pretty straight forward, it’s just easier to work with curl with it. In addition, the phpQuery is a library that let’s you use CSS3 selectors just like you do with jQuery.

I know it’s lame, but as example let’s get the title of SaveWalterWhite.

<?php
$curl = new \Curl\Curl();
$curl->get("http://www.savewalterwhite.com");
$pq = phpQuery::newDocument($curl->response);
echo $pq->find('title')->text();
?>

Obviously you can do more complex stuff, like getting all the image paths that are inside list items of the #walter-container div.

<?php
$curl = new \Curl\Curl();
$curl->get("http://www.savewalterwhite.com");
$pq = phpQuery::newDocument($curl->response);
for ($i=1;$i
$pics = $pq->find('div#walter-container li img')->attr('src');
if (!empty($pics)) { var_dump($pics); } 
?>

You can also use the selector on an iteration like this:

<?php
for ($i=1;$i<=$limit;$i++)
{
 $pics = $pq->find('div#product-detail ul li:nth-child('.$i.') a')->attr('data-image-zoom');
 if (!empty($pics))
 {
 $images[] = $pics;
 }
 }
?>

Checkout the phpQuery manual for further information. This class is handy and saved me a lot of time.