Wern Ancheta

Adventures in Web Development.

A Developers New Years Resolution

| Comments

It’s 2016. A brand-new year is upon us. And this is the time of the year when people usually set goals for the new year. While most other folks have new year’s resolution for their real life, In this article I’ll be sharing some of my new year’s resolution as a developer.

Generate Passive Income

The idea of generating a passive income has really enticed me in the past but it’s only this year that I’ve thought about it seriously. For developers one way of generating passive income is through marketplaces like Themeforest and CodeCanyon. All you have to do is build something useful and you can sell it on the platforms that I’ve just mentioned. I’ve already created an account on CodeCanyon, set it up and read their terms. All that’s left for me to do is to build something and submit it for review so that people can find it.

Continue What I’ve Started

I have a bunch of projects on Github. Some might not already work. Some lacking in documentation. This year I’ll continue every project that I started. Or at least mention that I won’t already be doing active development for projects that I’m no longer interested in pursuing.

I have also a blog series that I started back in 2014 which I called: A Whirlwind Tour of Web Developer Tools, I’m planning to start that up again this year.

Be More Picky

I read a lot. In fact I’ve created a website that curates all the news from sources that I want. Usually these are from the developer newsletters, twitter users, and websites that I follow. But I’m still subscribed to the newsletters which I have used as the news item source. So it still gets the better of my time when I receive a new issue. My plan is to unsubscribe to all of those newsletters and just stick to using the website myself. This is so that I don’t accidentally engage to some content. Or click on a link and not actually reading what’s in there. With the new setup I can actually just visit the website if I really want to read something and not when I receive a new issue of a newsletter.

The second step after unsubscribing to all newsletters is to actually pick only what I really want to read. If its a tool that I can use in the future, then I save it on my delicious account. If its an article which I want to go back to in the future then I save it on Pocket.

The third step is to actually read what’s really important or at least something that I really want to read. Of course this can’t be determined by merely looking at the title so the article has to be scanned first and then determine if it’s really relevant.

Of course this goes with all the other content that I’m consuming and creating. So movies, anime shows, personal projects, blog posts should go through a tight consideration before I actually engage on it.

Be More Healthy

Developers have a sedentary lifestyle by nature. Just sitting on a chair coding all day. That’s no good so here are the steps that I’m planning to implement to be more healthy.

  • Indoor exercise in the morning. Intense outdoor exercise in the weekends.
  • Use the standing desk at least one hour in the morning and one hour in the afternoon.
  • Eat less rice.
  • Eat more fruits and vegetables. There should be at least one meal per day where I eat a decent amount of those.
  • Get more sunlight.
  • Sleep more.
  • Be more concious about my posture.

Engage More in the Community

  • I’ll start by creating videos on Youtube showing a specific technology, tool or methodology regarding web development. I’ve already started it the previous year by uploading some of my flipped classroom videos that I’ve used in my class in the school where I teach.
  • Comment on other developers blog posts, or talk to them on twitter.
  • Answer questions on Stackoverflow.
  • Attend local developer meetups.
  • Contribute to open-source projects.

Use Tools

I’ve been pretty much avoiding the use of tools in my day to day job as a developer. I still use plain css instead of Less, Sass, Stylus or {insert your css preprocessor of choice here}. I still don’t use Grunt, Gulp, Brocolli, Carrots, Eggplant, {insert your build tool of choice here} for every project (note: there’s no carrots or eggplant yet but someone might create it after this). I’ve been avoiding the use of tools because I just want to get started with a project fast. Installing a bunch of tools and setting them up before I can start coding is a pain. The only tools that I currently use are the following:

  • Composer
  • Bower
  • npm

Simply because you can’t install anything without those.

This year I’ll start by learning how to use Yeoman so I can easily setup all the things that I need for a project. And then learn how to use a css preprocessor, Gulp to process the project assets, JSLint to check the quality of my JavaScript code. And then in the back-end use PHPUnit for unit-testing. And lastly use a continuous integration server such as Jenkins to automatically run unit tests so that I immediately know if a specific code is still working or not.

Build More Cool Shit

Pardon the language but developers are commonly foul-mouthed right? Anyway, what I mean by build more cool shit is to create stuff that I can be proud of. I’d also like to build IOT (Internet of Things) projects. And with the birth of the RaspberryPi zero it just got more easy. Though I’m yet to order one because the stock is always zero. I should have ordered one when I first heard about it. Now people are ordering it non-stop. Who wouldn’t right? RaspberryPi zero is only five fucking dollars.

Learn a New Language, Framework, Tool, Methodology

  • Language: Python – If I am to build stuff with RaspberryPi I need to learn to code in Python. I also want to leap from the hybrid app bandwagon and go full native so I’ll have to learn (or rather re-learn) Java. This is simply because apps built with Hybrid App Framework such as Cordova performs poorly on my old android phone. Maybe I just need a new phone but I’ll go ahead and blame it to programming.
  • Framework: Symfony – I’m basically a Laravel guy so for a change I pick Symfony.
  • Tools: CI Server, PHPUnit, Gulp, Sass, ReactJS
  • Methodology: I’m still not sure. But I’ll probably try to learn some of the most popular design patterns in JavaScript and PHP.

