Blog

$ less blog.txt
This page is still kind of buggy with the pagination and format. If you prefer, see an archive of all of my blog posts.

Equality and Inequalities in JS and PHP

2015-02-26

It’s 2015, and from time to time I still see a lot of == peppered throughout codebases that I work with, and just wanted to share a few posts that might change your mind =)

tl;dr;

=== and its complement !== and should be used like 99% of the time because it is faster and more accurate.

> 0 == "0"
< true
> 0 === "0"
< false
> 0 == false
< true
> "0" == false // really?
< true
> !!"0"
< true
> !"0"
< false
> "0" === false
< false

There are more perverse and mind-bending examples that are out there, but I’ll leave you with those for now.

As you can see, the former == does type coercion, which is lazy way of doing comparisons without casting data explicitly, and can find yourself in hot water down the line. The latter === does type checking first, and then checks equality of the values.

Protip #1: If you want to test a JS expression or figure out some syntax really quickly, just open your JS console in the browser inspect tool.

Protip #2: If testing for something truthy or falsy, a nice trick is to just do use the ! operator twice (!!). As can be seen above, JS treats non-empty strings as a truthy (yet, strangely, "0" == false)

WordPress' New JetPacks All-Sites Dashboard

2014-12-16

The JetPacks 3.3 upgrade that allows you to manage and administer multiple WordPress sites from one WordPress.com account is a breeze to use!

I’m not quite used to it yet and still getting acclimated, but I think it’s a great time-saver and will grow on me more over time.

I can see it as a great feature to use once a site for daily workflows in updating content once a site’s major structural and design work has been done.

Cheers to the WordPress team for this great feature!

Read all about it in the original post.

Upgrading to Ubuntu 14.04.1 LTS

2014-09-06

tl;dr; When upgarding from Ubuntu 12.04 to 14.04 LTS, the Apache also gets upgraded from 2.2 to 2.4. There are lots of backwards incompatible changes.

I just spent the last 3 hours fixing my server after impulsively upgrading to Ubuntu 14.04.1 LTS from Ubuntu 12.04.

Well, not exactly that impulsively. I had seen this pestering MOTD-style message upon login for weeks now, and I figured that since 14.04.1 is a point release nearly 6 months after the initial release, it should be relatively issue-free.

I had already done 3 upgrades from 12.04 LTS to 14.04 LTS… on desktops. Two had gone successfully, and one on my parents’ computer unfortunately messed up pretty badly in the middle so that some of the ubuntu-desktop stuff is just not working properly, but I digress.

I figured that since it was a Friday night in addition to the above–“What the heck, why not?”–and dove right in. The OS upgrade was pretty much issue free. I let out a sigh of relief.

And then my luck ran out. All of my websites didn’t load. Read: Nothing worked. I started getting Pingdom pages and Nagios alerts non-stop.

Thankfully, the Internet is a great resource and I was able to identify the problem pretty quickly. Applying the fix is what took most of the time.

Most useful of all the resources that I came across was Upgrading Apache 2.2 to 2.4. I’d recommend reading through it thoroughly if you’re going through the upgrade yourself, but here are some highlights:

  • Don’t be alarmed if all you’re seeing for any of your websites is just the contents of /var/www/ or /var/www/html
  • All separate virtual host (VirtualHost) files and configurations need to end in *.conf due to the command in /etc/apache2/apache2.conf IncludeOptional sites-enabled/*.conf
  • It still wasn’t pulling in my VirtualHost
  • Got rid of NameVirtualHost *:80 as the first line in all of my VirtualHost config files. It wasn’t necessary. Good riddance.
  • Directory permissions now need to be explicitly granted. Require all granted (the old style was Order Deny, Allow; Allow from all)
  • I noticed that my websites were loading slowly, so needed to set EnableSendfile On in the main config file (apache2.conf)
  • For my Django sites, I needed to change the Directory permissions for the static files directory
  • For my custom WordPress sites, I needed to set the Directory permissions for the DocumentRoot as well as explicitly set AllowOverride all to allow picking up the .htaccess
  • /etc/php5/apache2/php.ini has short_open_tag disabled. I decided to leave it off and change my limited number of PHP applications that were using short open tags, because it’s better practice.

Other helpful resources:

Use Intel Hardware Acceleration for Faster Android Emulation

2013-09-20

tl;dr;

If this is you:

  • Android developer with an Intel-based computer
  • Sick of dealing with a slow emulator

Then:

I never knew this, and thought that I was doomed to a slow emulator or had to debug and deploy over a constantly plugged-in device, which could at times be inconvenient.

Thanks to the guys at CodePath (@thecodepath) for this useful tip! If you’re interested in learning iOS or Android, definitely check them out.

Finally! A mobile school for engineers

2013-09-12

Got an email today about a new Android training program starting up in SF for engineers. Best of all, it’s free!

I’m definitely going to check them out and try to sign up.

Update (2013-09-15): If you’re unable to attend the class, they may have a “course observer option where you will have access to all the materials for the class, but you just won’t participate in the live classes, discussion forums, or the group projects.”

Jonathan,

I’m a co-founder of CodePath, a startup that runs iOS and Android training programs. We’ve trained hundreds of engineers at Yahoo who are moving from web development to mobile development.

We’re offering the same training program to engineers in the bay area for free. It’s a project-based course, meets twice a week for 6 weeks, and the next class begins on October 2nd (another one starts in January). It’s an intensive program, but we’ve seen great results with it.

We’re currently accepting engineers with a technical degree OR at least two years of object-oriented programming experience. If you’re interested, sign up here:

Please forward to any engineers or mailing lists that might be appropriate, additional details below.

Tim

Additional Program Details

This is an evening bootcamp meaning that all sessions are held after work hours and all of the bootcamp projects can be done after hours and on the weekends. Here’s a summary of what you need to know:

  • Free of charge for engineers
  • We will select up to 30 applicants for each cohort
  • 6-week evening bootcamp starting Oct 2nd
  • 2 on-site sessions each week in the evening (instruction and lab, 7-9 pm)
  • Sessions held at Zynga SF office at 8th and Brannan
  • A mini-app is built each week (5 total projects)
  • Group project designed and developed over 6 weeks

Here are the requirements for the course:

  • Physically present in San Francisco and available Mon+Wed from 7-9 pm during sessions
  • Technical (CS, EECS) Degree and/or 2 years of professional software development experience
  • 8-10 additional hours every week to dedicate to projects and collaborative learning
  • Existing development experience with object-oriented languages
  • Passionate about learning and collaborating on mobile projects
  • Laptop with Mac OS X (iOS, Android) or Windows (Android)

Read more details about this program and us here and on our website at http://thecodepath.com. Also, you can follow us on twitter at @thecodepath for future updates!


Make a Donation