Time pass by

Sunshine and rain of a developer

Archive for the ‘Uncategorized’ Category

How to save GNU screen scroll buffer

Posted by vanguard33 on February 27, 2011

If you use gnu screen, I am sure this tip will be useful someday. If you ran some programs for hours and want to dump the whole scroll buffer to a file. Here’s how:

Ctrl-a :hardcopy -h dump_file.

Note: the dump_file might have many empty line at the beginning, you might need to scroll down a little bit to see the content.

Do NOT use the Ctrl-a [ copy buffer for super big block, screen might die!

From screen user manual:

18.1 hardcopy

— Command: hardcopy [-h] [file]

(C-a h, C-a C-h)
Writes out the currently displayed image to the file file, or, if no filename is specified, to hardcopy.n in the default directory, where n is the number of the current window. This either appends or overwrites the file if it exists, as determined by the hardcopy_append command. If the option -h is specified, dump also the contents of the scrollback buffer.

Posted in Uncategorized | Leave a Comment »

100 Things To Do Before Leo Die

Posted by vanguard33 on May 8, 2010

  1. Skydive
  2. 100% test coverage for a middle size project
  3. complete a project with TDD
  4. visit the tomb of Alan Turing
  5. swim with sharks
  6. become a pilot
  7. lead a great project that has huge impact
  8. write my operating system
  9. write my device driver
  10. attend a public film audition
  11. write a book
  12. get a bs degree in computer science
  13. get a ms degree in computer science
  14. design a commercial game and make money from it
  15. write a patch for python lib
  16. speak in a major conference
  17. be in a daft punk live show
  18. be in a justice live show
  19. visit wolfenstein
  20. live in jail for few weeks
  21. contribute to ubuntu community
  22. contribute to kernel community
  23. meet a lovely girl and fall in love with her
  24. study statistics
  25. study DJ software
  26. create another human
  27. teach my kids programming
  28. get a mustang or 370z
  29. get a Audi R8 or same class car
  30. get a small plane
  31. drive my car in Nürburgring
  32. get married
  33. somebody ask me for autograph
  34. build my Linux distribution
  35. work in a project that could affect millions people’s life
  36. invent something and apply for patent
  37. build an elementary somewhere in China
  38. improve gmail
  39. work in a game company
  40. become the vice president of a major company
  41. visit Las Vagas
  42. get drunk, for real
  43. meet Larry Page when he is still alive
  44. visit Hide’s museum in Japan
  45. become a mentor and guide some students
  46. make a documentary film
  47. draw many elephants
  48. play computer game with my kids
  49. fire guns
  50. develop a software for mobile device
  51. attend cooking school
  52. on a TV show or news
  53. 200 miles per hour on the ground
  54. 20000 meters from earth
  55. win a chess game against another good player
  56. build a personal website
  57. draw animal cartoons
  58. still life painting
  59. fight for justice
  60. create Wikipedia pages
  61. start up a company
  62. work in a restaurant and learn how to run a restaurant
  63. own a Bar
  64. survive a deadly disease or accident
  65. find true love
  66. donate blood
  67. climb a huge snow mountain
  68. act in a film
  69. visit NASA
  70. kill pigs
  71. get some really decent clothing
  72. sleep for a whole day
  73. finish a very difficult rock climbing track
  74. translate a book
  75. over 1000 friends on facebook
  76. get tased by a police officer
  77. double my income in 3 years
  78. triple my income in 5 years
  79. own a nice house
  80. live in a ghetto
  81. crack a software
  82. hack a website and get root privilege
  83. no spelling error in a long mail
  84. find a information collection system that fits me best
  85. find a time management system that fits me best
  86. work extremely efficient for a day
  87. keep writing code for 24 hours
  88. learn to play a music instrument
  89. work in the same company for 5 years
  90. take a one-year vacation
  91. teach my grad child programming
  92. draw a naked woman
  93. fly in a balloon
  94. beg on street
  95. find a remote place without using GPS
  96. convert somebody to atheist
  97. convince some girls that astrology is not for real
  98. play soccer in an amateur league
  99. dance in a dance club
  100. build a nice system for blood simulation and human organs simulation

Posted in Uncategorized | Leave a Comment »

CPU Instruction Speed Benchmark (1999 – 2010)

Posted by vanguard33 on February 23, 2010

I’ve been reading the Programming Pearls for the last few weeks. It is a very interesting and inspirational book. In the appendix, I found a small C speed benchmark program. I changed the source code (casting the pointer to right type) so that it runs on my 64 bit system. The test results is surprising but very logical. Modern CPU runs much faster on division and mod operation. Overall, my 2.8G Core 2 Due takes 13 seconds to terminate while the 1999 PII CPU takes 513 seconds.

Testing result on a 2.8Ghz Intel Core 2 Duo CPU (Date: Feb 23 2010)

C Time Cost Model, n=5000
Integer Arithmetic (n=5000)                         nanosecond per instruction
 {}                     66372 66265 66226 66217 66212       3
 k++                    61226 61101 61105 61089 61112       2
 k = i + j              66915 66618 66593 66589 66378       3
 k = i - j              66905 66215 66413 66270 67377       3
 k = i * j              66908 66768 66696 66800 66713       3
 k = i / j              84009 83901 83915 83896 83916       3 division and mod operation cost the same amount of time as addition and subtraction!
 k = i % j              87329 87328 87340 87317 87335       3
 k = i & j              66861 66588 66563 66471 66507       3
 k = i | j              67665 67547 67562 67493 67586       3
Floating Point Arithmetic (n=5000)
 fj=j;                  61255 61130 61096 61151 61094       2
 fj=j; fk = fi + fj;   107793107778107782107780107777       4
 fj=j; fk = fi - fj;   107816107781107784107822107783       4
 fj=j; fk = fi * fj;   116801116769116760116763116767       5
 fj=j; fk = fi / fj;   197412197467197431197405197428       8
Array Operations (n=5000)
 k = i + j              68272 68202 68198 68208 68196       3
 k = x[i] + j           61465 61294 61280 61305 61280       2
 k = i + x[j]           62285 62135 62112 62137 62108       2
 k = x[i] + x[j]        67986 67857 67861 67854 67871       3
Comparisons (n=5000)
 if (i < j) k++         67828 67620 67623 67623 67608       3
 if (x[i] < x[j]) k++   68377 68288 68286 68280 68276       3
Array Comparisons and Swaps (n=5000)
 k = (x[i]<x[k]) ? -1:1 80980 80932 80932 80928 80931       3
 k = intcmp(x+i, x+j)  142630142660142621142593142599       6
 swapmac(i, j)         108802108758108734108766108734       4
 swapfunc(i, j)        189412189421189412189460189490       8
Max Function, Macro and Inline (n=5000)
 k = (i > j) ? i : j    75729 75485 75551 75480 75543       3
 k = maxmac(i, j)       75842 75592 75522 75535 75518       3
 k = maxfunc(i, j)     143934143780143783143748143777       6
Math Functions (n=1000)
 fk = j+fi;              2733  2736  2739  2734  2734       3
 k = rand();            12512 12529 12557 12476 12485      13
 fk = sqrt(j+fi)        11497 11496 11506 11503 11500      12
 fk = sin(j+fi)         46135 46116 46092 46128 46106      46
 fk = sinh(j+fi)        11829 11819 11824 11837 11832      12
 fk = asin(j+fi)         6392  6387  6390  6386  6387       6
 fk = cos(j+fi)         46199 46183 46177 46174 46179      46
 fk = tan(j+fi)         55542 55496 55507 55488 55501      56
Memory Allocation (n=500)
 free(malloc(16));      13106 13017 12932 12779 12959      52
 free(malloc(100));     12972 12947 12867 13016 12923      52
 free(malloc(2000));    11653 11683 11536 11673 11620      47
 Secs: 13.33

Testing result of a PII CPU in 1999

C Time Cost Model, n=5000
Integer Arithmetic (n=5000)
{}                      1263  1313  1263  1263  1263       5
k++                     2011  2011  2010  2011  2011       8
k = i + j               2260  2260  2260  2260  2260       9
k = i - j               2244  2260  2259  2260  2260       9
k = i * j               4023  4005  4023  4022  4023      16
k = i / j              13814 13814 13980 13914 14163      56
k = i % j              13814 13814 13814 13797 13797      55
k = i & j               2260  2277  2260  2260  2260       9
k = i | j               2260  2260  2260  2260  2260       9
Floating Point Arithmetic (n=5000)
fj=j;                   5019  5003  5021  4970  5036      20
fj=j; fk = fi + fj;     5021  5019  5019  5021  5019      20
fj=j; fk = fi - fj;     5019  5021  5036  5019  5021      20
fj=j; fk = fi * fj;     5036  5021  5019  5019  5038      20
fj=j; fk = fi / fj;    12549 12551 12551 12551 12567      50
Array Operations (n=5000)
k = i + j               2260  2260  2260  2260  2260       9
k = x[i] + j            2808  2810  2775  2808  2810      11
k = i + x[j]            2908  3341  2893  2875  2860      12
k = x[i] + x[j]         3490  3507  3490  3490  3490      14
Comparisons (n=5000)
if (i < j) k++          2393  2393  2377  2393  2393      10
if (x[i] < x[j]) k++    2926  2924  2926  2908  2926      12
Array Comparisons and Swaps (n=5000)
k = (x[i]<x[k]) ? -1:1  3042  3057  3059  3059  3057      12
k = intcmp(x+i, x+j)    7015  7015  7015  7015  7016      28
swapmac(i, j)          15077 15110 15077 15110 15094      60
swapfunc(i, j)          8477  8479  8477  8494  8495      34
Max Function, Macro and Inline (n=5000)
k = (i > j) ? i : j     2509  2509  2509  2526  2511      10
k = maxmac(i, j)        2509  2509  2526  2509  2509      10
k = maxfunc(i, j)       5536  5519  5536  5519  5534      22
Math Functions (n=1000)
fk = j+fi;               151   149   166   166   149      16
k = rand();              715   680   698   682   697      69
fk = sqrt(j+fi)         2360  2343  2360  2343  2343     235
fk = sin(j+fi)          2743  2742  2742  2743  2758     275
fk = sinh(j+fi)         9209  9226  9226  9242  9226     923
fk = asin(j+fi)         7747  7730  7728  7714  7714     773
fk = cos(j+fi)          2758  2758  2760  2758  2760     276
fk = tan(j+fi)          3256  3258  3258  3258  3258     326
Memory Allocation (n=500)
free(malloc(16));       1113  1113  1113  1113  1097     444
free(malloc(100));      1296  1296  1296  1296  1296     519
free(malloc(2000));     1296  1279  1298  1279  1296     516
Secs: 513.37

Posted in Uncategorized | Leave a Comment »

DirectX 10 DrawText Disable Depth Buffer. Here’s how to fix it.

Posted by vanguard33 on July 6, 2009

DrawText() is a bitch. It changes device state silently.  You have to use a spirit to save the states before you draw it and reset depth buffer after you draw the text.


void cGraphicsLayer::DrawTextString(int x, int y, 
 D3DXCOLOR color, const TCHAR* strOutput)
{
 m_pFontSprite->Begin(D3DX10_SPRITE_SAVE_STATE);
 RECT rect = {x, y, m_rcScreenRect.right, m_rcScreenRect.bottom};

 m_pFont->DrawText(m_pFontSprite, strOutput, -1, &rect, DT_LEFT|DT_NOCLIP , color);
 m_pFontSprite->End();
}

Here’s how to recover the depth buffer. You need to keep your DepthStencilState and set it with OMSetDepthStencilState


void cGraphicsLayer::ResetDepthBuffer()
{
 m_pDevice->OMSetDepthStencilState(m_pDepthStencilState, 1);
}

Good luck

Posted in Uncategorized | 3 Comments »

System 6 Forever

Posted by vanguard33 on June 28, 2009

sys6_1sys6_2

System 6 (also referred to as System Software 6) is a graphical user interface-based operating system for Macintosh computers. It was released in 1988 by Apple Computer and was part of the Mac OS line of operating systems. System 6 was shipped with various Macintosh computers until it was succeeded by System 7 in 1991. The boxed version of System 6 cost 49 USD when introduced.[1] System 6 is classed as a monolithic operating system. It featured an improved MultiFinder, which allowed for co-operative multitasking. The last version of System 6 was released in 1991.

Why system 6?

Macintosh Operating System 6 is probably the nicest operating system ever made. Nowadays it’s considered ancient (development stopped somewhere in 1991) but it’s far from backward and with the use of the proper vintage software you can be just as productive on a System 6 machine as you’d be on a modern Mac. System 6 runs on most older Macintosh computers with 68000, 68020 and 68030 processors. Some of these Machines are also able to run later versions of the Mac OS up to 7.55 and 7.61, but the lower-end models, most notably the so called Compact Macs, the Mac Plus, the SE and the Classic, and the lowend 68020′s, the Mac II and the LC, are better off running System 6. They will be a lot faster with System 6 than with System 7. The reason behind this is the fact that System 6 is not only a lot more compact (it has less features and therefore less code to crunch), but also because System 6 was written in assembly code instead of the high level language C. Assembly code is a bit lower level and because of that a bit closer to the hardware of the machine, making it a lot more responsive.

Read some more system 6 advocacy here

Link System 6 Heven

Posted in Uncategorized | Leave a Comment »

Will it blend? Iphone

Posted by vanguard33 on June 18, 2009

They blend almost everything which that be put in to the blender

Posted in Uncategorized | Leave a Comment »

Use Python To Convert ASCII to UTF-16

Posted by vanguard33 on June 17, 2009

Such an easy thing. But I took 1 hours to figure out.

import codecs
f=open(“wall.obj”,’r')
txt = f.read()
print txt
f.close()

of = codecs.open(“uwall.obj”,’w',’utf-16′)
of.write(txt)
of.close()

Posted in Uncategorized | Leave a Comment »

How to use C++ Sleep() function under Windows

Posted by vanguard33 on May 28, 2009

If you want to sleep 1 second in your program, you should do the following thing

1. #include <windows.h>

2. DWORD dwMillseconds=1000;

3. Sleep(doMillseconds);

Posted in Uncategorized | Leave a Comment »

Good Writing Tips

Posted by vanguard33 on May 1, 2009

I discovered this good writing tips in Randy Pausch’s website. He is the professor that I respect most. The paper is written by  Marc H. Raibert at January 1985 and the key ideas in this paper remain true today.

The full version of the paper can be found here. It is not very long, so you can read it within 10 minutes. I promise that it is worth your time to read it.  Here are the outlines of this paper

  • You must want to produce good writing.
  • You must have confidence that you can produce good writing.
  • Good writing is bad writing that was rewritten.
  • Spill the beans right away.
  • Don’t be a slave to your prose.
  • Outlining helps to get unstuck.
  • Husband your readers.
  • Trust your readers.

Posted in Uncategorized | Leave a Comment »

Test Post by ScribeFire

Posted by vanguard33 on April 13, 2009

ScribeFire is a offline blog client in Firefox.

17 Again Movie Trailer – Zac Efron

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.