Showing posts with label 23. Show all posts
Showing posts with label 23. Show all posts

Thursday, February 13, 2014

Book Review #23


Modernist Cuisine at Home todo
Nathan Myhrvold et al

If you have ever seen the book Modernist Cuisine in the book store, then you know that the package isn't shaped like a book, but more like a big block of wood. And just as heavy. If the $450 purchase price does not scare you, you will find that it is the best, most comprehensive cooking book anywhere in the world. However, the problem is that the equipment list is so long, that most people would have no use for it. This version of the book (for at Home), I bought at 50% off during a new year sale.

And it is wonderful. The equipment list is also long, and the fact is, there are recipes in there that I will never ever cook. But that's not the aim of the book. The purpose of the book is to understand how the food cooks, and that's why there are illustrations on how the food cooking process happen inside the pot. By the way, these illustrations aren't handdrawn. They're photos. That's right. You can actually see how the food cooks inside the pot because they cut the pot in half! That's no mean feat when they're illustrating on cooking sous vide!

A lot of the cooking process can be summarized as cook low and slow. This holds true, especially for sous vide (under vacuum). However, the result is worth it. Unfortunately, precision is essential, so be prepared to invest in more hardware that is used only in cooking. It's not until after reading this book, that I'm persuaded to buy kitchen timer and thermometer, for example. Also, some of the hardware is industrial looking. Do you know they use a special sprayer for omellete? Sigh.

Anyway, the title may be "for home", and in most part, that's true. However, it's still too much for me. Is the book worth the purchase price? Production quality is top-notch, easily the best I've seen. Considering that I got it for 50% off, the answer is "Absolutely!". If you have to pay full price, then I can understand your reluctance. The best thing you can do is read it. Even if you're not a cooking afficiando, this book may just turn you into one. It did for me. :)

Monday, January 27, 2014

Cooking Journal #23

Frozen Pizza

So, I bought a few pizza from the local supermarket. Buying in batch of 5, they cost $2 each. Quite a good deal, if I may say so myself. $2 meal is nice, but the large pizza means that I eat only half. The other half goes to refrigerator for another meal time. So, the cost per meal is only $1.

I find it hard to believe that people will order a pizza delivery. I can understand if you're travelling and have no means to cook good food. I can also understand if you're having a party or maybe you want to have more than one pizza. If all you want is a pizza, frozen pizza is cooked in about 20 minutes at 400 degrees, or about the same as delivery.

Pizza quality, of course, is less than gourmet pizza. Pizza Hut is great. So is Papa John. However, the quality of frozen pizza is not bad. There's nothing wrong with stocking your freezer with them.

Take a simple Pepperoni pizza. Maybe you think it's rather bland. So? Just add more toppings as you like it. There's nothing wrong with customizing the toppings. You may need to experiment a little bit with the proper cooking time as to accomodate the opening of the oven, but I don't think that's too difficult to do.


Friday, November 1, 2013

Petit Computer Journal #23


6. Loop with Player input + multi-thread


This time, we're going to do something that is common in complex games: multi-threading.

Multi-threading is a rather sophisticated and complex way to have multiple process going on at the same time. It is also extremely difficult to get right, especially if different processes depends on other processes. What I'm going to do is to simplify the problem, so that there is no dependency to the process.

We're going to set up and do multiple timers. Except, we're not going to do it the simple way using sprites. We're going to do it the hard way using internal timers: MAINCNTL.

MAINCNTL is the counting of frames since the program launched. Since there is a limit in the numerical accuracy, it is only able to count up to 145 minutes at a time. After that, it rolls over. So, our program must be able to handle that scenario.

The standard way to handle it, is to check MAINCNTH. However, in order to simplify the program, I'm not going to do that. What I'm going to do, is to store the MAINCNTL value for each thread, and compare it to the current MAINCNTL value. Then increase the timer for the difference. Surely, that method will lose a few frames over time, but I'm not worried. When the timer has minute resolution, a few frames missing isn't going to be a big deal.



  1. CLS:CLEAR
  2. DIM N(20)
  3. DIM M(20)
  4. DIM C(20)
  5. DIM L(20)
  6. DIM A(20)
  7. DIM T$(20)


  8. @TMRDATA
  9. DATA 0,99,"MAXTIMER"
  10. DATA 1,1,"QUICK TIMER"
  11. DATA 2,2,"SLOW TIMER"
  12. DATA 3,3,"EGG TIMER"
  13. DATA 4,4,"SNOOZER"
  14. DATA -1,-1,"DONE"

  15. @INIT
  16. CLS
  17. LOCATE 0,22:?"A START  ","B PAUSE  ","X RESET"
  18. P=1:RESTORE @TMRDATA
  19. FOR I=0 TO 19
  20. A[I]=FALSE
  21. IF P THEN READ N[I]:'TIMER NUMBER
  22. IF P THEN READ M[I]:M[I]=M[I]*3600:'TIMER MINUTES
  23. IF P THEN READ T$[I]:'TIMER LABEL
  24. IF N[I]<0 THEN P=0:TC=I-1
  25. NEXT
  26. CS=0:'CURSOR
  27. TH=0:'THREAD