Get Better at What I Do

No matter how good you are at something there’s always room for improvement, there’s always another way for doing things twice as easy or efficient. So the plan for 2016 is to look for ways to improve my current development workflow. Like I said earlier I’m a Laravel guy so I’ll start by examining my current Laravel workflow and see what I can improve.

Invade Other Fields

I’ve been really interested in UX because I know it will be helpful for me as an all-around developer. When I say all-around it means I’m the one doing the server setup up to deployment and anything between those two. I’m pretty much a one-man band in all the projects that I’ve built so far. No devops, no designer, no nothing.

Another field that I’d like to look into is SEO. Who wouldn’t want to have their website more findable?

That’s it! How about you? What’s your plan for 2016?

Year-end Review

| Comments

A year is coming to an end again. And with lots of free time during the holidays I figured it would be nice to reflect on the previous year. So in this post I’ll be sharing some of the things that happened in 2015.

Career

As you might already know I’m a developer. So I develop websites and apps for a living. I mainly do home-based work since I graduated from college. Mainly because of its convenience and for personal reasons. You get to work from home and earn money how cool is that? But recently its no longer that fun. Payments get delayed. And projects are no longer that interesting. I basically stopped doing it around October of this year. Good thing I got hired as an author for Tutsplus’ Mobile channel. And I still write for Sitepoint. So I currently write articles for those two awesome websites full-time.

Around July this year I got a message from my college instructor asking if I want to teach. I said yes. And so from August until December I taught at the college where I graduated from. It’s only part-time during the afternoon so I still got to write full-time. From my 4 months of experience I can say that I really enjoyed teaching. Being able to share what you know and helping your students get better, it’s one of the most rewarding feelings ever.

Since teaching in college requires someone to have a master’s degree in their field. I had to take up Master’s in Information Technology. Good thing the school is only walking distance from my home so it’s very accessible. And classes are only on saturdays. So I’m still able to do what I like doing the most: coding.

Projects

This career section wouldn’t be complete without me talking about projects. If you look at my Github profile there are lots of new additions to the list of repos this year. This is mainly because I always write tutorials on making apps with different web technologies. Sitepoint and Tutsplus requires those apps to be in a Github repo. That’s why my Github has got a bunch of those apps. Another reason for the repo population growth is free time. I already mentioned that I currently write full-time. But I don’t necessarily have a boss. So I still got to choose whether to write for a certain day or work with another thing. Some days I choose to work on my personal projects. The common theme for my personal projects is usually to solve some problems that I’m having. Mainly automation stuff so I don’t have to do a lot of things manually. My part-time teaching job has particularly lots of problems that needs solving. This includes: attendance tracking, managing of files submitted by students, checking of student activities, showing grades to the students.

Health

Developers are mainly sedentary animals. That’s why there’s a need to make an effort to thwart the effects of sitting in front of the computer all day long. As for me what I did was to use a standing desk. And jog first thing in the morning.

Getting Information About Any Company With Clearbit’s Company API

| Comments

In this tutorial I’ll be showing you how you can get information from any company using the Clearbit Company API.

Start by signing up for an account on the Clearbit website. An API key will be assigned to your account after signing up. This allows you to make a request to their API.

Next, install Guzzle on your working directory. Guzzle is an HTTP library for PHP. It is used to easily make requests to any API.

1
composer require guzzlehttp/guzzle:~6.0

Include the vendor autoload file on your file and create a new Guzzle client with the following base uri: https://company.clearbit.com/.

1
2
3
4
5
<?php
require_once 'vendor/autoload.php';

$client = new GuzzleHttp\Client(array('base_uri' => 'https://company.clearbit.com/'));
?>

To use the API, make a get request to the v1/companies/domain/ endpoint followed by the domain name of the company that you want. Pass in the auth as an option. This allows you to specify the API key which you got from Clearbit.

1
2
3
4
5
<?php
$response = $client->get('v1/companies/domain/google.com', array(
    'auth' => array('YOUR-CLEARBIT-API-KEY', '')
));
?>

You can then get the response body by calling the getBody method in the response. In the example below, the response is converted to an array using the json_decode method.

1
2
3
4
5
6
<?php
$data = json_decode($response->getBody(), true);
?>
<pre>
<?php print_r($data); ?>
</pre>

