Customizing Google Calendar Colors

<iframe src="/gcalendar-wrapper.php?src=[google calendar embed url here]" style="border: 0" width="100%" height="600" frameborder="0" scrolling="no"></iframe>

Go to and get the embed code

Hover to your calendar and click the arrow down symbol. Then click Calendar Settings.
You can find the embed code in Calendar Details

Download the file here

Require All Application to use SSL

public class FilterConfig
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        filters.Add(new HandleErrorAttribute());
        filters.Add(new AuthorizeAttribute());

        //require application to use SSL
        filters.Add(new RequireHttpsAttribute());

After that, we need to update project url. Right click on project > properties > web and update Project Url like https://localhost:44331/

Content Delivery Network or CDN

CDN is a network of servers to deliver resources to its nearest users.

When a website is using CDN, any user trying to access its resources will pass through CDN network. The nearest server that has the requested resources will deliver it to the user. Faster load speed.

Since the request didn’t even reach to the server, there’s reduced load to the server making it available to more users.

Below is an example, is hosted in x.x.x.x server

Without CDN


Tracing route to [x.x.x.x]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms
  2     1 ms     2 ms     1 ms
  3     1 ms     2 ms     2 ms []
  4    14 ms    14 ms    14 ms []
  5    13 ms    13 ms    13 ms []
  6    31 ms    31 ms    31 ms
  7    35 ms    35 ms    34 ms
  8    77 ms    34 ms    34 ms []
  9    84 ms    83 ms   100 ms []
 10    80 ms    80 ms    80 ms []
 11    83 ms    83 ms    83 ms
 12    84 ms    84 ms    84 ms []
 13    84 ms    84 ms    83 ms []
 14    84 ms    84 ms    85 ms []
 15    80 ms    80 ms    80 ms
 16    80 ms    81 ms    81 ms  x.x.x.x

Trace complete.

It took 16 hops for my request to reach original server

With CDN


Tracing route to [cdn ip address here]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms
  2     4 ms     2 ms     1 ms
  3     2 ms     1 ms     1 ms []
  4    15 ms    14 ms    14 ms []
  5    14 ms    14 ms    14 ms []
  6    14 ms    16 ms    14 ms
  7    14 ms    15 ms    14 ms  [cdn ip address here]

  Trace complete.

It only took 7 hops to reach using CDN and no request was made to its original server. So faster content delivery and reduced load to the original server.

.htaccess redirect http to https

#check if https is off
RewriteCond %{HTTPS} off
#if the condition above is true, apply this RewriteRule 
#it redirects http to https with 301 or permanent redirect
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#the code below will redirect all domain's non-www to www
#[NC] for case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note: Search engines treat non-www and www sites as different sites, so for SEO purposes, select either www or non-www version of your site and do permanent redirect to the other site to avoid duplicate content

Parsing WordPress RSS Feed

Tested in content types

$url = '';
$feed1_xml = simplexml_load_file($url) or die("feed not loading");

To get the first post title
echo $feed1_xml->channel->item[0]->title;

To get the first post published date
echo $feed1_xml->channel->item[0]->pubDate

Returned date is in this format Wed, 20 Apr 2016 04:22:10 +0000
You can also convert it to ‘Y/m/d’

New Custom Post Type is not working

-rw-r--r-- 1 user members 842 3月 8 18:21 single-about.php
-rw-r--r-- 1 user members 842 3月 8 18:36 single-course.php

I already have an existing custom post type “about”. It’s loaded using single-about.php
I added new custom post type “course” and copied single-about.php content to single-course.php but the new post under “course” custom post type cannot be viewed.
And there’s also no sign that single-course.php is used.

The solution was to flush rewrite, you can do this by going to Settings > Permalinks and just hit Save Changes and everything works as expected after that.

Adding Roles in ASP.NET MVC 5

//UserStore & RoleStore
//UserManager, RoleManer and SignInManger

var roleStore = new RoleStore(new ApplicationDbContext());
var roleManager = new RoleManager(roleStore);
roleManager.Create(new IdentityRole("Role1"));
UserManager.AddToRole(user.Id, "Role1");

Note: UserManager.AddToRole(user.Id, "Role1")
will add record to AspNetUserRoles but not the cookie. Later when we check the role using
The above code will return false because it checks the cookie. We need to re-signin the user to update the cookie
SignInManager.SignIn(user, false, false);
Identity information like roles and claims are stored in the cookie when user logs in.

Adding Global Filters to ASP.NET MVC 5

In App_Start > FilterConfig.cs
public class FilterConfig
  public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    filters.Add(new HandleErrorAttribute()); //redirects the user to error page when an actions throws an exception
    filters.Add(new AuthorizeAttribute()); //all controllers will require authentication so we don't have to add [Authorize]

Sublime Text 3: Adding Auto-Fortmat Hotkey

In Sublime Text menu, Preferences > Key Bindings – User add the code below inside []
{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}
Re-open Sublime Text editor and press ALT+SHIFT+F to format texts