Skip to content

Instantly share code, notes, and snippets.

View qingwei91's full-sized avatar

Qing qingwei91

View GitHub Profile
@qingwei91
qingwei91 / getting-started-akka-stream.md
Created May 14, 2016 15:19
Getting Started on Akka-stream (Copied from StackOverflow)

DISCLAIMER: The whole content is copied from This awesome answer

To prevent lost of such useful content as the original question was too broad for SO

Full credit: content author sschaef

If you find this copied content offensive in anyway, please email me

This answer is based on akka-stream version 2.4.2. The API can be slightly different in other versions. The dependency can be consumed by [sbt][1]:

@qingwei91
qingwei91 / scalajs-frp-frontend.md
Last active February 26, 2017 16:41
How scala.js match with React

This blog post will discuss what Scala.js is suitable for. I will first introduce current state of web development, and discuss why scala.js might a sensible choice for web development

State of Web Development

As of early 2017, ReactJS remain the most popular frontend framework/ecosystem.

From the point of application architecture, two notable improvements are

  • composable UI components
  • Flux Architecture (aka Uni-directional data flow)
@qingwei91
qingwei91 / multiplayer-game-networking1.md
Last active May 9, 2024 08:15
How does Multiplayer Game sync their state? Part-1

The problem in multiplayer game

In multiplayer game, one of the most complex issue is to keep all player's state in sync with server state. There are a few good articles around this topic on the internet. However, some details are missing here and there, which may be confusing for beginners in field of game programming, I hope I can clear things up in this article.

I'll present a few techniques commonly used in this problem space.

Before we jump into the problem, let's have an overview on how multiplayer game generally works.

Typically, a game program needs to simulate

@qingwei91
qingwei91 / server.scala
Last active April 11, 2017 07:31
multiplayer-game-blog
def onReceivedInput(i: UserInput) = {
storeInputToBuffer(i)
}
while(!gameEnded) {
val allUserInputs = readInputFromBuffer()
currentState = step(currentState, allUserInputs) // ie. (STATEn , INPUTn) => STATEn+1
sendStateToAllPlayers(currentState)
}
class Server {
def main(): Unit = {
while (true) {
/**
* 1. Read user inputs which can be one of [←, ↑, →, ↓], to change the direction of snake.
* 2. Apply user input if any, which change the direction of snake.
* 3. Move snake by 1 unit space
* 4. Check if any snakes bump into enemy/wall/self, remove them from the game.
* 5. Broadcast the new game state to all clients
class Client {
def onServerUpdate(state: GameState) = {
renderGameState(state)
}
}
@qingwei91
qingwei91 / meeting.md
Last active June 27, 2017 12:58
about meeting

Fantastic meetings and where to find them

Anecdotally most people in the software industry hate meetings; a meeting is a soul-sucking dementor. Jokes aside, I think it's fair to say that people feel meetings are taking too much time and the process is often painful.

In this post, I'll try to provide a few rules of thumb that I believe can make meetings less painful and more efficient.

Rule 1: Always reiterate your goal before start

How many times do you attend a meeting without a goal in mind?

@qingwei91
qingwei91 / personal-postmortem.md
Last active August 6, 2017 08:52
post mortem @ 5th August

Things I've learnt after 1 year of working abroad, alone

Software development

  • Dont expect new stuff to work on the 1st time
    • New tools, new technology, new process, anything that you never tried before, you should expect you will fail at the very first time
    • This means you should generally be conservative on first try, try to experiment in small bits before fully commit into the new endeavour you are looking into
  • It also means you should not dismissed the new stuff on first try, as you're more likely to do it wrong at first, as a
@qingwei91
qingwei91 / scalameta-tut.md
Last active September 5, 2017 09:52
Creating a cache decorator macro with scalameta

Scalameta tutorial: Cache decorator

This is a tutorial to show how to use Scalameta to develop a generic, parameterized annotation. To know how to setup a project to use scalameta, refer to official docs

What is scalameta?

Scala-meta is the de-facto toolkit for metaprogramming in Scala. For those who are new to metaprogramming, it means programming against code/syntax/AST

Metaprogramming is very useful when you notice a repeating pattern in your code, but you are not able to refactor it due to limitations of the programming language.

class CacheBackEnd[K, V] {
private var map = Map.empty[K, V] // ignore the fact it is not thread safe
// `compute` is a function, only evaluated in case of cache miss
def getOrElse(k: K, compute: K => V): V = {
map.get(k) match {
case Some(v) => v // cache hit
case None =>
val v = compute(k)
map = map + (k -> v)