The output will look something like the following.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
Array
(
[id] => 1d396c21-e421-4dd9-988e-55a8200c6e10
[name] => Google
[legalName] => Google Inc
[domain] => google.com
[domainAliases] => Array
    (
        [0] => covet.com
        [1] => appspotchat.com
        [2] => ggh-uae.com
        [3] => remail.com
        [4] => orkut.com
        [5] => goolge.com
        [6] => picasa.com
        [7] => blogspot.ru
        [8] => sparkbuy.com
        [9] => pushlife.com
        [10] => greenparrotpictures.com
        [11] => phonetic-arts.com
        [12] => omnisio.com
        [13] => googlecloud.com
        [14] => weardrobe.com
        [15] => ojos-inc.com
        [16] => akwan.com.br
        [17] => appliedsemantics.com
        [18] => gemail.com.br
        [19] => wosix.com
        [20] => firstinwireless.com
        [21] => cloudmarket.me
        [22] => riya.com
        [23] => teronamanagement.com
        [24] => sxz.co
        [25] => womenfitnessinsider.com
        [26] => webtocracy.org
        [27] => webtocracy.com
        [28] => webtocracy.net
        [29] => superapple.org
        [30] => storktechnology.com
        [31] => sourful.com
        [32] => snapchatdeals.com
        [33] => quarterthree.com
        [34] => puwak.com
        [35] => nudevilla.com
        [36] => nemzis.com
        [37] => ryanstull.com
        [38] => mckayfamily.org
        [39] => marksearle.net
        [40] => opentolink.com
        [41] => lewispi.com
        [42] => levkova.com
        [43] => katenka.net
        [44] => imize.net
        [45] => google.us
        [46] => com.google
        [47] => gogle.com
        [48] => oingo.com
        [49] => googlesyndication.com
        [50] => ggoogle.com
        [51] => google.io
        [52] => blogspot.ae
        [53] => gogole.com
        [54] => hijab.pw
        [55] => industrial-perception.com
        [56] => googlr.com
        [57] => googleadservices.com
        [58] => talkbin.com
        [59] => picnik.com
        [60] => postrank.com
        [61] => appjet.com
        [62] => google.co
        [63] => zabrinalee.com
        [64] => blu-ray.us
        [65] => picasa.net
        [66] => googleproductforums.com
        [67] => googlelabs.com
        [68] => googlee.com
        [69] => gooogle.com
        [70] => diychef.com
        [71] => googl.com
        [72] => gmail.co
        [73] => blogger.ch
        [74] => mozingo.me
        [75] => orkut.org
        [76] => lifescapeinc.com
        [77] => firehunt.com
        [78] => google.info
        [79] => veremey.net
        [80] => docverse.com
    )

[url] => http://google.com
[site] => Array
    (
        [url] => http://google.com
        [title] => Google
        [h1] => 
        [metaDescription] => Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
        [metaAuthor] => 
    )

[category] => Array
    (
        [sector] => Consumer Discretionary
        [industryGroup] => Media
        [industry] => Media
        [subIndustry] => Publishing
    )

[tags] => Array
    (
    )

[description] => Google’s mission is to organize the world’s information and make it universally accessible and useful.
[location] => 1600 Amphitheatre Parkway, Mountain View, CA 94043, USA
[geo] => Array
    (
        [streetNumber] => 1600
        [streetName] => Amphitheatre Parkway
        [subPremise] => 
        [city] => Mountain View
        [state] => California
        [country] => United States
        [postalCode] => 94043
        [lat] => 37.4224206
        [lng] => -122.0843021
    )

[logo] => https://logo.clearbit.com/google.com
[facebook] => Array
    (
        [handle] => google
        [likes] => 
    )

[linkedin] => Array
    (
        [handle] => company/google
    )

[twitter] => Array
    (
        [handle] => google
        [id] => 20536157
        [bio] => News and updates from Google
        [followers] => 11873983
        [following] => 448
        [location] => Mountain View, CA
        [site] => http://t.co/twxHxOtTvy
        [avatar] => https://pbs.twimg.com/profile_images/522909800191901697/FHCGSQg0_normal.png
    )

[angellist] => Array
    (
        [id] => 32203
        [handle] => google
        [description] => Google’s mission is to organize the world’s information and make it universally accessible and useful.
        [followers] => 7097
        [blogUrl] => http://googleblog.blogspot.com/
    )

[crunchbase] => Array
    (
        [handle] => google
    )

[emailProvider] => 
[type] => public
[ticker] => 
[phone] => +1 650-253-0000
[metrics] => Array
    (
        [alexaUsRank] => 1
        [alexaGlobalRank] => 1
        [googleRank] => 9
        [employees] => 10000
        [marketCap] => 
        [raised] => 1700000000
    )

[tech] => Array
    (
        [0] => google_analytics
        [1] => double_click
        [2] => google_adwords
        [3] => doubleclick
        [4] => google_apps
    )

)

Securing Passwords in PHP

| Comments

In this tutorial we’re going to take a look at some of the libraries that allows us secure passwords in PHP.

Password Compat

The first library that we’re going to look at is Password Compat. You can install it through Composer by using the following command.

1
composer require ircmaxell/password-compat

Once it’s done installing, you can the include the vendor autoload file so you can use its functions.

1
2
3
<?php
require_once 'vendor/autoload.php';
?>

The password_hash function is used to hash passwords. It accepts the password that you want to hash as its first argument and the algorithm to be used for password hashing as its second. In the example below, PASSWORD_DEFAULT is used. This allows you to use the most secure algorithm that’s currently available to PHP. At the time of writing of this article, the most secure algorithm that’s available to PHP is bcrypt. So that’s the one that’s being used when you specify PASSWORD_DEFAULT as the second argument.