Timers will have these operations on them: (A)START, (B)PAUSE, (X)RESET. It will have these data on them: (N)Timer Number,(M)Max Tick,(C)Current Tick,(L)Last MAINCNTL,(A)Active Status,(T$)Timer Label. We will also have something to process (TC)Timer Count up to 20.



  1. @LOOP
  2. 'PROCESS INPUT
  3. VSYNC 1:B=BTRIG()
  4. IF (B AND 1) THEN CS=CS-1:IF CS<0 THEN CS=TC
  5. IF (B AND 2) THEN CS=CS+1:IF CS>TC THEN CS=0
  6. IF (B AND 16) THEN A[CS]=TRUE
  7. IF (B AND 32) THEN A[CS]=FALSE
  8. IF (B AND 64) THEN GOSUB @TRESET

  9. 'PROCESS THREAD
  10. TH=TH+1:IF TH>TC THEN TH=0
  11. IF A[TH]==FALSE GOTO @SHOW
  12. IF MAINCNTL>L[TH] THEN C[TH]=C[TH]+(MAINCNTL-L[TH])
  13. IF C[TH]>M[TH] THEN GOSUB @ALARM

  14. @SHOW
  15. IF C[TH]==M[TH] THEN COLOR 13 ELSE COLOR 0
  16. TM=FLOOR((M[TH]-C[TH])/3600)
  17. TS=FLOOR(((M[TH]-C[TH])%3600)/60)
  18. TM$=RIGHT$(("00"+STR$(TM)),2)
  19. TS$=RIGHT$(("00"+STR$(TS)),2)
  20. LOCATE 0,TH:?" "*31
  21. IF CS==TH THEN LOCATE 0,TH:?">";
  22. LOCATE 3,TH:?N[TH];
  23. LOCATE 6,TH:TM$;":";TS$,T$[I]
  24. L[TH]=MAINCNTL
  25. GOTO @LOOP

  26. @TRESET
  27. A[CS]=FALSE
  28. C[CS]=0
  29. BGMSTOP
  30. RETURN

  31. @ALARM
  32. BGMPLAY 6
  33. A[TH]=FALSE
  34. C[TH]=M[TH]
  35. RETURN


Tuesday, September 17, 2013

Raspberry Pi Journal #23


Sorting Log  Frequency List


A lot of times, in analyzing log files, you want to see how often something happens. Maybe you want to know how often a particular user logon in a day, or how many times a web page is accessed? If you want to do a daily report, you want to automate the process. Well, there is an easy way to do it using Perl. But since I'm still learning the shell, I want to know if there's a way to do it using shell, not necessarily the most efficient, but as long as it's relatively quick, then it should be alright.

The first thing you want is a way to get only the relevant piece of data. I want to do this in two steps:
1. Identify the wanted line
2. put the identifying unique word in a line in a file.

Let's say I want to parse /var/log/messages.1 for various processes. I would do this:

egrep -o 'raspberrypi [[:alnum:]]+' messages.1 | egrep -o [[:alnum:]]+$ | sort > messlist.txt

replacing "raspberrypi" with your unique SSID_hostname. The "-o" option says that only the matching text, instead of the whole line will be piped out. I do it twice, first with the tell-tale SSID token, then only the process name. I also sort the file and write it out to messlist.txt

We now have the frequency list. How will we get unique names of the list? Simplicity itself. I simply sort it out again, with the "-u" option.

sort -u messlist.txt > messuniq.txt

That's all there is to it!

Now that we have two files, one containing the unique id, and the other contains all the instances of the ids, we can now count them no problem.

for NAM in `cat messuniq.txt`;
do
  echo $NAM `egrep $NAM messlist.txt | wc -l` ;
done

If you are familiar with computer programming at all, you will probably recognize that this algorithm is not at all efficient. What it basically does is for each entry in messuniq.txt, scan all entries in messlist.txt, outputting only those that matches, and count each occurrence. It's pretty easy to do. It's easy-as-a-bubble-sort, and just as inefficient.

But it works, and works well. So, there you go. If you want to do frequency counting, no need to bring out some large, bloated scripting engine. Just do it via shell!

By the way, I was confused by the instruction in using "for" loops. I keep using the square brackets, and keep getting invalid token error. It was only after I step back, and consider all possibilities that I guessed that the square brackets are there only to indicate optional entries. As such, I eliminate all the square brackets, and it works!

Here is the script in its entirety:

#!/bin/bash

egrep -o 'raspberrypi [[:alnum:]]+' messages.1 | egrep -o [[:alnum:]]+$ | sort > messlist.txt
sort -u messlist.txt > messuniq.txt

for NAM in `cat messuniq.txt`;
do
  echo $NAM `egrep $NAM messlist.txt | wc -l` ;
done



And here is the output:

kernel 6379
motion 1545
mtp 34
rsyslogd 19
shutdown 14
wpa 366