Upgrade to Hexo 3

I’ve use Hexo for a while and deply my blog on Github. Upgrade to Hexo 3 is extremely simple.

  1. Upgrade Hexo command line tool

    $ npm install hexo-cli -g
  2. Update your package.json

    • Basically replace old dependencies


      "dependencies": {
      - "hexo-renderer-ejs": "*",
      - "hexo-renderer-stylus": "*",
      - "hexo-renderer-marked": "*"
      + "hexo": "^3.0.0",
      + "hexo-generator-archive": "^0.1.0",
      + "hexo-generator-category": "^0.1.0",
      + "hexo-generator-index": "^0.1.0",
      + "hexo-generator-tag": "^0.1.0",
      + "hexo-renderer-ejs": "^0.1.0",
      + "hexo-renderer-marked": "^0.2.4",
      + "hexo-renderer-stylus": "^0.2.0",
      + "hexo-server": "^0.1.2"
      }
    • Add Hexo version This step is very important, your hexo cli wont work if you didn’t add this

      "hexo" : {
      "version" : 3.0.0
      }
  3. Update deployer settings

    • Install deployer first

      $ npm install hexo-deployer-git --save
    • Update deployer config

      -  type: github
      - repository: git@github.com:ryanhanwu/ryanhanwu.github.io.git
      + type: git
      + repo: git@github.com:ryanhanwu/ryanhanwu.github.io.git

It’s done, happy blogging.

Upgrade to Sublime Text 3

Moved all my settings and snippets from Sublime Text 2 to 3, the Sublimelinter is much better, especially for a Node.js developer.

Backup all my settings on Github

Download whole project here

On the other hand, some packages are snippets and syntax highlights (LESS, Jade …etc), some are productivity tools.

Find more details on Package Control.

How to monitor iPhone's HTTP traffic

I usually wonder how my iPhone apps communicate with their servers. I had a debate with my ex-coworker about the security of app communication. He thinks we can use simple HTTP protocol for app communication, including authentication. But I insist that we should use more secure way for transmission in apps.

Let me use an example to demonstrate how little an app protects the content and how easy it is to monitor the traffic of an iPhone app.

According to Apple’s document here. I choose tcpdump and take 7-11 Taiwan app as an example.

This app provides coupon for Starbucks. I want to get the content of this coupon.

The steps are as following :

Using Node.js to redirect and proxy normal HTTP+WebSocket traffics based on hostnames

Usually I used to use a single server to host several developing or experimental projects. Thus I need a quick solution to forward different request to these services. I had tried to use nginx before. But now I have a easier way to do so.

  1. require modules

  2. config proxy(forward) and redirect mappings (hostname based)

    var proxyOptions = {
    router: {
    "api.testAppX.com" : 'localhost:2041',
    "dev.api.testAppX.com" : 'localhost:2042',
    "www.testAppY.com" : 'localhost:10520',
    "test.oldApps.com" : 'localhost:10520',
    'bc.ryanwu.co' : 'localhost:8888'
    }
    },
    redirectOptions = {
    'olddomain.com' : 'http://newdomain.com/',
    'www.olddomain.com' : 'http://newdomain.com/',
    'blog.olddomain.com' : 'http://newdomain.com/blog/'
    };

Best way of singleton in Objective-C

It’s very useful during iOS development

static GeneralData __strong *generalDataObject = nil;
 
@synthesize currentUser;
 
+(GeneralData *) getInstance
{
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        generalDataObject = [self new];
    });
    return generalDataObject;
}

Usage

  1. Add Data

    firstViewController.m
    #import "GeneralData.h";
    
    - (IBAction) passValueButton:(id)sender { 
    {
        User *user = [User new];
        user.name = "Mary Jane";
        user.age = "21";
        [GeneralData sharedInstance].currentUser = user;
    }
  2. Read Data

    secondViewController.m
    #import "GeneralData.h";
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        User *loggedInUser = [GeneralData sharedInstance].currentUser;
        NSLog(@"Name : %@", loggedInUser.name);
        NSLog(@"Age : %@", loggedInUser.age);
        
    }

Reference : StackOverflow

JavaScript number only lock

function(event) {
// Allow: backspace, delete, tab, escape, and enter
if ( event.keyCode == 46 ||
event.keyCode == 8 ||
event.keyCode == 9 ||
event.keyCode == 27 ||
event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) &&
(event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
}

Make UILabel glow

You have to import QuartzCore

#import <QuartzCore/QuartzCore.h>

Then apply effect on your UILabel or titleLabel.

myLabel.layer.shadowOffset = CGSizeMake(0.0, 0.0);
myLabel.layer.shadowRadius = 20.0;
myLabel.layer.shadowOpacity = 0.5;
myLabel.layer.masksToBounds = NO;

Display remote Node.JS service logs on Chrome Console

In recent years, we got plenty of PaaS services which provide very simple and easy way to deploy our Node.JS services.

Usually after deploying my service, I have to use the command line tools or visit some very slow web pages to access the server logs. It’s really waste my time.

But today, I want to introduce a tool, Chrome Logger, it provides a way to display server logs into Chrome Developer Tool’s Console.

Install it, then visit my sample project on Heroku to see what’s going on.

  • Sample Test Project on Github

Update 06/25 00:40:

  • If you’re using ExpressJS, you can simple log your error like following error handling middleware

Update 06/25 01:50:

Pull requests sent : chromelogger & express-chrome-logger.

Good luck to myself.