1
2
3
4
<?php
$password = 'mypassword';
$hash = password_hash($password, PASSWORD_DEFAULT);
?>

There’s also an optional third argument which allows you to change the CPU cost of hashing the password. By default the cost is 10. So if you have a less powerful server you can change it to something lower. The cost can have a value between 4 and 31.

1
2
3
<?php
$hash = password_hash($password, PASSWORD_DEFAULT, array('cost' => 7));
?>

You can then store the hash in your database.

To validate if a password matches the hash stored in the database, use the password_verify method. This accepts the password as the first argument and the hash as the second. So in your application you might have a query to select the user based on its email or username and then you use the hash that was returned for the second argument.

1
2
3
4
5
6
7
<?php
if(password_verify($password, $hash)){
    echo 'valid';
}else{
    echo 'invalid';
}
?>

PHPAss

PHPAss is one of the older password hashing libraries that are available for PHP. Nevertheless it doesn’t make it less secure than any of the password securing methods in this article. It uses the blowfish algorithm to hash passwords.

Execute the following to install PHPAss.

1
composer require hautelook/phpass

After including the vendor autoload file, set your current file to use the PasswordHash class in the Hautelook namespace.

1
2
3
<?php
use Hautelook\Phpass\PasswordHash;
?>

Create a new password hasher instance. This accepts 2 required arguments. First is the base-2 logarithm of the iteration count used for password stretching. The second a boolean value for setting if the password will use portable hashes. The values that I’ve set below are the default one’s. Those will do for most use cases.

1
2
3
<?php
$passwordHasher = new PasswordHash(8, false);
?>

You can then call the HashPassword method to actually hash the password. This hash should then be stored into the database.

1
2
3
4
<?php
$password = 'mypassword';
$hash = $passwordHasher->HashPassword($password);
?>

You can check if a password is valid by using the CheckPassword method. This accepts the password as its first argument and the hash that came from the database as the second.

1
2
3
4
5
6
7
8
<?php
$passwordMatch = $passwordHasher->CheckPassword($password, $hash);
if($passwordMatch){
    echo 'valid';
}else{
    echo 'invalid';
}
?>

PHP Password Lib

PHP Password Lib is one of those libraries that isn’t really recommended for production use. As mentioned in their Github page itself, it’s currently in beta and should be used at your own risk.

In order to install PHP Password Lib, you first have to add a minimum-stability option and set it to dev. Also set prefer-stable to true so that composer will default to installing the stable versions of the other libraries that you’re installing via composer.

1
2
"minimum-stability": "dev",
"prefer-stable": true

Can’t really find the library in Packagist so you need to add the following to your composer.json file directly.

1
"PasswordLib/PasswordLib": "*"

Once that’s done, execute composer update to update the dependencies.

To use the library, create a new instance of the PasswordLib class and then use it to call the createPasswordHash method to hash a password.

1
2
3
4
5
<?php
$password = 'mypassword';
$lib = new PasswordLib\PasswordLib();
$hash = $lib->createPasswordHash($password);
?>

Just like the previous libraries it also comes with its own verify function.

1
2
3
4
5
6
7
8
<?php
$is_valid = $lib->verifyPasswordHash($password, $hash);
if($is_valid){
    echo 'yep';
}else{
    echo 'nope';
}
?>

Aside from the generating and verifying hashes, it also allows you to generate random tokens. A sample use case would be when users request for their password to be reset. That’s commonly done by sending an email to the user. That email contains a link with a query parameter on it which has a random string as its value. That string is the token. Which is used for fetching the password reset request that was saved in the database.

1
2
3
4
<?php
$token = $lib->getRandomToken(35);
echo $token; // Mpe/H3oLamOqEV4uxTwu.fuhKpb5p/u4BMu
?>

zxcvbn-php

zxcvbn-php is a library for estimating password strength.

You can install it by executing the following command.

1
composer require bjeavons/zxcvbn-php

To use the library, make use of the ZxcvbnPhp\Zxcvbn namespace.

1
2
3
<?php
use ZxcvbnPhp\Zxcvbn;
?>

You can then determine the password score by calling the passwordStrength method.

1
2
3
4
5
6
<?php
$zxcvbn = new Zxcvbn();
$password = 'mypassword';
$strength = $zxcvbn->passwordStrength($password);
echo $strength['score'];
?>

Based on my testing, it returns 0 if the password is not secure or easy to crack. And return 4 if it is secure. I haven’t found any values between those and there’s nothing higher than 4 so I assume it can only return a score of either 4 or 0. The result contains other data as well. Things like the entropy, calc_time and crack_time.

GenPhrase

Lastly, we’re going to take a look at GenPhrase. This library allows us to generate secure passphrases in PHP.

To install GenPhrase, execute the following on your terminal.

1
composer require genphrase/genphrase

