顯示具有 Programming 標籤的文章。 顯示所有文章
顯示具有 Programming 標籤的文章。 顯示所有文章

9/23/2010

Printing Java Call Stack

The following function could be use to print current java call stack.


Arrays.toString(new Throwable().getStackTrace()).replace(',', '\n')

8/17/2009

Java reference type

以下連結針對Java soft reference及weak reference有很棒的解說

http://blog.centuryminds.com/2007/11/weak-and-soft-references-in-java/

7/21/2009

Android 1.5 source code build error in Ubuntu 9.04

Issue:
make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_intermediates/sockets.o] Error 1

Solution:
Modify "external/qemu/Makefile.android"
Original:
# this is needed to build the emulator on 64-bit Linux systems
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
MY_CFLAGS += -Wa,--32
endif

Modified:
# this is needed to build the emulator on 64-bit Linux systems
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
MY_CFLAGS += -Wa,--32 -D_GNU_SOURCE
endif

10/09/2008

Install/Update JDK on Linux

  • sh jdk-6u7-linux-i586-rpm.bin
  • alternatives --install /usr/java/jdk1.6.0_07/bin/java java /usr/java/latest/bin/java 2
  • alternatives --config java

4/17/2008

OOP .........Oops

物件導向程式設計(Object-Oriented Programming, OOP), 這真是個電腦語言界的偉大發明.
利用物件(Object)之間的互動關係來設計程式, 的確能讓程式有更加的彈性.
但是...對一個半調子的OOP程式員來說, 後面要加個"S"比較貼切.
最近很認真的在寫論文的模擬實驗, 更深刻的體會到OOP的博大精深.
對讀完大學加上研究所的資工系學生來說, 應該沒幾個人能寫出個像樣的物件導向程式.
再加上我又三八想寫個程窗的介面, 這根本是自找麻煩嘛!
不過說真的在寫模擬的過程中我也學到了不少東西.
最重要的就是了解如何去"設計 (Designing)"一個程式, 而不是"寫 (Coding)"一個程式.
說到這裡又不禁為台灣的資工系學生感到汗顏, 業界是很危險滴...快回你的火星吧!
唉~當初如果用程序式的方法硬幹...我該早畢業了吧XD

4/13/2008

Eclipse for Everything

Eclipse真是個神奇的東西, 幾乎對所有程式語言都有plug-in

目前用它來寫java, c/c++(CDT + MinGW)及LaTeX(TeXlipse)

還有sublipse可以做version control

想當初癡肥的Visual Studio快把我搞瘋了

如今用了它以後頭腦就靈光了很多,每次考試都考一百分

我想在不久的將來所有的程式設計師電腦中只要有這一套IDE就夠了

4/12/2008

Notes about Eclipse for Windows Programming

Setup Eclipse with CDT + MinGW for Windows Programming.

  • Step1: install eclipse.
  • Step2: install MinGW with win32api.
  • Step3: install MinGW's gdb.
  • Step4: run eclipse, install CDT by "Help->Software Updates->Find and Install".
  • Step5: In general, you could build and debug regular c/c++ source file and win32 program. If you could not it, you have to do a little configure to enable it.
  • Step6: open "Project->Properties", in "C/C++ build", click "Manage Configurations". New a new configuration named "Win32". In "C/C++ build->Settings", click "MinGW C++ Linker->Miscellaneous". Add a linker flag "-mwindows" and click apply.
  • Step7: Try to build a win32 program again.

3/07/2008

How can I create two classes that both know about each other?

Use a forward declaration.

Sometimes you must create two classes that use each other. This is called a circular dependency. For example:

class Fred {
public:
Barney* foo();
// Error: Unknown symbol 'Barney'
};

class Barney {
public:
Fred* bar();
};

The Fred class has a member function that returns a Barney*, and the Barney class has a member function that returns a Fred. You may inform the compiler about the existence of a class or structure by using a "forward declaration":

class Barney;

This line must appear before the declaration of class Fred. It simply informs the compiler that the name Barney is a class, and further it is a promise to the compiler that you will eventually supply a complete definition of that class.

1/05/2008

Random Number

產生1到10之間的亂數

int main(void)
{
srand((unsigned)time(0));
int random_integer;
for(int i = 0;i < 20;i++)
{
random_integer = rand()%10;
cout << random_integer << endl;
}
}

11/12/2007

How to Output Debug Message in Visual C++ Debug Mode's Output Area

DbgMessage.h
#ifndef _DBGMESSAGE_H_
#define _DBGMESSAGE_H_

void __cdecl DbgPrintf(LPCTSTR format, ...);

#endif /*_DBGMESSAGE_H_*/

#ifndef DBG_MAX_BUFFER_SIZE

#define DBG_MAX_BUFFER_SIZE 256

#endif /*_DBG_MAX_BUFFER_SIZE_*/

DbgMessage.cpp
#include "stdafx.h"

void __cdecl DbgPrintf(LPCTSTR format, ...)
{
static TCHAR DbgMsg[DBG_MAX_BUFFER_SIZE];
size_t len;
TCHAR *p = DbgMsg;
va_list args;

va_start(args, format);
StringCchVPrintf(p, sizeof(DbgMsg) - 1, format, args);
StringCchLength(DbgMsg, sizeof(DbgMsg) - 1, &len);
p += len;
va_end(args);

*p++ = '\r';
*p++ = '\n';
*p = '\0';

OutputDebugString(DbgMsg);
}



Usage:
int a = 101;
DbgPrintf(TEXT("hello %d"), a);

9/08/2007

Programming Notes

An abstract class is one whose main purpose is to define a common interface for its subclasses.

An mixin class is a class that's intended to provide an optional interface to other classes. It's similar to an abstract class in that it's not intended to be instantiated.

3/26/2007

Random Number Generation

在做模擬實驗時最重要的就如何去產生一組符合應用要求的random data set, 這個由Steve Park及Dave Geyer在98年所釋出的Multi-stream random number generation library, 可以產生許多常用到的random number, 其中包含...

Discrete Distributions:

  1. Bernoulli
  2. Binomial
  3. Equilikely
  4. Geometric
  5. Pascal
  6. Poisson

Continuous Distributions:
  1. Uniform
  2. Exponential
  3. Erlang
  4. Normal
  5. Lognormal
  6. Chisquare
  7. Student

4/21/2006

Latex with Chinese

0.安裝MikTex

1.安裝CJK套件

2.選擇字型(c:\texmf\tex\latex\CJK\Bg5\)

3.加入以下package
\usepackage{CJK}

4.使用以下指令加入中文
\begin{CJK}{Bg5}{bsmi}
\end{CJK}

2/08/2006

Adding Console I/O to a Win32 GUI App

One of the common misconceptions surrounding Win32 programming is that you must decide early in the design process whether your application will be a console or GUI application. In reality, console applications can create windows and have a message loop just like a GUI application (see "Adding Graphics to Console Applications" by Michael Covington, Visual Developer, June/July 1997). Alternatively, graphical applications can create and use a console. Although Win32 provides functions for communicating with a console, they are a little clumsy to use and require parameters that are unnecessary for simple text I/O. This article shows how to use standard C/C++ I/O with consoles, and how to work around specific problems in the Visual C++ I/O library.

http://dslweb.nwnexus.com/~ast/dload/guicon.htm