Guowei Lv

3 minute read

Let’s take the assembly-line function and refactor it to make things a bit more clear, and also as a recap. (defn go-body [body-chan] (go (while true (let [body (loop [] (let [part (take-part)] (if (body? part) part (recur))))] (prn "Got body") (>! body-chan body)))) ) (defn go-wheel1 [wheel1-chan] (go (while true (let [wheel1 (loop [] (let [part (take-part)] (if (wheel? part) part (recur))))] (prn "Got first wheel") (>! wheel1-chan wheel1))))) (defn go-wheel2 [wheel2-chan] (go (while true (let [wheel2 (loop [] (let [part (take-part)] (if (wheel?

Guowei Lv

2 minute read

One way to boost productivity in traditional factories is to use assembly line. From Wikipedia: An assembly line is a manufacturing process (often called a progressive assembly) in which parts (usually interchangeable parts) are added as the semi-finished assembly moves from workstation to workstation where the parts are added in sequence until the final assembly is produced. By mechanically moving the parts to the assembly work and moving the semi-finished assembly from work station to work station, a finished product can be assembled faster and with less labor than by having workers carry parts to a stationary piece for assembly.

Toy Factory Simulation Using core.async (2)

Hiring(Increasing Concurrency)

Guowei

3 minute read

In Part 1 we have already defined the process of building toy cars, by one worker. Here is the code again for easy reference. (defn build-car [n] (prn n "Starting build") (let [body (loop [] (let [part (take-part)] (if (body? part) part (recur)))) _ (prn n "Got body") wheel1 (loop [] (let [part (take-part)] (if (wheel? part) part (recur)))) _ (prn n "Got wheel1") wheel2 (loop [] (let [part (take-part)] (if (wheel?

Guowei Lv

4 minute read

After learning the core.async library in Clojure, I was craving for a real-world example. Now I found one from purelyfunctional.tv. The original code can be found here. The Toy Car Factory Let’s describe how a worker builds a toy car. Take a car body from the part box. Take a wheel from the part box. Take another wheel from the part box. Attach the first wheel to the body. Attach the second wheel to the body.

Guowei Lv

11 minute read

Android custom view

In this post, we will be focusing on the Paint. Color The color in Paint has 3 parts: basic color, color filter and xfermode. Basic color There are 2 ways to set color in Paint: use setColor() and use Shader. Set color directly Two methods can be used: paint.setColor(Color.parseColor("#B90E83"); paint.setARGB(100, 255, 0, 0); There is no difference, pick whichever you like. Set color using Shader There are different types of Shader, let’s look them one by one.