One note about the installation though. It’s also mentioned in their official Github project page. It mentioned that GenPhrase should be obtained only via secure connection using Github. This is because Composer is susceptible to man-in-the-middle attacks. If you’re just testing, it’s fine to install this library via composer. But if you’re following this tutorial to implement this library on a production server then think again. You’ve been warned.

To use GenPhrase, create a new instance of the Password class under the GenPhrase namespace. Then call the generate method to generate the random passphrase.

1
2
3
4
<?php
$gen = new GenPhrase\Password();
echo $gen->generate(); // Slum treble Boost rack
?>

You can also pass the entropy) as an argument. By default the value is 50. But you can have a value between 26 and 120.

1
2
3
<?php
echo $gen->generate(60); // soviet!Retain8skinny&spoil
?>

Conclusion

That’s it! In this tutorial you’ve learned how to secure passwords in PHP using the Password Compat, phpass, PHP Password Lib, zxcvbn and GenPhrase libraries.

Tools of Trade

| Comments

Every developer has their own set of “go to tools” when it comes to developing applications. Such as the stack, programming tools and libraries that would make specific tasks easier to implement. In this article I’m going to share some of the tools and resources that I usually use in my day to day web development practice.

LAMP

Since I’m running Ubuntu on my machine, I use the LAMP (Linux, Apache, MySQL, PHP) stack for all of my projects. Linux being the Operating System, Apache as the web server, MySQL for the database and PHP for the programming language.

Composer

Composer is a package manager for PHP. It handles the installation of various PHP libraries which can be found at Packagist.org.

Laravel

For medium-sized projects (takes about 2-5 months to build), I use the Laravel framework. And for small-sized (takes about 2 days to 3 weeks to build), I use the Lumen framework which is basically a lightweight version of Laravel. I chose it because of the sheer elegance of code that can be written when using the framework. It also comes with a lot features that I need in most of my projects. Such as database migrations, seeding, routing, templating and easy integration with third-party libraries.

jQuery

They say jQuery is for sissies, but I don’t really mind. As long as the tool works, it doesn’t really matter. jQuery is basically the all in one solution for all my JavaScript needs. It makes it easy to select and manipulate the elements in the page, listen to events and make AJAX requests. I haven’t done a web project where I didn’t need jQuery.

Sublime Text

My text-editor of choice, though I admit that I’m still using an unregistered copy. So I still see the purchase pop-up every now and then. Though I have plans to buy a license in the future. But as they say “someday I’ll buy a sublime text license but today isn’t that day”. What I liked with Sublime Text is that it makes writing code faster. You can also install plugins which integrates with other programs such as JSHint or Git.

Git

Most developers today are using Git, probably because of Github. But that doesn’t really matter. Git is an awesome software by itself, even without Github. For the uninitiated, Git is a version control software which allows you to make snapshots of your project so that you can easily revert later or share your changes to your team. Github on the other hand, is a web based Git repository hosting service with lots of other nice features. Go check it out yourself. But the key takeaway is that Github makes collaboration much easier with the set of tools that it provides.

Cordova

Ocassionally I get mobile app development projects. This is where Cordova comes in handy. It basically makes it easier to develop apps for any of the platforms (Android, iOS, Windows, etc.) that it supports by making use of web technologies (HTML, CSS, JavaScript). Access to native device APIs are also provided by making use of plugins.

Bootstrap

I admit, I’m not a designer and my CSS skills could certainly improve. Making things pretty isn’t really my forte. That’s why front-end frameworks such as Bootstrap really helps. It keeps my mind off making things pretty so I can just concentrate on the functionality.

Chrome/Chromium

The main browser that I use for testing the web applications that I build. The developer tools is what really makes it shine. It’s interface is really intuitive and easy to use. Almost every aspect of your web application can be inspected and tested by using their developer tools.

Skype

Since I’m mostly working remotely, there’s a need for exchanging messages and making calls. Skype helps me with that. It’s also cross-platform, so I can install it no matter what machine I’m using. Recently they also released Skype for web which makes things even more easier.

Bitbucket

Bitbucket is another Git repository hosting service. Well there’s already Github, but the thing is you can only have public repositories on Github. Bitbucket on the other hand allows you to have private repositories for free. That’s pretty much the only reason why I used Bitbucket. I need my projects to be private so I use it instead of Github.

Node.js

If a project calls for real-time functionality such as chat applications, nothing beats Node.js. It provides an event-driven architecture and a non-blocking I/O API. This allows real-time applications to be built with ease.

Socket.io

Socket.io is a library that makes it easy to build real-time applications. It’s often used in tandem with Node.js.

Virtualbox

If a project requires me to test on a different platform and browser such as Internet Explorer or Safari on Windows. I usually use Virtualbox. I guess I don’t really have much of a choice. Other than Virtualbox, I’m not really aware of any other software that can virtualize an OS.

AWS

Amazon Web Services as the name suggests is a collection of Web Services offered by Amazon. I only use ec2 (elastic compute cloud), s3 (simple storage service) and cloudfront (CDN) though. The cool thing about their web services is that they’re tightly integrated with each other. Which means that you can easily use s3 within an ec2 instance without having to do much of the setup. They also provide an API which can be used to programatically upload files to their servers.

