2016年4月27日 星期三

I want to be a millionaire~~ So freakin' bad~~~

This is not gambling :)

Today I decided to resume one of my old projects: data crawling and mining on the Hong Kong Jockey Club!

From my past experience, it is quite hard to predict the result of a horse race as there are too many variants, such as the horses' and riders'. So I decided to change the subject from horse racing to Mark Fix......

First, let me introduce the "Mark Six" (六合彩):


The concept is like Powerball. There are 49 balls in total. In each draw, 7 balls will be picked random by the machine and one of them is called "special number". To win the first place, you need to guess all 7 numbers correctly. So, we will know the possibility is about 1/85900584 by simple math. 

This time, I will first crawl the data from the official website of Mark Six and then do some data-mining between the data and try to predict the result based on the findings. Except the basic calculations on the possibilities, I will also try to predict it through a neural network by representing the data as a series of binary numbers.

Data Crawling

To crawl the data, I take the advantage of htmlparser2 and shelljs. They are really handy. I do the prototype in a short time as the tools are really easy to use. (That's why I like Javascript very much 🤓) Shelljs will execute the curl commands and pass the standard output to the html parser. Then the parser will generate the database from all possible entries. For now, I just crawled 3000 draws from the site from 1993 to now. That's a special feeling. 🤑

Next, I will start to do the data processing part on python (most likely will use sklearn). Hope that I could be a millionaire somedays~~~


2016年4月24日 星期日

Please, don't cheat on me ...... my dear OPENCV

As I joined a class about the exhibition of digital arts, I get a chance to deal with something really handy about robotics and OpenCV. OpenCV is a power library for the image processing, such as facial recognition and objects detection. My goal for this project is to track a few robots' positions and estimate the velocity and orientations. Then send the information back to the robots and let them interact with "others".

However, I do have a hard time on the installation of the OpenCV. First, I tried to cmake the libraries from the source. But I found that there is a bug for the VideoCapture. Then, I switched to OpenCV 2 with homebrew installations. Soon, I found there are libraries missing in the version 2. That means I have to switch back version 3. Now, I am struggling with the unknown errors emitted in the terminal and tons of retries.

I will update once I got the library working... 😞


2016年4月21日 星期四

What would you do except waiting for luck?

I have tried a very annoying coding challenge yesterday. It's about guessing the random number of the output of Math.floor(Math.random() * 100 + 1). What!? Guessing the number? Even the possibility of doing that is only 0.01. That means you should get it to right in at most 100 trials. However, you know, we are engineers! So, we need a way of engineers to solve this.


Here is the link of the problem and the screenshot of it. ClickMeToTheProblem





Here are some of my trials: (in chronological order)

1. Make the guess to be the var of lucky_number. As expected, it throws out an undefined error because the checking is after executing my code.

2. Guess some numbers.

3. Make the guess to be a function so that it can be get the value of lucky_number later using something like eval('lucky_number').

4. Guess some numbers again ...... :)

5. Make the guess to be a lazy evaluation variable or function so that it can be in the scope of the expected number when it is evaluated.

However, none of these are working because I messed up with the scope. After a few trials, I feel like this problem is unsolvable. Then I tried to look at some discussions. I saw a person asking why the method of changing the kernel random method is not working. It did inspire me. Now, I know the answer ......


Just right before the declaration of my guess, put this magic code:

Math.floor = function (a) {
    return 1
}
var myGuess = Math.floor('hacked it :)')

This question is really interesting and funny to play around. I have spent about 2 hours on this simple question. But I feel like I am leveling up. @@






P.S. I thinking to `open source` this blog plugin which is built in react.js and make it handy for other people to plug in their sites. Let's see.





2016年4月19日 星期二

I am such a bad developer...

Since I arrived U.S., I started my journey of intern finding. After sending a bunch (approximately 30 ~ 40) of emails, résumés, cover letters and application, I received a few app test for me to prove that I deserve it.

This story starts with an app test that I have completed recently. I was told to complete a question on codewars.com. The problem is not that hard actually. Because there are a few different ways to complete it. However, I choose the functional-style to complete it. I dunno why I would do that in such functional style as the problem was asked on Javascript. After 60 minutes of working, I completed it in the last minute.

