Saturday, August 13, 2016

Introduction (Methods of Proof, Algorithms and Data Structure)

As an introduction to this course, we'll learn about different methods of proof, algorithms and data structures. This is when you'll start seeing computer science less on the computer (hardware, tech-stuff) side but more on the math, computing aspect of it.

These things are the ones that draw the line between computer scientists and self-thought programmers. Learning how to code alone could land you a job but knowing the basic principles is another thing. Yes, you may not have a winning card against those programmers (as real world opportunities are almost the same for both), the learning will let you appreciate your craft more. ^.^

Lesson Outline

Monday, March 21, 2016

Workaround on How to "Save and Render" Emojis

I've came up to this problem of sending marketing emails that contains emojis in the subject ('cause yeah, emojis can be eye-catching, inducing users to open and read the email).

This marketing emails are stored in the database with all the info needed including the subject to be used. Upon sending, these details are to be fetched from the database.

The problem is that the database uses utf-8 character set whereas utf8mb4 is needed to support emojis. I have to implement this preferably without changing the encoding of the database, if possible.

So I've come up to this hackish trick of encoding the subject first before saving it to the database. Then just decode it in the application layer, if necessary.

In my case, since I use mb_encode_mimeheader(), I don't even need to decode it upon sending the email. I can just use it as is and this will be rendered properly by email providers.

Emojis in Email Subject

If you need to display/render the emojis back to the user, simply decode it.

The only drawback I could think of is when you try to query the data directly from the database. If you use the db records directly to track stats or something, that would be difficult. But anyway, emojis are supposed to be part of texts (e.g. message content, comment, etc.) which most of the time aren't the data scientists' subject. But in case it is, or you just really need to store the emojis unencoded, you'll then have to change the database character set to utf8mb4.

Wednesday, March 9, 2016

How to Redirect Post in an Old Blogspot Domain to a New One

Few months back, I changed one of my blogs' domain to a new one. Right after changing the domain, I created another blog using the old domain so I still own that subdomain.

Recently, I received an email from Google Web Master Tools that I'm my old site has receiving a lot of soft 404's lately, meaning a lot of people are accessing my posts using the old domain that were indexed by Google.

Hence, I got the idea of redirecting the users when they access the old domain to the corresponding blog post in the new domain.

Here's the very simple trick.
  1. Go to your Blogger dashboard
  2. Go to Template and click the Edit HTML button.
  3. In the template code displayed in the textarea, look for the <head> tag.
  4. Add this very simple JavaScript code inside the head tag. 

<script type='text/javascript'>
  location.href = 'newdomain.blogspot.com'+window.location.pathname;
</script>


Basically, you just have to append window.location.pathname to your new domain so old posts can be mapped to their new address.

And viola, it redirects now!



The graph has been flat straight since I made the changes.