DigitalOcean

Recently I also started using Digitalocean for my personal projects. Mainly because its very affordable (only $5 a month for the lowest tier) and easy to resize (I can upgrade or downgrade any time).

Carbon

Carbon is a PHP library for working with dates.

Moment

Basically the Carbon equivalent for JavaScript. The nice thing is that you can use it on both the client-side and server-side (node.js).

Intervention Image

When there’s a need for image processing in a PHP application, I always grab intervention image through Composer. Resizing, cropping, blurring, change orientation, optimizing, name it and intervention image has it. But what hit the jackpot is that it works nicely with Laravel without having to do much setup.

Twig

Blade is the default templating engine used by Laravel so I use that without having second thoughts. But whenever I work outside Laravel, I have to use something like Twig to handle my templating needs.

Handlebars

My templating engine of choice when I’m using JavaScript.

Mandrill

Whenever I need to send out emails from an application, Mandrill is the tool of choice. Its a no-brainer since Laravel makes it easy to send emails using services such as Mandrill.

Faker

As programmers we all love automating things. Faker does exactly that. It generates fake data for you so you don’t have to enter it manually through the application that you’re building.

Dropzone

Dropzone is my file upload libary of choice. It’s easy to get started using it. But it also makes it easy for developers to customize.

Stripe

Whenever a project needs to accept payments from its users, Stripe is my service of choice. I’m not really confident enough that I’d be able to implement a payment system which is safe from every hacker. Just the thought of saving the hash of credit card numbers on a database sends shivers to my spine. Stripe takes that fear away. I know the guys at Stripe know their stuff.

Paypal

For simple payment needs, Paypal is the tool. And BTW, this is also how I receive payments. It integrates with almost every bank on the planet so you can easily withdraw your money using your bank of choice.

Twilio

Whenever there’s a need for voice enabled apps or SMS verification, nothing beats Twilio.

Guzzle

“No man is an island”, the same is true with web applications. More often than not, you’ll find the need to integrate with third party services. That’s where Guzzle comes in, it’s a PHP library for making http requests. If the API that you’re working on doesn’t already come with a library for making requests, then Guzzle is for you.

thujohn/pdf-l4

For applications that require printing of reports. Thujohn’s pdf-l4 library does it.

Datatables

If an application requires searching or paginating through a table of data, datatables does the trick. What’s great is that there’s also a datatable library for Laravel 4 which makes it easy to integrate to a Laravel project.

Beanstalk

Beanstalk is a queue system. You basically use it for running time-consuming tasks such as sending out emails or processing images. There’s also a library called Pheanstalk which makes it easy to work with Beanstalk for queueing tasks.

Elasticsearch

I use Elasticsearch if there’s a need for fast searches. Elasticsearch if a full-text search server that is based on Apache Lucene. It works with

schickling/laravel-backup

Any decent developer would implement a database backup and restore functionality for each of the applications that they build. For Laravel developers, the laravel-backup library is one choice. It allows you to easily backup your database on a folder in the server or in an Amazon s3 bucket.

Cron

We all know Cron. It’s the thing that we use whenever we need to execute something at specific intervals.

Express

Express is a framework for Node.js. From their website itself: “Express: Fast, unopinionated, minimalist web framework for Node.js”. It handles routing and serving of static files. That’s all it really does but you can easily install third-party libraries for talking to the database or handling views and you wouldn’t have any problem. Its unopinionated so you can do whatever the fuck you want and it won’t complain.

Picnic CSS

Recently for some of my personal projects, I used picnic css. Think of it as a lightweight bootstrap. It makes your UI beautiful without all the cruft that usually comes with bootstrap. It’s also modularized into a set of plugins. So you can just include the plugins that you need.

Conclusion

In this article you’ve learned about some of the tools that I usually use in my projects. What about you? What are your “go to” tools when it comes to developing applications?

How to Get the Logo of Any Company

| Comments

In one of my previous projects called StockSwitch, I had the need to fetch and utilize the logo of companies that are included in the NYSE, NASDAQ, and AMEX. In this article, I’ll be showing you how you can get the logo for any company so that you can use it in your projects.

The best way to get the logo of any company is via Clearbit’s logo API. All you have to do is replace the value of {DOMAIN-NAME} with the domain name used by the company that you want.

1
https://logo.clearbit.com/{DOMAIN-NAME}

For example, you want to utilize Google’s logo in your project. Simply create a new image tag and link to logo.clearbit.com followed by the domain name.

1
<img src="https://logo.clearbit.com/google.com">

You can also pass in the following optional parameters.

  • size – the size in pixels of the logo. The highest value I found to be valid is 800px. And the lowest is 5px.
  • format – you can pass either png or jpg.
  • greyscale – pass in a value of true if you want the logo to be in greyscale.

For example, you want the image to be in 50px and the format is png.

1
<img src="https://logo.clearbit.com/google.com?size=50&format=png">

