2021-03-26T02:35:47+00:00 http://yjyao.com Yujian Yao Copyright (c) Yujian Yao 2012-2021 A quick example of async/await 2019-04-20T00:00:00+00:00 http://yjyao.com/2019/04/typescript-async.html/ Note: all the code in this post is in TypeScript. Suppose we want to implement the following function: function retry<T>(action: () => Promise<T>, n: number): Promise<T> such that it performs the action and retrieves the value and retries up to n times, if the action fails. Had action been a synchronous function, it may be natural to use a for loop, which is easy to write and pretty readable. But we can’t use a for... Add some colorful cowsay to your terminal 2014-09-20T00:00:00+00:00 http://yjyao.com/2014/09/colorful-cowsay-in-your-terminal.html/ So I often get asked about my terminal because it’s a little bit flamboyant: So today I am going to write about how this can be achieved. Here’s the tools that you need: cowsay, fortune, gshuf and lolcat. cowsay, fortune and gshuf are binaries so depending on your OS, you can use your package manager to install them. lolcat is a ruby gem so you will need to install ruby first, then do you usual... Markmon - a fast markdown previewer 2013-12-15T00:00:00+00:00 http://yjyao.com/2013/12/markmon-a-markdown-previewer.html/ Github link If you use markdown often, chances are that you also use some sort of markdown previewers. Unfortunately, most of them simply generate the HTML and refresh the content when there’s an update - which is fine for a lot of use cases, but not when you need to do some post-processing like MathJax. So I built markmon which focus on improving the re-rendering speed. The problem with refreshing page is that it will... Hearts with POMDP 2013-12-11T00:00:00+00:00 http://yjyao.com/2013/12/hearts-with-pomdp.html/ This project is hosted on Github Also try here: http://hearts.yjyao.com Hearts is one of the few card games that I know how to play, thanks to Microsoft Windows and the countless boring hours. So based on what I have done Gomoku and solitaire, it seems natural to fuse the two and write a hearts card game with AI. It turns out that Hearts is a lot trickier than the simple Gomoku - it’s multiplayer and... Web Daemon - Pin Websites to Menubar 2013-06-14T00:00:00+00:00 http://yjyao.com/2013/06/web-daemon-pin-websites-to-menuber.html/ This project is hosted on Github This is a convenient Mac app I made quite some time ago. The idea is based on my previous app treb, but this time it is Mac only and not Qt-based cross-platform, because I found Qt Webkit to be rather inadequate. Anyway, Web Daemon allows you to pin ‘small versions’ of websites into your status bar. You can pin as many as you like, so long as your menubar... NUSMorge and My First Hackathon 2013-02-27T00:00:00+00:00 http://yjyao.com/2013/02/hack-and-roll.html/ I had my 24-hour hackathon from this Sunday to Monday. Really great experience. Stayed up all night long coding non-stopped and produced something that actually works. Take a look at my github profile page - there were 108 commits during that period! This is kind of funny because it is exactly half the number of commits I have pushed in a year. Working in a team of four was also great. I don’t have to... Shuffling Cities 2012-11-30T00:00:00+00:00 http://yjyao.com/2012/11/shuffling-cities.html/ So I am currently interning at NonStop Games, an awesome startup that focuses on mobile and social gaming using HTML5 technology and node.js. And here’s an image about an ultra-secret project we are currently working on: Anyway, recently I was assigned a task to write a world map generator for this game, and I thought the algorithm I came up with is worthy of a blog post ;) Please note that all codes in this... A Silly Alarm Clock in HTML 2012-09-07T00:00:00+00:00 http://yjyao.com/2012/09/a-silly-alarm-clock-in-html.html/ This project is hosted on Github I have embeded the page below, but you can also directly access it here Eh iframe not supported? I have made this alarm clock, but I am a bit tired of it so I just release this partially finished app as a demo/concept. As you can see, this is an alarm clock designed to be mobile-friendly (though I don’t really think people will actually use a HTML5 alarm clock... NUS IVLE Downloader 2012-08-31T00:00:00+00:00 http://yjyao.com/2012/08/nus-ivle-downloader.html/ Update This app has stopped working as the school revamps the IVLE API and limits the poll rate. This can be fixed by updating the code, but as I have graduated there is no easy way for me to test. If you or friends of you wants to fix this, let me know and I am happy to pass on the project. It's open source anyway. This project is hosted on Github To me, it’s... Gomoku In HTML5 2012-06-04T00:00:00+00:00 http://yjyao.com/2012/06/gomoku-in-html5.html/ Update: I have open sourced this game on Github You can play the game here, or install it from Chrome Web Store. It also supports Mobile Safari! Gomoku is one of the very few board games I actually play and get to win sometimes. Since it’s a game with perfect information and very simple rules, I thought it should be easy to make an AI for it, so I coded this game. This game allows... Some Handy Web Development Tricks 2012-03-25T00:00:00+00:00 http://yjyao.com/2012/03/some-handy-web-development-tricks.html/ In this post, I would like to share some small but useful tricks I found in web development. Set up a simple server locally. For front-end web developers, setting up a PHP and mess around with all the web configurations is just inconvenient. But certain features, like XHttpRequest and web workers, are just not supported by some browsers when the page is accessed locally. Luckily Python has a really interesting utility: python -m SimpleHTTPServer 8000... Canvas Experiments 2012-03-24T00:00:00+00:00 http://yjyao.com/2012/03/canvas-experiments.html/ So I started learning the html5 canvas feature, and here are the three projects I coded. Crazy Paint makes the computer paint randomly on the canvas with a random brush. The brush draws random shapes, some filled, some unfilled, around the point being painted. If you are patient enough, you can try leaving the computer to draw on itself until it makes a nice wallpaper, like the one shown below. Simple Paint uses a lot... New Year, New Platform 2012-01-31T00:00:00+00:00 http://yjyao.com/2012/01/new-year-new-platform.html/ I have just finished setting up my personal site with Jekyll! Hooray!! Why Jekyll? For me, it is because it gives me complete control over the layout and style of the whole site. I also got to host it on Github with git, which is both free and convenient. The customization is way better than Blogspot and much easier to learn. While people describe it as ‘blogging like a hacker’, I found that I don’t... New Year Resolution 2012-01-11T00:00:00+00:00 http://yjyao.com/2012/01/new-year-resolution.html/ Well,this is pretty late, but I will do it any way. Last year my only resolution was 'to learn Qt' and I did it! Although I didn't 'master' Qt, but at least I am now able to write programs with GUI and I am happy with it. I also learnt something outside the plan-client side web development, and I think it seemed more fun. So this is the plan for this year-a much detailed one... How to code a book in CSS 2011-10-08T00:00:00+00:00 http://yjyao.com/2011/10/long-book.html/ This is the first 'theme' I designed. I call it The Long Book, as it is supposed to mimic a book, and turns out to be rather long.... It's probably not a good blog theme-the color is too bright and distracting, the layout is too rigid and the features I used are too new to make this theme work in older browsers. The Mark-up The HTML mark-up is rather straight-forward: <div id='main-body'> <div id='body-left'> <!--... Solitaire three in one 2011-10-06T00:00:00+00:00 http://yjyao.com/2011/10/solitaire-three-in-one.html/ Update: the game has been sold to a company. Some content has been removed and the links are no longer valid. This post is a bit late, but anyway, my HTML Spider is done! I have also merged this game with my previous Solitaire (Klondike) and Freecell, and updated my Solitaire to 'Solitaire Three In One'. The link to the game is here; I have also uploaded it to Chrome Web Store. Shown above is... Wireless@HCI autologin Daemon 2011-08-22T00:00:00+00:00 http://yjyao.com/2011/08/wirelesshci-autologin-daemon.html/ Hullo folks living in HCIBS! Tired of keeping logging into your wireless account every half an hour? Here is an app for you! This app will automatically log into HCI@Wireless with your account every half an hour. During the first time you run the app, it will ask for your login credentials. Click 'login now' after you key in the username and password - and that's it, it will automatically log you in subsequently. To... Treb 2011-08-13T00:00:00+00:00 http://yjyao.com/2011/08/run-google-task-google-plus-in-your.html/ At first I wanted to code a simple Google Tasks client, something that allows me to summon https://mail.google.com/tasks/ig quickly. But as I started coding, my ideas evolved, so finally I kind of merged two new ideas and created this app. Firstly, I think we should be able to use mobile pages on our desktop for quick view of information. For example, instead of building a twitter client, we can just use the mobile twitter to... Solitaire 2011-07-23T00:00:00+00:00 http://yjyao.com/2011/07/solitaire.html/ Update: the game has been sold to a company and the links are no longer valid. My second HTML5 game is done! Grab my Solitaire here! This time it was relatively easy to write because I recycled much of the old codes from the previous Freecell. However, maybe I overused a lot of transformation to achieve the flipping effect, only chrome can run the game fluently :( On firefox it was very laggy, and on... Freecell with HTML5 2011-07-17T00:00:00+00:00 http://yjyao.com/2011/07/freecell-with-html5.html/ The game has been sold to a company and the links are no longer valid. I spent some time learning css3 and html5 and coded this game. You can play it here, or install it from Chrome Store here. This game was coded primarily for chrome, so it doesn't work on IE or opera. I added support for firefox, but firefox doesn't render scaled background nicely. It also can't render box-shadow efficiently, so the experience...