Here is the question:




The interesting thing about codewars is that I can look at others' solutions so that I can "learn" from them. I will post two answers for this problem underneath and see if you can guess which one is mine ;).

First

function maxSumPath(a) {
  // Your code here
//   console.log(a) 
  var sumList = getSumList(a,
    {
      max: {
        path: '',
        sum: Number.MIN_VALUE
      }
    }, '', 0, 0, 0);
//   console.log(sumList)

  return sumList.max
}

var getSumList = function(inputList, sumList, path, i, j, sum) {
  sum += inputList[i][j]
  // travse the arrays
  if (inputList && i < inputList.length - 1) {
    sumList = mergeMaxObjects(sumList, getSumList(inputList, sumList, path + '↓', i + 1, j, sum))
  }

  if (inputList[0] && j < inputList[0].length - 1) {
    sumList = mergeMaxObjects(sumList, getSumList(inputList, sumList, path + '→', i, j + 1, sum))
  }
  // end condition
  if ((i == inputList.length - 1) && (j == inputList[0].length - 1)) {
    // reach the end, return the object

    // check exist path
    sumList = setMaxProperty(sumList, path, sum)
    // compare the max path
    if (sumList.max.sum < sumList[path]) {
      sumList.max.path = path
      sumList.max.sum = sum
    }

    return sumList
  } else {
    // not the end, return the original list
    return sumList
  }
}

var setMaxProperty = function (obj, key, value) {
  if (typeof obj[key] !== 'undefined') {
    // exist a record
    if (obj[key] < value) {
      // set if sum is greater than the record
      obj[key] = value
    }
  } else {
    obj[key] = value
  }
  return obj
}

var mergeMaxObjects = function (obj1, obj2) {
  for (var path in obj2) {
    obj1 = setMaxProperty(obj1, path, obj2[path])
  }
  return obj1

}

Second

function maxSumPath(a){
    var p='',s=0,r=0,c=0,t=a.map(x=>x.slice()).slice();
    for(var i=0;i<t.length;i++)
        for(var j=0;j<t[i].length;j++)
            t[i][j]+=Math.max((t[i+1]||[])[j]||0,(t[i]||[])[j+1]||0);
        while(r<a.length&&c<a[r].length){
            s+=a[r][c];
            if(((t[r+1]||[])[c]||0)<((t[r]||[])[c+1]||0))
                [p,c]=[p+'→',c+1];
            else if(((t[r+1]||[])[c]||0)>((t[r]||[])[c+1]||0))
                [p,r]=[p+'↓',r+1];
            else break;
        }
    return {path:p,sum:s};
}



How's the guess @@?



Yes, the first one. Such long and unclear coding compared to the second one which is small and clean. (But I think it is a bit de-human. I thought it was the result of minifying.) Anyway, you can see how bad style I code......

This story can tell that I may be not that ready for an internship here. So, I should head back my home and find an internship for my next summer (?).




P.S. hope that I can at least get an interview!!!

2016年4月17日 星期日

Joining the family of React!

After attending the online course of React JS fundamentals, I added this blog component to this site using React JS. Here are some of my feelings toward React JS:

1. JSX is not a big deal
- Some people are arguing if we should put the html-like code, JSX in the javascript. I don't feel that this is a big deal as it is just like splitting the components up. The only I have to get used to is that some keywords are changed for the sake of reversed keywords of Javascript, like "class" and "className".

2. Ready for Single Page Application (SPA)
- As the library will pack the all the components into a single js file, this blog page can only include a single js library to sustain for the while blog application. The transitions between pages are purely powered by javascript (react-router) which can boost up the performance and keep track the whole state of the app.

P.S. actually, this is also a test post for the blog feature. 😏

2016年4月16日 星期六

"Hello World!"

Hello there! The first blog post is here!
As I am a "developer", I need to follow the tradition to say "Hello World" to all of you.

Actually, this blog is made for the plugin on my personal site. Thus, I will try different kinds of tags to test with the API of Blogger. See you on the other side!

I am bigger text.

I am colored text.

Here are my friends: bolditalicunderlinestrikethroughlink and highlight.

I am centered text.


a picture

a video