You can also save it on your own server so you don’t use Clearbit’s resources every time the company logos are requested. Here’s a sample code on how you might do it in php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$companies = array(
    'facebook.com',
    'google.com',
    'oracle.com',
    'amazon.com',
    'ebay.com',
    'uber.com',
    'twitter.com',
    'github.com'
);

foreach($companies as $company){

    $url = "https://logo.clearbit.com/{$company}?size=150&format=png";
    $contents = file_get_contents($url);
    file_put_contents('logos/' . $company . '.png' , $contents);

}
?>

The code above gets the contents returned from the clearbit logo URL and then saves it to the logos directory in the server.

Introduction to Pokeapi-json

| Comments

Welcome to yet another post about a side-project of mine. This time it’s a totally useless project. It’s called pokeapi-json. As the name suggests, its the JSON version of the pokeapi project. If you check their Github page, the data is basically in csv format. The only real difference is that I’m using JSON on my project. Which is pretty much the same way they’re serving the data on the pokeapi website. That’s really all there is to it to this project. I had fun watching as my hard drive gets filled up by 6000+ Pokemon descriptions from different games. I had fun seeing the cute little Pokemon sprites filling the directory that I specified. Here’s a screenshot:

Pokemon sprites

Very cute right? There’s a sense of achievement just seeing all 718 Pokemon sitting in a directory in your hard drive.

But I’m not satisfied with this yet. I’m planning on creating my own Pokedex app which has all the Pokemon data one can imagine. Currently there are 2 awesome Pokedex app out there:

I’m planning to create something much more awesome.

I’ll probably need to scrape the following websites in order to get every possible information about Pokemon.

I know it’s not going to be easy but I’ll try to do it for the love of Pokemon.

Quick Tip: How to Setup Virtual Hosts in Ubuntu

| Comments

In this quick tip I’ll show you how you can setup virtual hosts for Apache in Ubuntu.

The first thing that you need to do is clone the default Apache configuration. In the example below myproject.dev is the virtual host name that you want to use.

1
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myproject.dev.conf

Open the new configuration file and update the values for the ServerName, ServerAlias, and DocumentRoot. Where ServerName is the virtual host name and the ServerAlias is the www version. The DocumentRoot is the absolute path to the directory where your project is stored.

1
2
3
4
5
6
7
<VirtualHost *:80>
        ServerName myproject.dev
        ServerAlias www.myproject.dev

        ServerAdmin wern@localhost
        DocumentRoot /home/wern/www/antares-backend
</VirtualHost>

Next, enable the new virtual host configuration.

1
sudo a2ensite myproject.dev

Lastly, add it to the hosts file.

1
sudo nano /etc/hosts
1
2
127.0.0.1       antaresapp.dev
127.0.0.1       www.antaresapp.dev

Introduction to Grade Viewer

| Comments

As a teacher I want to show my students what grades they’re getting. And the common tool for recording their scores is a spreadsheet. This would automatically compute their grade based on the scores they got from each of the activities. If you have already worked with a spreadsheet before, you might already know that its hard to present it to another person. Because you have to scroll horizontally in order to view every thing. And since the total score for an activity is located at the top row, so you also have to scroll to the top whenever they want to see the total score. To put it simply, the eye of the viewer has to move a lot. Not to mention, they will see the grades of their classmates as well. So directly showing the grades in the spreadsheet is really a no go.

Luckily I can actually program things. That’s why I built Grade Viewer. This allows me to upload an excel spreadsheet, then specify the range that I want to target.

new subject

Then I enter the activities done for each component (lecture and laboratory) of the subject.

activities

Once that’s done (provided I have specified every thing correctly) I can now go to the dashboard and click on the view grades link.

dashboard

This will list out all the subjects that I’ve currently added. From here I can click on the update link to update the excel file and the settings. Or the view link to view the grades.

subjects

Here’s what the page for viewing grades looks like:

grades

It has a search feature but it can also navigate with previous and next links. Just below the name of the student is their grade for lecture and laboratory. And below it is the break down. From here, the student can just ask any questions regarding their grades.

Future Plans

Nothing really. The project is in a pretty sweet spot right now when it comes to functionality. But just like many of my side projects, the underlying code has a lot of room for improvement.

Working With Dates and Times in PHP With Carbon

| Comments

When writing PHP applications there’s often a need for working with dates and times. In this tutorial, I’ll be walking you through Carbon, a simple PHP API extension for the DateTime class. It basically makes working with dates and times a lot more easier. I’ve personally used this library on my Ahead project, a Laravel app for scheduling posts to social media sites like Facebook, Twitter and LinkedIn.

Installation

To install Carbon, you need to use Composer.

1
composer require nesbot/carbon

Usage

Include the vendor autoload in your file and then use the Carbon class in the Carbon namespace.

1
2
3
4
5
<?php
require_once 'vendor/autoload.php';

use Carbon\Carbon;
?>

Getting the Current Date and Time

You can get the current date and time using the now method. If you do not specify an argument, it uses the default timezone from your PHP config.

1
2
3
<?php
echo Carbon::now(); //2015-07-26 20:21:20
?>

