A Simple Interview Question

I ran into an interview question on leetcode about a number conversion that marked as easy. It reveals the beauty of our numbering notation. Question Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ... Example 1: Input: 1 Output: "A" Example 2: Input: 28 Output: "AB" Example 3: Input: 701 Output: "ZY" Solution (Incorrect) At first glance, I thought it is just a simple conversion to a base 26 number. Read more →

Graphql Subscription with Angular and Rxjs

In this article, I want to show you how easy it is to use only Angular and its build in Rxjs to do Graphql subscription. (There are existing graphql clients such as Apollo Client, but we show you how simple it it to roll your own.) Graphql has a subscription type besides query and mutation. Most implementations use websocket to implement subscription type and send data from server to client. Read more →

GraphQL File Upload with Angular

GraphQL does not support file upload natively. Thankfully, jaydenseric created graphql-multipart-request-spec to standardize the format to use multipart (HTTP file upload) request to upload file to a GraphQL server. On the server side, most popular GQL servers support this standard. On the client side, you can use Apollo GraphQL client. However, what if you want to implement your own file upload client? This article shows that all you need to do is to create a multipart request according to the format of graphql-multipart-request-spec and send it to the server. Read more →

LDAP authentication in passport with React

LDAP authentication in passport with React When develop enterprise app, LDAP authentication is needed most of the time. I will show you how to do that in this blog. What you need You will need express as the server, Mongodb with mongoose as the session storage and local user database. passport with passport-ldapauth as the authentication middleware On the front end, we will use react and Materail-UI to build a simple login page. Read more →

Promise Flow Control Dilemma

Note: With async and await syntax, this is no longer a problem: var input = getInput() if (sanityCheck(input)) { if (isEdit) { var obj = await db.findById(id).exec() await update(obj, input) } else { obj = await newObject(input) } await modifyAndSaveObject(obj) } else { throw(new Error('Invalid input')) } Promise in flow control IF…ELSE… In sequential programming, we can easily use if...else to diverge the code into different control flow paths, then after that, merge the control together. Read more →