If you want to use a different timezone, you can pass a valid timezone as the argument.

1
2
3
<?php
echo Carbon::now('Asia/Manila'); //2015-07-26 20:21:20
?>

Aside from the now method, there’s also today, which returns the start of today’s date, yesterday, which returns the start of the date yesterday, and tomorrow, which returns the start of the date tomorrow.

1
2
3
4
5
<?php
echo Carbon::today()->toDateTimeString(); //2015-07-26 00:00:00
echo Carbon::yesterday()->toDateTimeString(); //2015-07-25 00:00:00
echo Carbon::tomorrow()->toDateTimeString(); //2015-07-27 00:00:00
?>

Converting to String

By default, methods in Carbon returns a datetime object. Though its an object, you can directly output it using echo because of the __toString magic method. But if you want to convert it to a string, you can use the toDateString or toDateTimeString methods.

1
2
3
4
<?php
echo Carbon::now()->toDateString(); //2015-07-26
echo Carbon::now()->toDateTimeString(); //2015-07-26 20:22:50
?>

Parsing Dates

You can also parse dates in all sorts of formats using the parse method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
echo Carbon::parse('2015/03/30')->toDateTimeString(); //2015-03-30 00:00:00
echo Carbon::parse('2015-03-30')->toDateTimeString(); //2015-03-30 00:00:00
echo Carbon::parse('2015-03-30 00:10:25')->toDateTimeString(); //2015-03-30 00:10:25

echo Carbon::parse('today')->toDateTimeString(); //2015-07-26 00:00:00
echo Carbon::parse('yesterday')->toDateTimeString(); //2015-07-25 00:00:00
echo Carbon::parse('tomorrow')->toDateTimeString(); //2015-07-27 00:00:00
echo Carbon::parse('2 days ago')->toDateTimeString(); //2015-07-24 20:49:53
echo Carbon::parse('+3 days')->toDateTimeString(); //2015-07-29 20:49:53
echo Carbon::parse('+2 weeks')->toDateTimeString(); //2015-08-09 20:49:53
echo Carbon::parse('+4 months')->toDateTimeString(); //2015-11-26 20:49:53
echo Carbon::parse('-1 year')->toDateTimeString(); //2014-07-26 20:49:53
echo Carbon::parse('next wednesday')->toDateTimeString(); //2015-07-29 00:00:00
echo Carbon::parse('last friday')->toDateTimeString(); //2015-07-24 00:00:00
?>

Constructing Dates

You can also construct dates by using individual parts such as the year month and day.

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$year = '2015';
$month = '04';
$day = '12';

echo Carbon::createFromDate($year, $month, $day); //2015-04-12 20:55:59

$hour = '02';
$minute = '15':
$second = '30';

echo Carbon::create($year, $month, $day, $hour, $minute, $second); //2015-04-12 02:15:30
?>

Optionally, you can pass in any valid timezone as the last argument for the create and createFromDate methods.

Manipulating Dates

Manipulating dates can be done by using add (to add) or sub (to subtract) followed by the unit of time you want to add or subtract. For example, you want to add a specific number of days to the specific date, you use the addDays method. There’s also the modify method which allows you to pass in the modification that you want. It takes the format of + or - followed by the unit value and the unit. So if you want to add a year to the current date, you use +1 year. Check out the examples below to have an idea what else you can do.

1
2
3
4
5
6
7
8
9
<?php
echo Carbon::now()->addDays(25); //2015-08-20 21:10:00
echo Carbon::now()->addWeeks(3); //2015-08-16 21:10:00
echo Carbon::now()->addHours(25); //2015-07-27 22:10:00
echo Carbon::now()->subHours(2); //2015-07-26 19:10:00
echo Carbon::now()->addHours(2)->addMinutes(12); //2015-07-26 23:22:00
echo Carbon::now()->modify('+15 days'); //2015-08-10 21:10:00
echo Carbon::now()->modify('-2 days'); //2015-07-24 21:10:00
?>

Commonly in PHP apps are international. This means that you need to work with different timezones. Here’s how to convert from one timezone to another.

1
2
3
<?php
echo Carbon::now()->setTimezone('America/Los_Angeles'); //2015-07-26 06:23:48
?>

Comparing Dates

You can use the following methods to compare dates in Carbon.

  • min – returns the smaller date.
  • max – returns the larger date.
  • eq – check if two dates are the same.
  • gt – check if the first date is greater than the second date.
  • lt – check if the first date is less than the second date.
  • gte – check if the first date is greater than or equal to the second date.
  • lte – check if the first date is lesser than or equal to the second date.

Other helpful methods include isWeekDay, isWeekend, isYesterday, isFuture and isPast.

Laravel Integration

If you’re on Laravel, you can just add an alias for the Carbon library in the aliases in the app/config/app.php.

1
'Carbon' => 'Carbon\Carbon'

Conclusion

That’s it! In this tutorial, you’ve learned how to work with the Carbon library in PHP. Carbon is a really nice and easy way to work with dates in PHP. Be sure to check out the official docs to learn more about it.