锘??xml version="1.0" encoding="utf-8" standalone="yes"?>BlogJava-gembinhttp://www.8634070.com/gembin/<font color="red">OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP</font><br/><br/> <font color="green">HBase, Hadoop, ZooKeeper, Cassandra</font><br/><br/> <font color="blue">Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.</font><br/><br/> <font color="black"> There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.</font> <br/><br/> <a href="http://about.me/gembin">About Me</a> <script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-counter="right"></script> zh-cnTue, 26 Mar 2019 21:13:45 GMTTue, 26 Mar 2019 21:13:45 GMT60Overriding Vs Hiding http://www.8634070.com/gembin/archive/2014/05/29/414246.htmlgembingembinThu, 29 May 2014 07:52:00 GMThttp://www.8634070.com/gembin/archive/2014/05/29/414246.htmlhttp://www.8634070.com/gembin/comments/414246.htmlhttp://www.8634070.com/gembin/archive/2014/05/29/414246.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/414246.htmlhttp://www.8634070.com/gembin/services/trackbacks/414246.htmlCan I override a static method?

Many people have heard that you can't override a static method. This is true - you can't. However it is possible to write code like this:


class Foo {
    public static void method() {
        System.out.println("in Foo");
    }
}

class Bar extends Foo {
    public static void method() {
        System.out.println("in Bar");
    }
}

This compiles and runs just fine. Isn't it an example of a static method overriding another static method? The answer is no - it's an example of a static method hiding another static method. If you try to override a static method, the compiler doesn't actually stop you - it just doesn't do what you think it does.

So what's the difference?

Briefly, when you override a method, you still get the benefits of run-time polymorphism, and when you hide, you don't. So what does that mean? Take a look at this code:


class Foo {
    public static void classMethod() {
        System.out.println("classMethod() in Foo");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in Foo");
    }
}

class Bar extends Foo {
    public static void classMethod() {
        System.out.println("classMethod() in Bar");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in Bar");
    }
}
 
class Test {
    public static void main(String[] args) {
        Foo f = new Bar();
        f.instanceMethod();
        f.classMethod();
    }
}

If you run this, the output is

instanceMethod() in Bar classMethod() in Foo

Why do we get instanceMethod from Bar, but classMethod() from Foo? Aren't we using the same instance f to access both of these? Yes we are - but since one is overriding and the other is hiding, we see different behavior.

Since instanceMethod() is (drum roll please...) an instance method, in which Bar overrides the method from Foo, at run time the JVM uses the actual class of the instance f to determine which method to run. Although f was declared as a Foo, the actual instance we created was a new Bar(). So at runtime, the JVM finds that f is a Bar instance, and so it calls instanceMethod() in Bar rather than the one in Foo. That's how Java normally works for instance methods.

With classMethod() though. since (ahem) it's a class method, the compiler and JVM don't expect to need an actual instance to invoke the method. And even if you provide one (which we did: the instance referred to by f) the JVM will never look at it. The compiler will only look at the declared type of the reference, and use that declared type to determine, at compile time, which method to call. Since f is declared as type Foo, the compiler looks at f.classMethod() and decides it means Foo.classMethod. It doesn't matter that the instance reffered to by f is actually a Bar - for static methods, the compiler only uses the declared type of the reference. That's what we mean when we say a static method does not have run-time polymorphism.

Because instance methods and class methods have this important difference in behavior, we use different terms - "overriding" for instance methods and "hiding" for class methods - to distinguish between the two cases. And when we say you can't override a static method, what that means is that even if you write code that looks like it's overriding a static method (like the first Foo and Bar at the top of this page) - it won't behave like an overridden method.

So what about accessing a static method using an instance?

It's possible in Java to write something like:

   f.classMethod();

where f is an instance of some class, and classMethod() is a class method (i.e. a static method) of that class. This is legal, but it's a bad idea because it creates confusion. The actual instance f is not really important here. Only the declared type of f matters. That is, what class is f declared to be? Since classMethod() is static, the class of f (as determined by the compiler at compile time) is all we need.

Rather than writing:

    f.classMethod();
It would be better coding style to write either:
    Foo.classMethod();
or
    Bar.classMethod(); 
That way, it is crystal clear which class method you would like to call. It is also clear that the method you are calling is indeed a class method.

Barring that, you could always come up with this monstrosity:

    f.getClass().getMethod("classMethod", new Class[]).invoke(null, new Object[]);

But all this could be avoided by simply not trying to override your static (class) methods. :-)

Why does the compiler sometimes talk about overriding static methods?

Sometimes you will see error messages from the compiler that talk about overriding static methods. Apparently, whoever writes these particular messages has not read the Java Language Specification and does not know the difference between overriding and hiding. So they use incorrect and misleading terminology. Just ignore it. The Java Language Specification is very clear about the difference between overriding and hiding, even if the compiler messages are not. Just pretend that the compiler said "hide" rather than "override"..

ref: http://www.coderanch.com/how-to/java/OverridingVsHiding



gembin 2014-05-29 15:52 鍙戣璇勮
]]>
Fuck GFWhttp://www.8634070.com/gembin/archive/2014/05/18/413795.htmlgembingembinSat, 17 May 2014 16:21:00 GMThttp://www.8634070.com/gembin/archive/2014/05/18/413795.htmlhttp://www.8634070.com/gembin/comments/413795.htmlhttp://www.8634070.com/gembin/archive/2014/05/18/413795.html#Feedback1http://www.8634070.com/gembin/comments/commentRss/413795.htmlhttp://www.8634070.com/gembin/services/trackbacks/413795.html Just one word: FUCK!! 
Two words: FUCK YOU!! 
Three words: FUCK YOU Forever!! 

I JUST want to access github !! WHY is this! GFW锛宼he son of a bitch!!!!
 

gembin 2014-05-18 00:21 鍙戣璇勮
]]>
A web-based monitoring tool for WebSphere MQhttp://www.8634070.com/gembin/archive/2013/12/04/407231.htmlgembingembinWed, 04 Dec 2013 15:22:00 GMThttp://www.8634070.com/gembin/archive/2013/12/04/407231.htmlhttp://www.8634070.com/gembin/comments/407231.htmlhttp://www.8634070.com/gembin/archive/2013/12/04/407231.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/407231.htmlhttp://www.8634070.com/gembin/services/trackbacks/407231.html
My developerWorks article on WebSphere MQ
http://www.ibm.com/developerworks/websphere/library/techarticles/1311_jin/1311_jin.html


gembin 2013-12-04 23:22 鍙戣璇勮
]]>
How JavaScript Timers Workhttp://www.8634070.com/gembin/archive/2013/05/27/399816.htmlgembingembinMon, 27 May 2013 05:50:00 GMThttp://www.8634070.com/gembin/archive/2013/05/27/399816.htmlhttp://www.8634070.com/gembin/comments/399816.htmlhttp://www.8634070.com/gembin/archive/2013/05/27/399816.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/399816.htmlhttp://www.8634070.com/gembin/services/trackbacks/399816.htmlAt a fundamental level it’s important to understand how JavaScript timers work. Often times they behave unintuitively because of the single thread which they are in. Let’s start by examining the three functions to which we have access that can construct and manipulate timers.

  • var id = setTimeout(fn, delay); – Initiates a single timer which will call the specified function after the delay. The function returns a unique ID with which the timer can be canceled at a later time.
  • var id = setInterval(fn, delay); – Similar to setTimeout but continually calls the function (with a delay every time) until it is canceled.
  • clearInterval(id);clearTimeout(id); – Accepts a timer ID (returned by either of the aforementioned functions) and stops the timer callback from occurring.

In order to understand how the timers work internally there’s one important concept that needs to be explored: timer delay is not guaranteed. Since all JavaScript in a browser executes on a single thread asynchronous events (such as mouse clicks and timers) are only run when there’s been an opening in the execution. This is best demonstrated with a diagram, like in the following:


(Click to view full size diagram)

There’s a lot of information in this figure to digest but understanding it completely will give you a better realization of how asynchronous JavaScript execution works. This diagram is one dimensional: vertically we have the (wall clock) time, in milliseconds. The blue boxes represent portions of JavaScript being executed. For example the first block of JavaScript executes for approximately 18ms, the mouse click block for approximately 11ms, and so on.

Since JavaScript can only ever execute one piece of code at a time (due to its single-threaded nature) each of these blocks of code are “blocking” the progress of other asynchronous events. This means that when an asynchronous event occurs (like a mouse click, a timer firing, or an XMLHttpRequest completing) it gets queued up to be executed later (how this queueing actually occurs surely varies from browser-to-browser, so consider this to be a simplification).

To start with, within the first block of JavaScript, two timers are initiated: a 10mssetTimeout and a 10ms setInterval. Due to where and when the timer was started it actually fires before we actually complete the first block of code. Note, however, that it does not execute immediately (it is incapable of doing that, because of the threading). Instead that delayed function is queued in order to be executed at the next available moment.

Additionally, within this first JavaScript block we see a mouse click occur. The JavaScript callbacks associated with this asynchronous event (we never know when a user may perform an action, thus it’s consider to be asynchronous) are unable to be executed immediately thus, like the initial timer, it is queued to be executed later.

After the initial block of JavaScript finishes executing the browser immediately asks the question: What is waiting to be executed? In this case both a mouse click handler and a timer callback are waiting. The browser then picks one (the mouse click callback) and executes it immediately. The timer will wait until the next possible time, in order to execute.

Note that while mouse click handler is executing the first interval callback executes. As with the timer its handler is queued for later execution. However, note that when the interval is fired again (when the timer handler is executing) this time that handler execution is dropped. If you were to queue up all interval callbacks when a large block of code is executing the result would be a bunch of intervals executing with no delay between them, upon completion. Instead browsers tend to simply wait until no more interval handlers are queued (for the interval in question) before queuing more.

We can, in fact, see that this is the case when a third interval callback fires while the interval, itself, is executing. This shows us an important fact: Intervals don’t care about what is currently executing, they will queue indiscriminately, even if it means that the time between callbacks will be sacrificed.

Finally, after the second interval callback is finished executing, we can see that there’s nothing left for the JavaScript engine to execute. This means that the browser now waits for a new asynchronous event to occur. We get this at the 50ms mark when the interval fires again. This time, however, there is nothing blocking its execution, so it fires immediately.

Let’s take a look at an example to better illustrate the differences betweensetTimeout and setInterval.

  1. setTimeout(function(){
  2.     /* Some long block of code... */
  3.     setTimeout(arguments.callee, 10);
  4.   }, 10);
  5.  
  6.   setInterval(function(){
  7.     /* Some long block of code... */
  8.   }, 10);

These two pieces of code may appear to be functionally equivalent, at first glance, but they are not. Notably the setTimeout code will always have at least a 10ms delay after the previous callback execution (it may end up being more, but never less) whereas the setInterval will attempt to execute a callback every 10ms regardless of when the last callback was executed.

There’s a lot that we’ve learned here, let’s recap:

  • JavaScript engines only have a single thread, forcing asynchronous events to queue waiting for execution.
  • setTimeout and setInterval are fundamentally different in how they execute asynchronous code.
  • If a timer is blocked from immediately executing it will be delayed until the next possible point of execution (which will be longer than the desired delay).
  • Intervals may execute back-to-back with no delay if they take long enough to execute (longer than the specified delay).

All of this is incredibly important knowledge to build off of. Knowing how a JavaScript engine works, especially with the large number of asynchronous events that typically occur, makes for a great foundation when building an advanced piece of application code.

from: http://ejohn.org/blog/how-javascript-timers-work/




gembin 2013-05-27 13:50 鍙戣璇勮
]]>
Tip of changing the language settings for Websphere MQ Explorerhttp://www.8634070.com/gembin/archive/2013/03/23/396905.htmlgembingembinSat, 23 Mar 2013 09:26:00 GMThttp://www.8634070.com/gembin/archive/2013/03/23/396905.htmlhttp://www.8634070.com/gembin/comments/396905.htmlhttp://www.8634070.com/gembin/archive/2013/03/23/396905.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/396905.htmlhttp://www.8634070.com/gembin/services/trackbacks/396905.htmlOpen <InstallDir>/MQExplorer/eclipse/configuration/config.ini
Add these two lines before eof

org.osgi.framework.language=en
osgi.nl=en_US


gembin 2013-03-23 17:26 鍙戣璇勮
]]>
Mac鎶宸箣璁U鐩樸佺鍔?#32429;?#37929;樺湪鑻规灉鐢佃剳鍜學indows PC閮借兘璇嗗埆/璇诲啓锛屼笖鏀寔4GB澶枃浠?#38171;exFAT鏍煎紡http://www.8634070.com/gembin/archive/2013/03/12/396297.htmlgembingembinMon, 11 Mar 2013 17:27:00 GMThttp://www.8634070.com/gembin/archive/2013/03/12/396297.htmlhttp://www.8634070.com/gembin/comments/396297.htmlhttp://www.8634070.com/gembin/archive/2013/03/12/396297.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/396297.htmlhttp://www.8634070.com/gembin/services/trackbacks/396297.html 濡傛灉鎮殑 U 鐩樸佺鍔?#32429;?#37929;樻棦瑕佺敤浜?PC 鍙?#29781;佺敤浜?#38011;规灉鐢佃剳锛孧ac OS X 绯荤粺?#27537; HFS锛?鍜?Windows ?#27537; NTFS 鏍煎紡鏄剧劧閮戒笉琛?#8230;…HFS+ ?#28266; Windows 涓嬩笉璇嗗埆锛孨TFS 鏍煎紡?#27537; U 鐩樸佺鍔?#32429;?#37929;樻彃?#28266;鑻规灉鐢佃剳涓?#37721;兘璇讳笉?#20824;?#21843;銆?#37837;煎紡?#23538;鎴?FAT32 鏄剧劧鍙?#28000;?#37824;寔涓?#28051;?#32495;荤粺锛屼?#21975;崟涓?#26499;浠?#28598;?#27996;?4GB 灏辨瓏鑿?#37510;?/span>

exFAT 鏍煎紡

    ?#32126;鑻规灉鐢佃剳 Mac OS X 10.6.5 绯荤粺鍋氬嚭浜?#28051;椤规剰涔夐噸澶殑鍗囩骇锛?#37824;寔 exFAT 纾?#37929;?#37837;煎紡锛?#37837;煎紡?#23538;鎴?exFAT 鏍煎紡?#27537; U 鐩樸佺鍔?#32429;?#37929;樺湪 Windows PC 涓?#37724;?#38011;规灉鐢佃剳 Mac OS X 绯荤粺涓嬪潎?#20824;璇诲啓锛?#38000;屼笖鏀寔瓒呰繃鍗?#28051;綋绉?#29906;呰繃 4 GB ?#27537;澶枃浠?#37510;?/p>

    涓嬮潰鏄?#28751;?U 鐩樸佺鍔?#32429;?#37929;?#37837;煎紡?#23538;鎴?exFAT 鏍煎紡?#27537;鏂规硶锛屼互鍙?exFAT銆丗AT32銆丠FS锛?涓夌鏍煎紡涓嬪?#23676;竴鍧?U 鐩樼殑璇诲啓閫熷害娴?#29831;?/p>

鑻规灉鐢佃剳 Mac OS X 绯荤粺涓?#37814;U鐩樸佺鍔?#32429;?#37929;?#37837;煎紡?#23538;鎴恊xFAT鏍煎紡
鑻规灉鐢佃剳 Mac OS X 绯荤粺涓?#37814;U鐩樸佺鍔?#32429;?#37929;?#37837;煎紡?#23538;鎴恊xFAT鏍煎紡

    鐐瑰嚮鑻规灉鐢佃剳灞忓箷鍙?#28051;?#29785;掔殑鏀?#28598;?#38336;?#37816;夐挳锛Sportlight 鎼滅储“纾?#37929;?#23480;叿”锛屽湪纾?#37929;?#23480;叿渚?#26440;规爮閫夋嫨瑕?#37837;煎紡?#23538;?#27537; U 鐩樻垨绉?#37716;?#32429;?#37929;樺?#21975;尯锛?#37721;充晶閫夋嫨“鎶规帀”鏍囩锛屽湪鏍煎紡涓嬫媺鑿?#37719;?#38322;?#38315;夋嫨 ExFAT 鍗?#37721;?#37510;?#28641;?#28051;婂浘鎵绀?#37510;?/p>

Windows 绯荤粺涓?#37814;U鐩樸佺鍔?#32429;?#37929;?#37837;煎紡?#23538;鎴恊xFAT鏍煎紡
Windows 绯荤粺涓?#37814;U鐩樸佺鍔?#32429;?#37929;?#37837;煎紡?#23538;鎴恊xFAT鏍煎紡

    Windows 7 鍜?Vista 榛?#29825;?#28751;?#37824;寔 exFAT 鏍煎紡锛?#28641;傛灉鏄?XP 绯荤粺锛?#29781;?#28051;嬭浇 KB955704 琛?#28051;?#38171;?u style="margin: 0px auto; padding: 0px;">http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=1cbe3906-ddd1-4ca2-b727-c2dff5e30f61

    鑷?#27996;?exFAT 鏍煎紡?#27537; U 鐩樼殑璇诲啓閫熷害锛屼?#23342;潰鏄?#37722;屼竴鍧?U 鐩樺湪鍚屼竴鍙?#37922;佃剳锛?#37812;戠殑 Macbook Pro锛?#28051;婄殑璇诲啓閫熷害娴?#29831;?#38171;屾祴璇曡蒋浠?#28051;?nbsp;浠墠浠嬬粛?#27537;?#21412;璐硅蒋浠?#38171;欰JA System Test銆?br style="margin: 0px auto; padding: 0px;" />

FAT32銆丠FS锛?#37510;乪xFAT 鏍煎紡?#27537; U 鐩?#29831;诲啓閫熷害娴?#29831;? title=
FAT32銆丠FS锛?#37510;乪xFAT 鏍煎紡?#27537; U 鐩?#29831;诲啓閫熷害娴?#29831;?/div>

    椤烘椂閽?#28186;?#23046;?#37828;?FAT32銆丠FS锛?#37510;乪xFAT 鏍煎紡涓?U 鐩?#29831;诲啓閫熷害娴?#29831;?#32513;撴灉锛屼笉澶?#28641;?#37510;傛墍浠?#38171;?#37721;?#37814;?U 鐩樺拰绉?#37716;?#32429;?#37929;樼殑涓涓?#37714;嗗尯锛?#28051;撻棬鐢?#27996;?PC銆丮ac ?#31651;?#26879;浜崲?#26499;浠?#38171;?#37837;煎紡?#23538;鎴?exFAT 灏?#29723;屼簡銆?br />KEEP FOR REF: http://www.mac52ipod.cn/post/use-u-disk-hdd-on-windows-pc-and-mac-os-x-4gb-exfat.php



gembin 2013-03-12 01:27 鍙戣璇勮
]]>JPA Conceptshttp://www.8634070.com/gembin/archive/2013/03/07/396169.htmlgembingembinThu, 07 Mar 2013 08:58:00 GMThttp://www.8634070.com/gembin/archive/2013/03/07/396169.htmlhttp://www.8634070.com/gembin/comments/396169.htmlhttp://www.8634070.com/gembin/archive/2013/03/07/396169.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/396169.htmlhttp://www.8634070.com/gembin/services/trackbacks/396169.html
keep it for reference
http://tomee.apache.org/jpa-concepts.html</div><div>http://www.jpalace.org/docs/tutorials/jee/jpa_2.html


gembin 2013-03-07 16:58 鍙戣璇勮
]]>
JPA Criteria API http://www.8634070.com/gembin/archive/2013/03/06/396131.htmlgembingembinWed, 06 Mar 2013 05:44:00 GMThttp://www.8634070.com/gembin/archive/2013/03/06/396131.htmlhttp://www.8634070.com/gembin/comments/396131.htmlhttp://www.8634070.com/gembin/archive/2013/03/06/396131.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/396131.htmlhttp://www.8634070.com/gembin/services/trackbacks/396131.html
Count
CriteriaBuilder critBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> critQuery = criteriaBuilder.createQuery(Long.class);
Root<Foo> root = critQuery.from(Foo.class);
critQuery.select(critBuilder.countDistinct(root));
int count = entityManager.createQuery(critQuery).getSingleResult().intValue();


 

 Result

CriteriaBuilder critBuilder = entityManager.getCriteriaBuilder(); 
CriteriaQuery<Long> critQuery = criteriaBuilder.createQuery(Long.class);
Root<Foo> root = critQuery.from(Foo.class);
critQuery.select(root).distinct(true);
List<Foo> result = entityManager.createQuery(critQuery).getResultList();


gembin 2013-03-06 13:44 鍙戣璇勮
]]>
Adobe Photoshop Source Code - version 1.0.1http://www.8634070.com/gembin/archive/2013/02/14/395312.htmlgembingembinThu, 14 Feb 2013 08:28:00 GMThttp://www.8634070.com/gembin/archive/2013/02/14/395312.htmlhttp://www.8634070.com/gembin/comments/395312.htmlhttp://www.8634070.com/gembin/archive/2013/02/14/395312.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/395312.htmlhttp://www.8634070.com/gembin/services/trackbacks/395312.htmlpho·to·shop, transitive verb, often capitalized \藞f艒-(藢)t艒-藢shäp\

  1. to alter (a digital image) with Photoshop software or other image-editing software especially in a way that distorts reality (as for deliberately deceptive purposes)

– Merriam-Webster online dictionary, 2012

When brothers Thomas and John Knoll began designing and writing an image editing program in the late 1980s, they could not have imagined that they would be adding a word to the dictionary.

Thomas Knoll

John Knoll


Thomas Knoll, a PhD student in computer vision at the University of Michigan, had written a program in 1987 to display and modify digital images. His brother John, working at the movie visual effects company Industrial Light & Magic, found it useful for editing photos, but it wasn’t intended to be a product. Thomas said, “We developed it originally for our own personal use…it was a lot a fun to do.”

Gradually the program, called “Display”, became more sophisticated. In the summer of 1988 they realized that it indeed could be a credible commercial product. They renamed it “Photoshop” and began to search for a company to distribute it. About 200 copies of version 0.87 were bundled by slide scanner manufacturer Barneyscan as “Barneyscan XP”.

The fate of Photoshop was sealed when Adobe, encouraged by its art director Russell Brown, decided to buy a license to distribute an enhanced version of Photoshop. The deal was finalized in April 1989, and version 1.0 started shipping early in 1990.

Over the next ten years, more than 3 million copies of Photoshop were sold.

  That first version of Photoshop was written primarily in Pascal for the Apple Macintosh, with some machine language for the underlying Motorola 68000 microprocessor where execution efficiency was important. It wasn’t the effort of a huge team. Thomas said, “For version 1, I was the only engineer, and for version 2, we had two engineers.” While Thomas worked on the base application program, John wrote many of the image-processing plug-ins.

With the permission of Adobe Systems Inc., the Computer History Museum is pleased to make available, for non-commercial use, the source code to the 1990 version 1.0.1 of Photoshop. All the code is here with the exception of the MacApp applications library that was licensed from Apple. There are 179 files in the zipped folder, comprising about 128,000 lines of mostly uncommented but well-structured code. By line count, about 75% of the code is in Pascal, about 15% is in 68000 assembler language, and the rest is data of various sorts. To download the code you must agree to the terms of the license.

Download Photoshop version 1.0.1 Source Code

The 1990 version of the Adobe Photoshop User Guide is athttp://www.computerhistory.org/collections/accession/102640940

and the 1990 Adobe Photoshop tutorial is athttp://www.computerhistory.org/collections/accession/102640945 

Commentary on the source code

Software architect Grady Booch is the Chief Scientist for Software Engineering at IBM Research Almaden and a trustee of the Computer History Museum. He offers the following observations about the Photoshop source code:

“Opening the files that constituted the source code for Photoshop 1.0, I felt a bit like Howard Carter as he first breached the tomb of King Tutankhamen. What wonders awaited me?

I was not disappointed by what I found. Indeed, it was a marvelous journey to open up the cunning machinery of an application I’d first used over 20 years ago.

Architecturally, this is a very well-structured system. There’s a consistent separation of interface and abstraction, and the design decisions made to componentize those abstractions – with generally one major type for each combination of interface and implementation — were easy to follow.

The abstractions are quite mature. The consistent naming, the granularity of methods, the almost breathtaking simplicity of the implementations because each type was so well abstracted, all combine to make it easy to discern the texture of the system.

Having the opportunity to examine Photoshop’s current architecture, I believe I see fundamental structures that have persisted, though certainly in more evolved forms, in the modern implementation. Tiles, filters, abstractions for virtual memory (to attend to images far larger than display buffers or main memory could normally handle) are all there in the first version. Yet it had just over 100,000 lines of code, compared to well over 10 million in the current version! Then and now, much of the code is related to input/output and the myriad of file formats that Photoshop has to attend to.

There are only a few comments in the version 1.0 source code, most of which are associated with assembly language snippets. That said, the lack of comments is simply not an issue. This code is so literate, so easy to read, that comments might even have gotten in the way.

It is delightful to find historical vestiges of the time: code to attend to Andy Herzfield’s software for the Thunderscan scanner, support of early TARGA raster graphics file types, and even a few passing references to Barneyscan lie scattered about in the code. These are very small elements of the overall code base, but their appearance reminds me that no code is an island.

This is the kind of code I aspire to write.”

And this is the kind of code we all can learn from. Software source code is the literature of computer scientists, and it deserves to be studied and appreciated. Enjoy a view of Photoshop from the inside.

 

Early Photoshop screenshots*

 

The home screen, showing the available tools.

 

Photoshop allowed you to select brush color as well as size and texture. (The first color Mac was the Macintosh II in 1987.)

 

There were some sophisticated selection tools, and a good assortment of image filters. One important missing feature, which came with version 3 in 1994, was the ability to divide an image into multiple layers.

 

The preferences page allowed for some customization of the features.

 

There was a limited choice of fonts, font sizes, and font styles. The text was entered into this dialog box, then moved into the image.

*Screen shots courtesy of creativebits, www.creativebits.org.
from:  
http://computerhistory.org/atchm/adobe-photoshop-source-code/



gembin 2013-02-14 16:28 鍙戣璇勮
]]>
Thread-safety when injecting JPA EntityManagerhttp://www.8634070.com/gembin/archive/2013/02/04/395088.htmlgembingembinMon, 04 Feb 2013 02:49:00 GMThttp://www.8634070.com/gembin/archive/2013/02/04/395088.htmlhttp://www.8634070.com/gembin/comments/395088.htmlhttp://www.8634070.com/gembin/archive/2013/02/04/395088.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/395088.htmlhttp://www.8634070.com/gembin/services/trackbacks/395088.html闃?#29831;诲叏?#26499;

gembin 2013-02-04 10:49 鍙戣璇勮
]]>
Java Exception Practiceshttp://www.8634070.com/gembin/archive/2012/12/26/393525.htmlgembingembinWed, 26 Dec 2012 15:56:00 GMThttp://www.8634070.com/gembin/archive/2012/12/26/393525.htmlhttp://www.8634070.com/gembin/comments/393525.htmlhttp://www.8634070.com/gembin/archive/2012/12/26/393525.html#Feedback1http://www.8634070.com/gembin/comments/commentRss/393525.htmlhttp://www.8634070.com/gembin/services/trackbacks/393525.htmlJust keep it for reference.

Best Practices for Exception Handling
http://onjava.com/pub/a/onjava/2003/11/19/exceptions.html

The Trouble with Checked Exceptions
http://www.artima.com/intv/handcuffs.html

Exception-Handling Antipatterns
http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html

Exception management and error tracking in J2EE
http://www.javaworld.com/javaworld/jw-07-2005/jw-0711-exception.html?page=1

Exceptional practices
http://www.javaworld.com/javaworld/jw-12-2001/jw-1221-exceptions.html?page=1

Exception Handling
http://www.objectsource.com/j2eechapters/Ch18-Exception_Handling.htm

Spring MVC REST Exception Handling Best Practices 
http://www.stormpath.com/blog/spring-mvc-rest-exception-handling-best-practices-part-1
http://www.stormpath.com/blog/spring-mvc-rest-exception-handling-best-practices-part-2


gembin 2012-12-26 23:56 鍙戣璇勮
]]>
The Trouble with Checked Exceptionshttp://www.8634070.com/gembin/archive/2012/12/26/393523.htmlgembingembinWed, 26 Dec 2012 15:35:00 GMThttp://www.8634070.com/gembin/archive/2012/12/26/393523.htmlhttp://www.8634070.com/gembin/comments/393523.htmlhttp://www.8634070.com/gembin/archive/2012/12/26/393523.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/393523.htmlhttp://www.8634070.com/gembin/services/trackbacks/393523.htmlSummary
Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about versionability and scalability issues with checked exceptions.

Anders Hejlsberg, a distinguished engineer at Microsoft, led the team that designed the C# (pronounced C Sharp) programming language. Hejlsberg first vaulted onto the software world stage in the early eighties by creating a Pascal compiler for MS-DOS and CP/M. A very young company called Borland soon hired Hejlsberg and bought his compiler, which was thereafter marketed as Turbo Pascal. At Borland, Hejlsberg continued to develop Turbo Pascal and eventually led the team that designed Turbo Pascal's replacement: Delphi. In 1996, after 13 years with Borland, Hejlsberg joined Microsoft, where he initially worked as an architect of Visual J++ and the Windows Foundation Classes (WFC). Subsequently, Hejlsberg was chief designer of C# and a key participant in the creation of the .NET framework. Currently, Anders Hejlsberg leads the continued development of the C# programming language.

On July 30, 2003, Bruce Eckel, author of Thinking in C++ and Thinking in Java, and Bill Venners, editor-in-chief of Artima.com, met with Anders Hejlsberg in his office at Microsoft in Redmond, Washington. In this interview, which will be published in multiple installments on Artima.com and on an audio CD-ROM to be released this fall by Bruce Eckel, Anders Hejlsberg discusses many design choices of the C# language and the .NET framework.

  • In Part I: The C# Design Process, Hejlsberg discusses the process used by the team that designed C#, and the relative merits of usability studies and good taste in language design.
  • In this second installment, Hejlsberg discusses versionability and scalability issues with checked exceptions.

    Remaining Neutral on Checked Exceptions

    Bruce Eckel: C# doesn't have checked exceptions. How did you decide whether or not to put checked exceptions into C#?

    Anders Hejlsberg: I see two big issues with checked exceptions: scalability and versionability. I know you've written some about checked exceptions too, and you tend to agree with our line of thinking.

    Bruce Eckel: I used to think that checked exceptions were really great.

    Anders Hejlsberg: Exactly. Frankly, they look really great up front, and there's nothing wrong with the idea. I completely agree that checked exceptions are a wonderful feature. It's just that particular implementations can be problematic. By implementing checked exceptions the way it's done in Java, for example, I think you just take one set of problems and trade them for another set of problems. In the end it's not clear to me that you actually make life any easier. You just make it different.

    Bruce Eckel: Was there a lot of disagreement in the C# design team about checked excpetions?

    Anders Hejlsberg: No, I think there was fairly broad agreement in our design group.

    C# is basically silent on the checked exceptions issue. Once a better solution is known—and trust me we continue to think about it—we can go back and actually put something in place. I'm a strong believer that if you don't have anything right to say, or anything that moves the art forward, then you'd better just be completely silent and neutral, as opposed to trying to lay out a framework.

    If you ask beginning programmers to write a calendar control, they often think to themselves, "Oh, I'm going to write the world's best calendar control! It's going to be polymorphic with respect to the kind of calendar. It will have displayers, and mungers, and this, that, and the other." They need to ship a calendar application in two months. They put all this infrastructure into place in the control, and then spend two days writing a crappy calendar application on top of it. They'll think, "In the next version of the application, I'm going to do so much more."

    Once they start thinking about how they're actually going to implement all of these other concretizations of their abstract design, however, it turns out that their design is completely wrong. And now they've painted themself into a corner, and they have to throw the whole thing out. I have seen that over and over. I'm a strong believer in being minimalistic. Unless you actually are going to solve the general problem, don't try and put in place a framework for solving a specific one, because you don't know what that framework should look like.

    Bruce Eckel: The Extreme Programmers say, "Do the simplest thing that could possibly work."

    Anders Hejlsberg: Yeah, well, Einstein said that, "Do the simplest thing possible, but no simpler." The concern I have about checked exceptions is the handcuffs they put on programmers. You see programmers picking up new APIs that have all these throws clauses, and then you see how convoluted their code gets, and you realize the checked exceptions aren't helping them any. It is sort of these dictatorial API designers telling you how to do your exception handling. They should not be doing that.

    Versioning with Checked Exceptions

    Bill Venners: You mentioned scalability and versioning concerns with respect to checked exceptions. Could you clarify what you mean by those two issues?

    Anders Hejlsberg: Let's start with versioning, because the issues are pretty easy to see there. Let's say I create a method foo that declares it throws exceptions AB, and C. In version two of foo, I want to add a bunch of features, and now foo might throw exception D. It is a breaking change for me to add D to the throws clause of that method, because existing caller of that method will almost certainly not handle that exception.

    Adding a new exception to a throws clause in a new version breaks client code. It's like adding a method to an interface. After you publish an interface, it is for all practical purposes immutable, because any implementation of it might have the methods that you want to add in the next version. So you've got to create a new interface instead. Similarly with exceptions, you would either have to create a whole new method called foo2 that throws more exceptions, or you would have to catch exception D in the new foo, and transform the D into an A,B, or C.

    Bill Venners: But aren't you breaking their code in that case anyway, even in a language without checked exceptions? If the new version of foo is going to throw a new exception that clients should think about handling, isn't their code broken just by the fact that they didn't expect that exception when they wrote the code?

    Anders Hejlsberg: No, because in a lot of cases, people don't care. They're not going to handle any of these exceptions. There's a bottom level exception handler around their message loop. That handler is just going to bring up a dialog that says what went wrong and continue. The programmers protect their code by writing try finally's everywhere, so they'll back out correctly if an exception occurs, but they're not actually interested in handling the exceptions.

    The throws clause, at least the way it's implemented in Java, doesn't necessarily force you to handle the exceptions, but if you don't handle them, it forces you to acknowledge precisely which exceptions might pass through. It requires you to either catch declared exceptions or put them in your own throws clause. To work around this requirement, people do ridiculous things. For example, they decorate every method with, "throws Exception." That just completely defeats the feature, and you just made the programmer write more gobbledy gunk. That doesn't help anybody.

    Bill Venners: So you think the more common case is that callers don't explicitly handle exceptions in deference to a general catch clause further up the call stack?

    Anders Hejlsberg: It is funny how people think that the important thing about exceptions is handling them. That is not the important thing about exceptions. In a well-written application there's a ratio of ten to one, in my opinion, of try finally to try catch. Or in C#, using statements, which are like try finally.

    Bill Venners: What's in the finally?

    Anders Hejlsberg: In the finally, you protect yourself against the exceptions, but you don't actually handle them. Error handling you put somewhere else. Surely in any kind of event-driven application like any kind of modern UI, you typically put an exception handler around your main message pump, and you just handle exceptions as they fall out that way. But you make sure you protect yourself all the way out by deallocating any resources you've grabbed, and so forth. You clean up after yourself, so you're always in a consistent state. You don't want a program where in 100 different places you handle exceptions and pop up error dialogs. What if you want to change the way you put up that dialog box? That's just terrible. The exception handling should be centralized, and you should just protect yourself as the exceptions propagate out to the handler.

    The Scalability of Checked Exceptions

    Bill Venners: What is the scalability issue with checked exceptions?

    Anders Hejlsberg: The scalability issue is somewhat related to the versionability issue. In the small, checked exceptions are very enticing. With a little example, you can show that you've actually checked that you caught the FileNotFoundException, and isn't that great? Well, that's fine when you're just calling one API. The trouble begins when you start building big systems where you're talking to four or five different subsystems. Each subsystem throws four to ten exceptions. Now, each time you walk up the ladder of aggregation, you have this exponential hierarchy below you of exceptions you have to deal with. You end up having to declare 40 exceptions that you might throw. And once you aggregate that with another subsystem you've got 80 exceptions in your throws clause. It just balloons out of control.

    In the large, checked exceptions become such an irritation that people completely circumvent the feature. They either say, "throws Exception," everywhere; or—and I can't tell you how many times I've seen this—they say, "try, da da da da da, catch curly curly." They think, "Oh I'll come back and deal with these empty catch clauses later," and then of course they never do. In those situations, checked exceptions have actually degraded the quality of the system in the large.

    And so, when you take all of these issues, to me it just seems more thinking is needed before we put some kind of checked exceptions mechanism in place for C#. But that said, there's certainly tremendous value in knowing what exceptions can get thrown, and having some sort of tool that checks. I don't think we can construct hard and fast rules down to, it is either a compiler error or not. But I think we can certainly do a lot with analysis tools that detect suspicious code, including uncaught exceptions, and points out those potential holes to you.

    from:  http://www.artima.com/intv/handcuffs.html



gembin 2012-12-26 23:35 鍙戣璇勮
]]>
CentOS 6 瀹夎鍚庡?#28888;湰?#21412;缃?/title><link>http://www.8634070.com/gembin/archive/2012/12/23/393380.html</link><dc:creator>gembin</dc:creator><author>gembin</author><pubDate>Sun, 23 Dec 2012 14:57:00 GMT</pubDate><guid>http://www.8634070.com/gembin/archive/2012/12/23/393380.html</guid><wfw:comment>http://www.8634070.com/gembin/comments/393380.html</wfw:comment><comments>http://www.8634070.com/gembin/archive/2012/12/23/393380.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.8634070.com/gembin/comments/commentRss/393380.html</wfw:commentRss><trackback:ping>http://www.8634070.com/gembin/services/trackbacks/393380.html</trackback:ping><description><![CDATA[<p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong>1</strong><strong>锛?#32515;戠?#28360;厤缃?/strong></p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">锛?锛夊懡浠厤缃?br /># ifconfig eth0 192.168.0.2 netmask 255.255.255.0 銆銆//ip鍦?#37735;銆佸瓙缃戞帺鐮?br /># route add default gw 192.168.0.1 dev eth0銆銆//缃?#37711;?br /># hostname centos 銆銆//璁畻鏈?#37722;?/p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">锛?锛夋枃浠堕厤缃?br /><1>淇?#37824;IP鍦?#37735;<br />淇?#37824;瑰?#29808;簲缃?#37719;殑IP鍦?#37735;?#27537;?#21412;缃枃浠?br /># vi /etc/sysconfig/network-scripts/ifcfg-eth0<br />DEVICE=eth0銆(鎻忚堪缃?#37719;?#28725;瑰簲鐨勮澶囧埆鍚?#38171;屼緥濡ifcfg-eth0?#27537;?#26499;浠?#28051;?#28729;?#28051;篹th0)<br />BOOTPROTO=static銆(璁剧疆缃?#37719;?#38014;?#23536;ip鍦?#37735;?#27537;鏂瑰紡锛?#37721;兘?#27537;閫?#26916;?#28051;簊tatic锛宒hcp鎴朾ootp锛屽?#21975;埆瀵瑰簲闈?#37804;?#37816;?#28729;氱殑ip鍦?#37735;锛?#38315;氳繃dhcp鍗?#29825;?#38014;?#23536;楃殑ip鍦?#37735;锛?#38315;氳繃bootp鍗?#29825;?#38014;?#23536;楃殑ip鍦?#37735;)<br />BROADCAST=192.168.0.255銆(瀵瑰簲?#27537;?#29913;缃?#39582;?#37822;?#37734;?#37735;)<br />HWADDR=00:07:E9:05:E8:B4銆 (瀵瑰簲?#27537;缃?#37719;墿鐞嗗湴鍧)<br />IPADDR=12.168.1.2銆(濡傛灉璁剧疆缃?#37719;?#38014;?#23536;ip鍦?#37735;?#27537;鏂瑰紡涓?#38344;?#37804;?#37816;?#28729;?#38171;屾?#29927;娈?#28751;辨寚瀹?#27996;?#32515;?#37719;?#28725;瑰簲?#27537;ip鍦?#37735;)<br />IPV6INIT=no銆 (寮鍚?#37812;?#37711;抽棴IPv6锛?#37711;抽棴no锛?#23534;鍚痽es)<br />IPV6_AUTOCONF=no銆 (寮鍚?#37812;?#37711;抽棴IPv6鑷?#37716;厤缃?#38171;?#37711;抽棴no锛?#23534;鍚痽es)<br />NETMASK=255.255.255.0銆(缃?#37719;?#28725;瑰簲?#27537;缃戠?#28356;帺鐮?<br />NETWORK=192.168.1.0銆(缃?#37719;?#28725;瑰簲?#27537;缃戠粶鍦?#37735;)<br />ONBOOT=yes銆(绯荤粺鍚?#37716;椂鏄?#37722;?#29825;剧疆姝?#32515;戠?#28356;帴鍙?#38171;?#29825;剧疆涓yes?#26882;锛?#32495;荤粺鍚?#37716;椂?#32314;娲?#23005;?#29825;?#28598;?<br /><br /><2>淇?#37824;?#32515;?#37711;?br />淇?#37824;瑰?#29808;簲缃?#37719;殑缃?#37711;崇殑?#21412;缃枃浠?br /># vi /etc/sysconfig/network<br />NETWORKING=yes銆(琛?#32448;?#32495;荤粺鏄?#37722;?#28003;?#37922;?#32515;戠粶锛屼竴鑸?#29825;剧疆涓yes銆?#28641;傛灉璁?#28051;簄o锛屽垯?#31497;?#20824;浣?#37922;?#32515;戠粶锛?#38000;屼笖寰?#28598;?#32495;荤粺鏈?#37716;?#32459;嬪?#24531;皢鏃?#23049;?#37722;?#37716;?<br />HOSTNAME=centos銆(璁剧疆鏈?#37832;虹殑涓?#37832;?#37722;?#38171;岃繖閲?#29825;剧疆?#27537;涓?#37832;?#37722;?#29781;?#37724;?etc/hosts涓?#29825;剧疆?#27537;涓?#37832;?#37722;?#28725;瑰簲)<br />GATEWAY=192.168.1.1銆(璁剧疆鏈?#37832;?#26473;?#37818;殑缃?#37711;崇殑IP鍦?#37735;銆?#28186;?#28641;?#38171;?#32515;?#37711;?#28051;?0.0.0.2)<br /><br /><3>淇?#37824;DNS<br />淇?#37824;瑰?#29808;簲缃?#37719;殑DNS?#27537;?#21412;缃枃浠?br /># vi /etc/resolv.conf<br />nameserver 202.101.224.68銆(鍩熷悕鏈?#37716;?#37731;?<br />nameserver 202.101.224.69銆(鍩熷悕鏈?#37716;?#37731;?<br /><br /><4>?#22136;鏂?#37722;?#37716;?#32515;戠?#28360;厤缃?br /># service network restart<br />鎴?br /># /etc/init.d/network restart<br /><br /><strong>2</strong><strong>锛庤蒋浠舵簮?#21412;缃?/strong></p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">鍥藉?#21620;熷害杈冨揩?#27537;?#29238;鐢洿鏂版簮濡?#28051;?#38171;?br />http://mirrors.163.com/centos/ 163-缃?#37828;?br />http://mirrors.ta139.com/centos/ 涓?#37733;?#32457;?#37716;?#38315;?#28103;?#38171;?#28766;?#28051;滅鍔?#38171;?br />http://centos.ustc.edu.cn/centos/ 涓?#37733;?#32457;戝鎶鏈?#28598;?#28699;?br />http://mirror.neu.edu.cn/centos/ 涓滃寳澶?#28699;?/p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong>缂?#26440;yum</strong><strong>?#21412;缃枃浠?#38171;?nbsp;</strong><br />#vi /etc/yum.repos.d/CentOS-Base.repo<br />[base]<br />name=CentOS-$releasever - Base<br />mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os<br />#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/<br />baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/<br />http://mirrors.ta139.com/centos/$releasever/os/$basearch/<br />http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/<br />http://mirror.neu.edu.cn/centos/$releasever/os/$basearch/<br />gpgcheck=1<br />gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#released updates <br />[updates]<br />name=CentOS-$releasever - Updates<br />mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates<br />#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/<br />baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/<br />http://mirrors.ta139.com/centos/$releasever/updates/$basearch/<br />http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/<br />http://mirror.neu.edu.cn/centos/$releasever/updates/$basearch/<br />gpgcheck=1<br />gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#additional packages that may be useful<br />[extras]<br />name=CentOS-$releasever - Extras<br />mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras<br />#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/<br />baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/<br />http://mirrors.ta139.com/centos/$releasever/extras/$basearch/<br />http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/<br />http://mirror.neu.edu.cn/centos/$releasever/extras/$basearch/<br />gpgcheck=1<br />gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#additional packages that extend functionality of existing packages<br />[centosplus]<br />name=CentOS-$releasever - Plus<br />mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus<br />#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/<br />baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/<br />http://mirrors.ta139.com/centos/$releasever/centosplus/$basearch/<br />http://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/<br />http://mirror.neu.edu.cn/centos/$releasever/centosplus/$basearch/<br />gpgcheck=1<br />enabled=0<br />gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#contrib - packages by Centos Users<br />[contrib]<br />name=CentOS-$releasever - Contrib<br />mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib<br />#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/<br />baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/<br />http://mirrors.ta139.com/centos/$releasever/contrib/$basearch/<br />http://centos.ustc.edu.cn/centos/$releasever/contrib/$basearch/<br />http://mirror.neu.edu.cn/centos/$releasever/contrib/$basearch/<br />gpgcheck=1<br />enabled=0<br />gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">?#21159;鍚?#28003;?#37922;?#28641;?#28051;嬪懡浠洿鏂?#37714;?#37832;鏂?#32495;荤粺锛?/p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#rpm –import /etc/pki/rpm-gpg-key*</p><span style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">#yum upgrade</span><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong>3</strong><strong>锛?#28729;夎璇?#29815;鍖?/strong></p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">浠?#28729;夎鐩樿繘琛?#28729;夎锛屾?#24807;?#26495;?#29808;簲rpm鍖?#38171;?br />fonts-chinese-3.02-9.6.el5.noarch.rpm<br />fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">鍙?#28000;?#38315;氳繃yum杩?#29723;?#28729;夎锛?#28729;夎鍔?#23049;?#28051;?#38171;?br />#yum groupinstall <language>-support</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">?#28266; 涓婇潰?#27537;?#25057;浠?#28051;?#38171;?lt;language> 鏄?#28051;嬪涔嬩竴: assamese, bengali, chinese, gujarati, hindi, japanese, kannada, korean, malayalam, marathi, oriya, punjabi, sinhala, tamil, thai, 鎴?telegu銆?/p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong>4</strong><strong>锛?#29785;?#37720;嬬缉?#33931;浠?nbsp;</strong><br />#yum install unrar unzip p7zip-full</p><img src ="http://www.8634070.com/gembin/aggbug/393380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.8634070.com/gembin/" target="_blank">gembin</a> 2012-12-23 22:57 <a href="http://www.8634070.com/gembin/archive/2012/12/23/393380.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣璇勮</a></div>]]></description></item><item><title>VirtualBox 瀹夎Centos ?#31651;璁?#38338;?#38095;氭嫙鏈?#38322;岄潰?#27537;鏈?#37716;?#37721;?#38339;?#29785;?#37712;?#37826;规http://www.8634070.com/gembin/archive/2012/12/23/393378.htmlgembingembinSun, 23 Dec 2012 14:40:00 GMThttp://www.8634070.com/gembin/archive/2012/12/23/393378.htmlhttp://www.8634070.com/gembin/comments/393378.htmlhttp://www.8634070.com/gembin/archive/2012/12/23/393378.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/393378.htmlhttp://www.8634070.com/gembin/services/trackbacks/393378.html鎯?#37712;?#37828;繖鏍风殑锛?#37812;戝涔cenots涓鐩?#37828;湪绯荤粺涓?#38322;?#37922;virtualbox閲岄潰瀹夎涓涓?#38095;氭嫙绯荤粺?#27537;鏂瑰紡銆傛瘡娆?#28729;夎?#21612;箣鍚?#38171;?#38318;?#37721;戠?#39041;笉?#20824;璁?#38338;?#38322;岄潰?#27537;80銆?1銆?306绛夎繖浜涘父鐢殑绔?#37721;?#37510;?#28052;?#28751;?#37828;?#29831;?#38171;?#37812;?#37721;兘?#28266;鏈?#37832;?#29825;?#38338;繖浜?#32468;?#37721;?#38171;屾兂浠?#37711;?#28000;?#37832;哄櫒璁?#38338;笉OK浜?#37510;傛兂璧?#28000;墠鑷?#23480;?#28051;?#27996;嗚繖浠?#27996;嬭浜嗘?#23384;暣涓鍛殑?#26882;鍊?#37813;嶇煡?#20158;鏄?#32468;?#37721;殑闂?#26864;樸?#28000;?#28598;?#28051;瀹?#29781;?#29825;板綍涓嬫潵锛屽厤寰?#28051;嬫鍙堝繕璁?#27996;?#37510;?/p>

寮鍚?0銆?1銆?306绔?#37721;?#38171;?/p>

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
/etc/init.d/iptables save
service iptables restart

鍏?#28729;?#38171;屽?#27692;?#27697;?#23337;簡浠墠?#21843;杩囩殑涓绡囨枃绔?#37510;?#37721;戠幇姝枃宸?#32513;?#37828;?#28598;?#28003;欑殑浜?#37510;傚攭銆傛棦?#21159;?#21843;浜?#37510;?#28751;啓瀹屾暣涓鐐瑰惂銆?/p>

涓鑸潵璇?#38171;?#37812;?#28000;笉?#32048;浣?#37922;linux鑷甫?#27537;闃?#37903;?#28583;欑殑銆傚湪IDC鏈?#37812;?#38171;屼汉瀹剁殑闃?#37903;?#28583;?#37828;?#32429;?#28000;?#37510;傝偗瀹氭瘮?#33931;浠?#29781;?#23534;?#28598;?#23536;?#28598;?#37510;?/p>

鍙?#28000;?#28003;?#37922;?#28641;?#28051;?#37826;瑰紡瀵规搷浣?#38339;?#37903;?#28583;?#38171;?br style="margin: 0px; padding: 0px; " />姘?#28052;?#37804;?#37711;?#37818;夐槻鐏?#28583;shell锛?/p>

chkconfig --level 35 iptables off

閫氳繃濡?#28051;嬪懡浠?#37836;?#37930;嬮槻鐏?#28583;?#37828;?#37722;?#37711;抽棴锛?/p>

service iptables status

濡傛灉宸?#32513;?#23005;?#32429;?#37711;抽棴锛屽垯?#32048;杈撳嚭濡?#28051;嬩俊鎭?#38171;?/p>

iptables锛氭湭杩?#29723;岄槻鐏?#28583;?#37510;?/span>

濡傛灉锛屼綘?#27537;鏄?#38011;辨枃鐗?#37832;?#38171;屽垯鍙兘鎻?#32448;?#28103;?#37805;笉澶?#28051;鏍?#37510;?br style="margin: 0px; padding: 0px; " />濡傛灉娌?#37832;夎緭?#22189;绫讳技闃?#37903;?#28583;?#37711;抽棴?#27537;淇?#37805;?#38171;?#37929;?#37818;噸鍚?#32495;荤粺鎴?#38000;?#37813;?#29723;?#28641;?#28051;嬪懡浠?#29831;?#28051;璇?#38171;?/p>

service iptables stop

鍏?#37818;夐槻鐏?#28583;欎箣鍚?#38171;岄偅涔?#37813;鏈?#23534;鍚殑绔?#37721;?#38318;藉?#21973;細?#27610;闇?#32513;?#27996;掕仈缃?#37813;鏈?#27996;?#37510;?#38317;?#28052;?#38171;?#37721;兘?#32048;瀵?#38007;村埆鏈?#37922;?#36423;冪殑浜?#38333;?#28725;?#28003;犵殑绯荤粺?#32033;娲?#37707;氬嚭涓浜?#37934;?#37735;忕殑浜嬫儏銆?/p>

闄?#27996;嗚繖涓?#26473;樻湁涓涓?#28051;滆鏄?#28751;盨ELINUX?#32342;涓帺鎰忓銆?#28641;傛灉闃?#37903;?#28583;?#37824;?#23534;浜嗙鍙?#28052;?#37827;?#23049;曡繘琛?#29825;?#38338;?#37510;?#29831;?#37828;庤繖涓帺鎰忓仛浜?#38340;?#37714;?#38171;?#28598;?#28729;?#28751;?#28729;?#37711;抽棴鍗?#37721;?#37510;?/p>

gembin 2012-12-23 22:40 鍙戣璇勮
]]>
VirtualBox 瀹夎 CentOs 6.3http://www.8634070.com/gembin/archive/2012/12/23/393376.htmlgembingembinSun, 23 Dec 2012 14:15:00 GMThttp://www.8634070.com/gembin/archive/2012/12/23/393376.htmlhttp://www.8634070.com/gembin/comments/393376.htmlhttp://www.8634070.com/gembin/archive/2012/12/23/393376.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/393376.htmlhttp://www.8634070.com/gembin/services/trackbacks/393376.html涓銆佺幆澧?#37721;?#29863;勬簮鍑嗗锛?br style="margin: 0px; padding: 0px; " />1锛夎?#27693;嫙鏈VritualBox 4.2鐗?#37832;?#37510;傜?#24807;害鎼滅储涓嬭浇姝蒋浠?#23536;?#28729;规槗涓嬭浇锛?#37812;?#28051;鑸?#37828;?#37720;诲绌鸿蒋浠?#37724;?#37719;?#37712;涜蒋浠?#32515;戠珯鍘?#28051;嬭浇銆?br style="margin: 0px; padding: 0px; " />2锛塁entOs鐗?#37832;?#38322;?#37922;殑鏄CentOS-6.3-x86_64-minimal.iso锛?#37719;?#37832;灏忓寲瀹夎?#21615;殑鐗?#37832;?#37510;傛渶灏忓寲瀹夎?#21615;増鏈?#23052;?#37832;夊?#24807;舰鐣岄潰锛岃繖鏍锋?#22563;桟PU鍜?#37712;?#28699;樼殑澶?#28598;?#37713;忓皯锛屾墍浠?#38171;屽父?#29238;鐢潵瀹夎鏈?#37716;?#37731;?#32495;荤粺浣?#37922;?#37510;?#38000;屾?#23684;潰鐗?#37832;?#28699;?#28052;?#28003;?#37922;?#28766;?#28598;?#37510;?#38000;?#37812;?#28000;殑鐩殑灏?#37828;?#29781;?#28000;?#37832;?#37716;?#37731;厤缃?#28051;?#37929;?#37837;?#26473;?#29723;?#37510;?br style="margin: 0px; padding: 0px; " />CentOS 6.3 64浣?#28051;嬭浇鍦?#37735;锛?a title="http://mirror.bit.edu.cn/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-minimal.iso" href="http://mirror.bit.edu.cn/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-minimal.iso" target="_blank" style="margin: 0px; padding: 0px; text-decoration: none; color: #0b75b6; ">http://mirror.bit.edu.cn/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-minimal.iso
3锛?#37812;戠殑绯荤粺鏄Win7 64浣嶇殑銆?windows xp 鍜寃indows 7 32浣嶅潎鍙?#37510;?/p>

浜?#37510;?#28729;夎?#21620;厤缃?#38095;氭嫙鏈?#32495;荤粺
1锛?鎵撹?#27693;嫙鏈?#37510;傜劧鍚?#38171;?#38315;夋嫨铏氭嫙鏈?#23480;叿鏍?#28051;婄殑“鏂板缓”鎸夐挳銆?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

 

 

 

 

 

 

 

 

 

 

 

 

2锛夌?#29808;嚮“鏂板缓”鎸夐挳鍚?#38171;?#23534;瑰嚭濡?#28051;?#23534;瑰嚭妗?#38171;?#37812;?#28000;湪鍚?#32457;?#26916;?#38322;岄潰杈?#37711;?#38171;歝entos 6.3 mini銆傝繖涓?#28003;?#32515;殢渚垮?#21843;娌?#37832;?#28000;讳綍闂?#26864;樸?#28641;傛灉锛屼綘濉啓?#27537;鏄痺indows xp?#27537;璇?#38171;屽垯绫诲?#23337;細鑷?#37716;?#37721;樻?#24686;indows锛?#37911;?#37832;?#38007;?#37716;細鍙樻?#24686;indows xp銆傚綋鎴?#28000;?#28617;啓centos 6.3?#27537;?#26882;鍊?#38171;?#32491;诲?#23337;細鑷?#37716;?#37721;樻垚Linux锛?#37911;?#37832;細鍙樻垚 Red Hat銆備絾鏄?#38171;?#37812;?#28000;?#28729;夎?#21615;殑鏄?4浣嶇殑锛屾墍浠?#38171;?#29781;?#28103;?#37824;筊ed Hat (64 bit)銆?br style="margin: 0px; padding: 0px; " />

3锛夌?#29808;嚮“涓嬩竴姝?#8221;锛?#23534;瑰嚭鍐?#28699;樺垎?#21412;?#27537;閫?#26916;规銆傝繖涓?#37734;?#37826;?#37911;瑰埆瑕?#23049;剰锛?#37712;?#28699;樺湪768MB?#32342;涓?#28003;?#32515;?#37828;?#28051;涓?#37714;嗘?#26449;箔銆?#28641;傛灉浣?#27996;庤繖涓繖涓?#37706;?#38171;屽垯瀹夎?#21615;殑?#26882;鍊欎細杩?#37711;瓧绗?#28729;夎?#21614;?#32033;銆?#28598;?#27996;庣瓑浜庤繖涓?#37706;间細杩?#37711;?#37733;惧舰瀹夎?#21615;?#23684;潰銆?#37714;?#23534;濮?#37812;戜笉澶?#37908;?#37806;夊瓧绗?#28729;夎?#21614;?#32033;锛屼竴鐩村湪?#32342;閲岀缁?#27996;?#23536;?#28052;呴兘?#31497;鐭亾涓?#28000;涔?#37510;傚悗?#28528;锛岀?#24807;害鎼滅储绛?#22935;殑?#26882;鍊?#38171;?#37721;戠幇瀹樻柟宸?#32513;?#37832;?#29831;?#37828;?#37510;?#28641;傚浘锛?#37812;?#37714;嗛厤浜?024MB?#27537;鍐?#28699;樸傚浘涓殑缁胯?#33580;殑绾?#28000;?#29723;?#37828;?#37712;?#28699;樻渶浣崇殑鍒嗛厤鍊?#38171;?#29906;呰繃?#32342;涓?#37706;?#38171;?#37721;兘?#32048;閫?#37812;?#32495;荤粺鍐?#28699;樹笉瓒崇殑闂?#26864;樸?br style="margin: 0px; padding: 0px; " />

4锛夌?#29808;嚮“涓嬩竴姝?#8221;淇濇寔榛?#29825;殑閫?#26916;逛笉鍙?#38171;?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

5锛夌?#29808;嚮“鍒涘缓”锛?#23534;瑰嚭閫?#26916;规锛屼?#28615;寔榛?#29825;笉鍙樸?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

6锛夌?#29808;嚮“涓嬩竴姝?#8221;锛?#23534;瑰嚭铏氭嫙纭?#37929;樼?#27946;棿鍒嗛厤?#27537;鏂瑰紡銆?#28051;鑸?#28103;濇寔榛?#29825;笉鍙樸?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

7锛夌?#29808;嚮“涓嬩竴姝?#8221;锛?#29825;剧疆铏氭嫙纭?#37929;?#28003;?#32515;?#37724;?#28598;?#28751;?#37510;傛垜灏嗚?#27693;嫙纭?#37929;樻枃浠剁殑浣?#32515;?#37824;剧疆?#28266;浜G:\VBoxs涓?#38171;?#28598;?#28751;忛厤缃?0GB銆?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

8锛夌?#29808;嚮“鍒涘缓”鎸夐挳锛?#37719;?#28729;?#37812;?#27996;嗗?#30789;?#27693;嫙鏈虹殑鍒涘缓銆備絾鏄?#38171;屾?#26882;鍙?#37828;?#37814;婇厤缃?#37707;氬浜?#37510;?#37719;?#28051;嬫潵?#27537;?#25655;浣滄墠鏄?#28729;夎绯荤粺銆傛?#26882;锛屽湪VBox鍒?#29723;?#38322;岄潰宸?#32513;?#37832;?#27996;嗗?#27693;墠鍒涘缓鐨勮?#27693;嫙鏈?#37510;?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

9锛?#37714;?#23005;?#28051;姝?#38171;?#37812;?#28000;殑?#21412;缃?#39582;舵病鏈夌?#25780;潫銆傚洜涓?#38171;?#23536;?#28598;氭?#21700;櫒鐜板湪?#27537;鍐?#28699;?#38318;?#23480;?#32513;?GB浜?#37510;傝繖?#32048;缁?2浣嶇殑绯荤粺瀹夎?#21620;?#37812;?#28051;浜?#38338;?#26864;樸傛墍浠?#38171;?#37812;?#28000;?#26473;橀渶瑕佹潵?#31223;闄繖浜?#38338;?#26864;樸?#37721;抽敭閫?#28051;?#38171;孷Box鍒?#29723;?#28051;?#37714;氭墠鍒涘缓鐨勮?#27693;嫙鏈?#38171;?#38315;夋嫨“璁剧疆”锛?#38315;夋嫨“绯荤粺”锛?#37712;?#38315;夋嫨“澶勭?#21975;櫒(P)”锛屼細鐪嬪埌涓椤?#38171;氭墿灞?#37911;规?#37510;傛垜浠?#37814;?#28729;冨嬀閫?#28051;?#38171;?#29825;?#38095;氭嫙鏈?#37824;寔4GB浠?#28051;婄殑鍐?#28699;樸?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

10锛夌?#26495;湪鎴?#28000;?#29781;?#37814;奀entos ISO闀滃?#24532;枃浠?#37716;?#26462;藉埌铏氭嫙鏈?#28051;?#37510;傚湪涓婂浘涓殑宸?#28186;?#28051;?#38315;夋嫨“鍌?#28699;?#8221;銆傜劧鍚?#37837;规嵁涓嬪浘涓殑?#25655;浣滆繘琛?#38171;?br style="margin: 0px; padding: 0px; " />

11锛夎?#27693;嫙鏈洪櫎浜?#38336;滃?#24538;繕鍙?#28000;?#28003;?#37922;?#37922;佃剳?#27537;鍏夐?#36779;繘琛?#28729;夎銆?#28641;傚浘锛?br style="margin: 0px; padding: 0px; " />

?#21159;鍚?#37904;瑰嚮“纭?#28729;?#8221;鍗?#37721;?#37510;?/p>

12锛夋?#26882;锛?#37812;?#28000;?#37712;?#37904;瑰嚮VBox宸叿鏍?#28051;婄殑“鍚?#37716;?#8221;鎸夐挳銆?#37904;瑰?#35763;箣?#22688;锛屽?#21620;?#35826;閫?#28051;?#37714;氭墠鎴?#28000;?#37714;涘缓鐨勮?#27693;嫙鏈?#37510;?#28751;变細鍒?#26440;?#28641;?#28051;嬬?#23684;潰锛?br style="margin: 0px; padding: 0px; " />

濡傛灉锛屼綘杩?#37711;繖涓?#37923;岄潰?#31651;?#22688;锛?#23534;瑰嚭濡?#28051;嬮敊璇?#37819;?#32448;?#38171;?br style="margin: 0px; padding: 0px; " />VT-x/AMD-V 纭?#28000;?#37716;?#38315;熷櫒宸茶鍚?#37716;?#38171;屼?#21975;綋?#22688;澶?#27996;?#37827;?#37825;?#37912;?#37804;?#37510;傛偍铏氭嫙鐢佃剳鍐呯殑?#25655;浣?#32495;荤粺灏?#37827;?#23049;曟娴嬪埌64浣嶇殑CPU锛屽洜姝?#28052;?#28751;?#37827;?#23049;?#37722;?#37716;?#8230;.

閭?#28052;?#38171;屼綘瑕佺瀹?#28003;犵殑CPU鏄?#37824;寔64浣嶇殑锛?#37721;?#28000;?#37816;夌収濡?#28051;?#37826;瑰紡杩?#29723;?#29785;?#37712;?#38171;?br style="margin: 0px; padding: 0px; " />1銆?#29831;?#32429;?#29825;?#28003;犵殑iso?#26499;浠?#37812;朌VD涓?4浣嶇殑IOS?#26499;浠?#37510;?br style="margin: 0px; padding: 0px; " />2銆?#29831;?#32429;?#29825;?#28003;犵殑CPU涓?4浣嶇殑CPU銆?br style="margin: 0px; padding: 0px; " />3銆?#29831;?#32429;?#29825;BIOS?#27537;Virtualization鏄?#37722;?#28051;篍nabled銆?#29825;剧疆鏂规硶锛氳繘鍏BIOS—->Advanced BIOS Features—–>Virtualization—->Disabled(棰勮?#24807;?淇?#37824;?#28051;篍nabled锛屽偍瀛?save)锛岄噸鍚?#37510;傛湁浜汢IOS璁剧疆鏂规硶涓?#23005;?#39582;朵笉鐩稿悓锛屾瘮濡?#38171;屾湁浜涚璁?#37832;琕irualization?#32342;涓?#38315;?#26916;硅繘鍘?#37828;?#28751;VT-x涓嶢MD-v涓?#26916;?#29825;剧疆鍒嗗紑?#27537;銆傛墍浠?#38171;?#29781;?#28751;?#28051;?#28051;?#38315;?#26916;?#38318;借璁剧疆涓篍nabled銆?/p>

13锛?#37812;?#28000;?#38315;夋嫨”Install or upgrade an existsing system”锛岀劧鍚?#38171;屾鍑诲洖杞?#38335;?#23536;涓?#28729;夎銆?/p>

14锛夋帴涓嬫潵?#32048;?#27537;鐣岄潰鏄?#29825;?#28003;犳娴?#29781;?#28729;夎?#21615;殑绯荤粺浠嬭川鏄?#37722;?#28729;屾暣鏈夋晥銆傚洜涓?#37812;?#37828;?#28000;?#23005;?#29785;勬?#29371;亾涓嬭浇?#27537;绯荤粺ISO锛屾墍浠?#38171;屽?#28888;湰涓婁笉?#32048;?#22189;鐜?#38338;?#26864;樸傛墍浠?#38171;?#37812;?#38315;夋嫨浜?#8220;Skip”閫?#26916;硅?#23456;繃浠嬭川妫娴?#37510;?#28641;傚浘锛?/p>

 

15锛夊洖杞?#8220;Skip”?#31651;鍚庡嚭鐜?#28641;?#28051;嬬?#23684;潰锛?#38315;夋嫨鐐瑰嚮“Next”銆?/p>

16锛夋鏃朵細?#22189;鐜?#28051;涓?#38315;夋嫨?#32139;?#22688;绯荤粺璇?#29815;?#27537;閫?#26916;?#38171;?#37812;?#28000;偗瀹?#37828;?#38315;夋嫨绠?#32139;涓枃浜?#38171;?#38315;夋嫨?#31651;鍚?#37904;瑰嚮涓嬩竴姝?#37510;?#28641;傚浘锛?/p>

17锛夋鏃朵細?#22189;鐜?#28051;涓?#38335;?#37929;?#29831;?#29815;?#27537;閫夋嫨锛?#37812;?#28000;偗瀹?#37828;?#38315;夋嫨“缇庡?#34249;紡鑻?#29831;?#8221;浜?#37510;?#28052;?#28751;?#37828;?#28103;濇寔榛?#29825;?#38315;?#26916;?#38171;?#37904;瑰嚮“涓嬩竴姝?#8221;鍗?#37721;?#37510;?#28641;傚浘锛?/p>

18锛夊嚭鐜?#28641;?#28051;嬬?#23684;潰锛屼?#28615;寔榛?#29825;?#37719;?#37721;?#38171;岀劧鍚?#37904;瑰嚮“涓嬩竴姝?#8221;缁?#32513;?#23536;涓?#28729;夎銆?#28641;傚浘锛?/p>

19锛夊嚭鐜?#28641;?#28051;嬬?#23684;潰锛?#37904;瑰嚮“鏄?#38171;屽鐣?#37813;鏈夋?#29256;嵁”銆傚洜涓?#38171;屽湪VirtualBox閲岄潰锛屾墍鍋氱殑浠讳綍?#25655;浣?#38318;戒笉?#32048;褰搷鍒扮湡瀹?#32495;荤粺閲岄潰?#27537;鏁版嵁銆傛墍浠?#38171;?#37824;惧績澶?#38003;嗗湴閫夋嫨姝?#26916;瑰惂銆?#28641;傚浘锛?/p>

20锛夌劧鍚庡嚭鐜?#28641;?#28051;嬬?#23684;潰锛?#29781;佹?#20635;垜浠?#28051;鸿繖鍙?#29825;畻鏈?#37721;?#28051;涓?#37722;嶅瓧銆?#23536;?#32480;鍗?#38171;?#37812;?#28000;?#37816;夌収瑕佹?#20634;?#21843;鍗?#37721;?#37510;?#28641;傚浘锛?/p>

21锛夋帴涓嬫潵?#27537;鐣岄潰鏄?#29825;?#37812;?#28000;?#28051;?#37922;佃?#25123;?#21095;疆涓涓椂?#23599;銆傛?#25120;殑閫夋嫨濡傚浘鎵绀?#38171;?/p>

22锛?#37719;?#28051;嬫潵锛屼細瑕佹?#20635;垜浠?#28051;?#27035;?#29825;殑root绯荤粺璐?#37812;?#29825;剧疆涓涓?#28725;?#37934;?#37510;?#28641;傚浘锛?/p>

濡傛灉锛屼綘璁剧疆?#27537;瀵?#37934;佽繃浜庣畝鍗?#37510;?#28641;?#38171;?23456?#32342;鏍风殑瀵?#37934;?#38171;屽垯绯荤粺?#32048;鎻?#32448;?#37812;?#28000;?#38171;屽瘑鐮?#23534;哄害?#31497;澶?#28729;?#37711;?#37510;傛垜浠笉绠?#28729;?#38171;?#37929;?#37818;?#38315;夋嫨“鏃?#29825;?#28641;?#28003;?#38318;戒娇鐢?U)” 鍗?#37721;?#37510;?#28641;傚浘锛?/p>

23锛夊湪鎺?#28051;嬫潵?#27537;鐣岄潰涓?#38171;?#37812;?#28000;?#38315;夋嫨“浣?#37922;?#37813;鏈夌?#27946;棿”?#27537;閫?#26916;硅繘琛?#28729;夎銆?#28641;傛灉锛屼綘鎯冲湪鐢佃剳涓?#29761;?#37721;?#32495;荤粺锛岄偅涔?#29831;蜂笉瑕?#38315;夋嫨姝?#26916;?#37510;傛垜浠?#37828;?#37922;VittualBox瀹屽叏?#31497;鐢?#37815;呭績纭?#37929;樹細?#37837;煎紡?#23538;?#27537;闂?#26864;樸?#28641;傚浘锛?/p>

24锛夌?#29808;嚮“涓嬩竴姝?#8221;?#32048;寮瑰嚭濡?#28051;嬫彁绀烘锛?#37812;?#28000;?#38315;夋嫨“灏嗕慨鏀瑰啓鍏?#32429;?#37929;?#8221;閫夋嫨銆?/p>

25锛塐K銆?#28051;鍒?#28729;屾?#26330;箣鍚?#38171;?#28751;?#29831;?#37813;?#29723;?#28729;夎?#21616;?#22249;?#23337;簡銆傛垜浠兘鍋氱殑灏?#37828;?#32475;?#23536;?#37510;傚綋瀹夎?#21616;?#28056;害100%?#27537;?#26882;鍊?#38171;屼細鎻?#32448;?#37812;?#28000;噸鏂?#23534;?#28725;?#32495;荤粺銆?#37714;版椂鍊?#29825;?#23536;?#37904;瑰?#35826;嵆鍙?#37510;?#28641;傚浘锛?/p>

 
鍙?#38315;夌殑绫诲瀷璇?#37828;?#28641;?#28051;?#38171;?nbsp;
Desktop 銆锛氬?#28888;湰?#27537;妗岄潰绯荤粺锛屽寘鎷父鐢殑妗岄潰?#33931;浠?#38171;?#28641;傛枃妗?#37836;湅宸叿銆?/span>
Minimal Desktop銆锛氬?#28888;湰?#27537;妗岄潰绯荤粺锛屽寘鍚?#37928;勮蒋浠舵洿灏?#37510;?/span>
Minimal锛氬?#28888;湰?#27537;绯荤粺锛屼笉鍚?#37832;?#28000;讳綍鍙?#38315;?#37928;勮蒋浠?#37718;?#37510;?/span>
Basic Server 銆锛?#28729;夎?#21615;殑鍩烘湰绯荤粺?#27537;骞?#37721;?#37824;寔锛屼笉鍖?#37722;?#22935;岄潰銆?/span>
Database Server銆锛氬?#28888;湰绯荤粺骞?#37721;?#38171;?#37716;?#28051;MySQL鍜孭ostgreSQL鏁版嵁搴?#38171;屾棤妗岄潰銆?/span>
Web Server銆锛?/strong>鍩烘湰绯荤粺骞?#37721;?#38171;?#37716;?#28051;奝HP锛學eb server锛岃?#27195;湁MySQL鍜孭ostgreSQL鏁版嵁搴撶殑瀹?#37812;风锛屾棤妗岄潰銆?/span>
Virtual Host锛氬?#28888;湰绯荤粺鍔?#38095;氭?#29111;钩鍙?#37510;?/span>
Software Development Workstation銆锛氬寘鍚蒋浠?#37718;呰澶?#38171;屽?#28888;湰绯荤粺锛岃?#27693;?#29111;寲骞?#37721;?#38171;屾?#23684;潰鐜?#28583;?#38171;?#23534;鍙?#23480;叿銆?/span>

鍒?#23005;?#37711;?#27996;VirtualBox瀹夎Centos 6.3 鏈灏忓寲瀹夎宸?#32513;?#28000;嬬粛瀹屼簡銆?/p>

gembin 2012-12-23 22:15 鍙戣璇勮
]]>
CentOS-璇?#29815;璁剧疆http://www.8634070.com/gembin/archive/2012/12/23/393375.htmlgembingembinSun, 23 Dec 2012 14:08:00 GMThttp://www.8634070.com/gembin/archive/2012/12/23/393375.htmlhttp://www.8634070.com/gembin/comments/393375.htmlhttp://www.8634070.com/gembin/archive/2012/12/23/393375.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/393375.htmlhttp://www.8634070.com/gembin/services/trackbacks/393375.html鏌?#37930;嬫墍鏈夌殑locale璇?#29815;

  1. # locale -a 
  2. # locale -a|grep en 

■ 鏌?#37930;嬪綋?#22688;?#25655;浣?#32495;荤粺浣?#37922;殑璇?#29815;

  1. # echo $LANG 

■ 璁剧疆绯荤粺locale璇?#29815;涓?#28051;枃鐜?#28583;?#38171;?#23000;?#28052;?#37922;熸晥锛?/p>

# vi /etc/sysconfig/i18n

  1. LANG="zh_CN.UTF-8" 

■ 璁剧疆绯荤粺locale璇?#29815;涓?#38011;辨枃鐜?#28583;?#38171;?#23000;?#28052;?#37922;熸晥锛?/p>

  1. LANG="en_US.UTF-8" 

■ 涓存椂鏀?#37721;?#32495;荤粺locale璇?#29815;锛?#38315;?#22189;鏈?#23046;?#37927;诲綍绔?#37719;?#28598;辨晥锛?/p>

  1. # export LANG=zh_CN.UTF-8 

■ 瀹夎涓枃?#29927;?#32139;

  1. # yum install fonts-chinese.noarch 

■ 鎸?#28729;?#28051;枃?#29927;?#32139;璺?#23536;?/p>

# vi /etc/X11/fs/config

  1. catalogue = /usr/X11R6/lib/X11/fonts/misc:unscaled, 
  2.         /usr/X11R6/lib/X11/fonts/75dpi:unscaled, 
  3.         /usr/X11R6/lib/X11/fonts/100dpi:unscaled, 
  4.         /usr/X11R6/lib/X11/fonts/Type1, 
  5.         /usr/share/fonts/default/Type1, 
  6.         , 
  7.         /usr/share/fonts/zh_CN/TrueType, 
  8.         /usr/share/fonts/zh_TW/TrueType 



    鏂规硶2

    淇?#37824;笴entOS杩?#29723;?#37916;?#28583;冪殑榛?#29825;?#29831;?#29815;鐜?#28583;?#37721;?#38322;忓?/p>

    [root@www ~]# vi /etc/profile

    鎵惧埌export璇?#37721;?#38171;屽湪璇?#37721;墠?#28528;鍔?#37711;?/p>

    LANG=”en_US.UTF-8″

    鍐嶅湪export鍚庨潰杩?#37716;LANG

    export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC LANG

    淇?#28699;橀厤缃?#38171;屼慨鏀笴entOS璇?#29815;瀹?#37812;?#37510;?/p>



gembin 2012-12-23 22:08 鍙戣璇勮
]]>
MySQL on Mac OS Xhttp://www.8634070.com/gembin/archive/2012/09/22/388351.htmlgembingembinSat, 22 Sep 2012 15:38:00 GMThttp://www.8634070.com/gembin/archive/2012/09/22/388351.htmlhttp://www.8634070.com/gembin/comments/388351.htmlhttp://www.8634070.com/gembin/archive/2012/09/22/388351.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/388351.htmlhttp://www.8634070.com/gembin/services/trackbacks/388351.htmlIf you have installed the Startup Item, use this command:

shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM start 
(Enter your password, if necessary)
(Press Control-D or enter "exit" to exit the shell)

If you do not use the Startup Item, enter the following command sequence:

shell> cd /usr/local/mysql 
shell> sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
shell> bg
(Press Control-D or enter "exit" to exit the shell)

You should be able to connect to the MySQL server, for example, by running /usr/local/mysql/bin/mysql.
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin


Sequel Pro is a database management app for MySQL databases
http://www.sequelpro.com/


gembin 2012-09-22 23:38 鍙戣璇勮
]]>
ethtool and mii-toolhttp://www.8634070.com/gembin/archive/2012/09/07/387249.htmlgembingembinFri, 07 Sep 2012 06:41:00 GMThttp://www.8634070.com/gembin/archive/2012/09/07/387249.htmlhttp://www.8634070.com/gembin/comments/387249.htmlhttp://www.8634070.com/gembin/archive/2012/09/07/387249.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/387249.htmlhttp://www.8634070.com/gembin/services/trackbacks/387249.htmlmii-tool锛堣繖鏄疞inux涓嬩?#25787;棬璁剧疆缃?#37719;?#23480;?#28003;滄?#32033;?#27537;?#25057;浠?#38171;?/span>
銆銆1. 鏌湅缃?#37719;殑宸?#28003;滄?#32033;锛岃緭鍏懡浠?#38171;?/span>
銆銆#mii-tool -v
銆銆eth0: negotiated 100baseTx-FD, link ok
銆銆product info: vendor 00:aa:00, model 56 rev 0
銆銆basic mode: autonegotiation enabled
銆銆basic status: autonegotiation complete, link ok
銆銆capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
銆銆advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
銆銆link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
銆銆浠?#28000;?#28051;?#28103;?#37805;?#28051;?#37721;?#28000;?#37930;嬪嚭锛岃繖鍧?#32515;?#37719;?#23480;?#28003;滃湪100M鍏?#37721;?#23480;?#38007;?#38315;傚簲妯紡涓?#38171;?#8220;100BaseTx-FD”?#21104;涓?00M Full Duplex銆?/span>
銆銆2. ?#27967;鏀?#32515;?#37719;殑宸?#28003;滄?#32033;锛岃緭鍏懡浠?#38171;?/span>
銆銆#mii-tool -F media [interface]
銆銆media鍙?#38315;夌殑妯紡鏈?00baseTx-FD銆?00baseTx-HD銆?0baseT-FD銆?0baseT-HD绛?#37510;?Interface浠?#29723;?#37813;閫夋嫨?#27537;缃?#37719;?#38171;?#28641;俥th0銆乪th1绛?#38171;岄粯璁?#28051;篹th0銆?/span>
銆銆渚?#28641;?#38171;?#29825;剧疆缃?#37719;?#23480;?#28003;滃湪10M鍗?#37721;?#23480;?#22959;紡涓?#38171;岃緭鍏懡浠?#38171;?/span>
銆銆#mii-tool -F 10baseT-HD eth0
銆銆3. 鎭?#28598;?#32515;?#37719;?#37928;勮嚜閫傚簲宸?#28003;滄?#32033;锛岃緭鍏懡浠?#38171;?/span>
銆銆#mii-tool -r eth0
銆銆?#27967;璇?#32513;嗙殑浣?#37922;?#37826;规硶鍙?#28000;?#37922;mii-tool -h?#28533;鑾?#23536;?#37510;?br />


ethtool/mii-tool

PrintPDF

Linux LAN card: Find out full duplex / half speed or mode

Q. How do I find out if my Lan (NIC) card working at full or halt duplex mode / speed under Linux?

A. LAN card or NIC is use to send and receive data. Technically, we use word Duplex for this functionality. Full duplex means you are able to send and receive data (files) simultaneously. In half duplex, you can either send or receive data at a time (i.e. you cannot send receive data (files) simultaneously). Obviously, full duplex gives you best user experience. However, how can I find out whether I am using full duplex/half duplex speed/mode?
Task: Find full or half duplex speed

You can use dmesg command to find out your duplex mode:

# dmesg | grep -i duplex

Output:

eth0: link up, 100Mbps, full-duplex, lpa 0x45E1

ethtool command

Uss ethtool to display or change ethernet card settings. To display duplex speed, enter:

# ethtool eth1

Output:

Settings for eth1:
Supported ports: [ TP ]
Supported link modes:   10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 10Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: umbg
Wake-on: g
Current message level: 0x00000007 (7)
Link detected: yes

mii-tool command

You can also use mii-tool to find out your duplex mode. Type following command at shell prompt:

# mii-tool


Output:

eth0: negotiated 100baseTx-FD flow-control, link ok

Remember,


1. 100baseTx-FD: 100Mbps full duplex (FD)
2. 100baseTx-HD: 100Mbps half duplex (HD)
3. 10baseT-FD: 10Mbps full duplex (FD)
4. 10baseT-HD: 10Mbps half duplex (HD)

mii-tool utility checks or sets the status of a network interface Media Independent Interface (MII) unit. Most fast ethernet adapters use an MII to autonegotiate link speed and duplex setting. If you are using old card then this utility may not work (use dmesg command).

This utility is useful for forcing specific Ethernet speed and duplex settings too, setup 100Mbps full duplex speed under Linux:

# mii-tool -F 100baseTx-FD


Setup 10Mbps half duplex:

# mii-tool -F 10baseT-HD


source:

http://www.cyberciti.biz/faq/howto-setup-linux-lan-card-find-out-full-duplex-half-speed-or-mode/



gembin 2012-09-07 14:41 鍙戣璇勮
]]>
XML Naming Conventionshttp://www.8634070.com/gembin/archive/2012/08/25/386269.htmlgembingembinSat, 25 Aug 2012 08:43:00 GMThttp://www.8634070.com/gembin/archive/2012/08/25/386269.htmlhttp://www.8634070.com/gembin/comments/386269.htmlhttp://www.8634070.com/gembin/archive/2012/08/25/386269.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/386269.htmlhttp://www.8634070.com/gembin/services/trackbacks/386269.htmlNames can start with dash (-) character.
Names cannot start with numbers or other punctuation characters. 
After the first character, numbers, hyphens, and periods are allowed. 
Names can't contain spaces. 
Names can't contain the colon (:) character. 
Names can't start with the letters xml, in uppercase, lowercase, or mixed.
There can't be a space after the opening <
There can be space before the closing > character. 

Here are some examples of valid names: <first.name> 

Following are some examples of invalid names: 

<xml-element> which starts with xml, 

<123> which starts with a number, 

<your=xml> because the equals sign (=)sign is illegal, and 

<your element> which contains a space.


Case Sensitivity
Most XML standards originating from the W3C tend to use lower case with hyphens.
<first> is different from <FIRST>, which is different from <First>. 

It's a good idea to pick a naming style and stick to it. 
Some examples of common styles are as follows: 

<first_name> 
<firstName> 
<first-name> 
<FirstName>



gembin 2012-08-25 16:43 鍙戣璇勮
]]>
ANSI sequence parser (Node.js) and client-side rendererhttp://www.8634070.com/gembin/archive/2012/07/21/383681.htmlgembingembinSat, 21 Jul 2012 15:16:00 GMThttp://www.8634070.com/gembin/archive/2012/07/21/383681.htmlhttp://www.8634070.com/gembin/comments/383681.htmlhttp://www.8634070.com/gembin/archive/2012/07/21/383681.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383681.htmlhttp://www.8634070.com/gembin/services/trackbacks/383681.html

gembin 2012-07-21 23:16 鍙戣璇勮
]]>
Flash 3d Sokoban Prototype With Alternativa3dhttp://www.8634070.com/gembin/archive/2012/07/21/383679.htmlgembingembinSat, 21 Jul 2012 15:03:00 GMThttp://www.8634070.com/gembin/archive/2012/07/21/383679.htmlhttp://www.8634070.com/gembin/comments/383679.htmlhttp://www.8634070.com/gembin/archive/2012/07/21/383679.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383679.htmlhttp://www.8634070.com/gembin/services/trackbacks/383679.html闃?#29831;诲叏?#26499;

gembin 2012-07-21 23:03 鍙戣璇勮
]]>
Flash 3d Sokoban Prototype With Alternativa3d Textured Versionhttp://www.8634070.com/gembin/archive/2012/07/21/383678.htmlgembingembinSat, 21 Jul 2012 15:00:00 GMThttp://www.8634070.com/gembin/archive/2012/07/21/383678.htmlhttp://www.8634070.com/gembin/comments/383678.htmlhttp://www.8634070.com/gembin/archive/2012/07/21/383678.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383678.htmlhttp://www.8634070.com/gembin/services/trackbacks/383678.html闃?#29831;诲叏?#26499;

gembin 2012-07-21 23:00 鍙戣璇勮
]]>
Flash 3d Sokoban Prototype With Alternativa3d Textured Versionhttp://www.8634070.com/gembin/archive/2012/07/21/383677.htmlgembingembinSat, 21 Jul 2012 14:58:00 GMThttp://www.8634070.com/gembin/archive/2012/07/21/383677.htmlhttp://www.8634070.com/gembin/comments/383677.htmlhttp://www.8634070.com/gembin/archive/2012/07/21/383677.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383677.htmlhttp://www.8634070.com/gembin/services/trackbacks/383677.htmlEmanuele Feronato added textures and some environment to Sokoban game prototype made with Flare3D.

I reproduced this prototype on Alternativa3D engine. And here you can find it:

Generally this port is bit different from Emanuele’s version. I can’t find information about feature like SkyBox in Alternativa3D, so this feature coded manually. Another difference is camera behavior. Emanuele binds camera to object and during rotations player object stand still and only camera fly around by its orbit. In Alternativa3d version object rotates too, this allow us to face player object it to it’s current direction. Camera is not binded to the object directly it is binded to object container and we can manipulate with player object in container, add animations, rotations etc. But both variants are good I think.


Here is source code:

package  { 	import alternativa.Alternativa3D; 	import alternativa.engine3d.containers.*; 	import alternativa.engine3d.controllers.*; 	import alternativa.engine3d.core.Camera3D; 	import alternativa.engine3d.core.Clipping; 	import alternativa.engine3d.core.Debug; 	import alternativa.engine3d.core.MipMapping; 	import alternativa.engine3d.core.MouseEvent3D; 	import alternativa.engine3d.core.Object3D; 	import alternativa.engine3d.core.Object3DContainer; 	import alternativa.engine3d.core.Sorting; 	import alternativa.engine3d.core.View; 	import alternativa.engine3d.materials.FillMaterial; 	import alternativa.engine3d.materials.TextureMaterial; 	import alternativa.engine3d.objects.Sprite3D; 	import alternativa.engine3d.primitives.Box; 	import alternativa.engine3d.primitives.Plane; 	import alternativa.engine3d.primitives.Sphere; 	 	import flash.display.BitmapData; 	import flash.display.BlendMode; 	import flash.display.Sprite; 	import flash.display.StageAlign; 	import flash.display.StageQuality; 	import flash.display.StageScaleMode; 	import flash.events.Event; 	import flash.events.KeyboardEvent; 	import flash.filters.GlowFilter; 	import flash.geom.ColorTransform; 	import flash.geom.Vector3D; 	import flash.sampler.NewObjectSample; 	import flash.system.Capabilities; 	import flash.ui.Keyboard; 		 	[SWF(backgroundColor="#000000", frameRate="100", width="640", height="480")] 	public class alternativa3dSokoban extends Sprite  	{ 		private const CUBESIZE:Number=10; 		//embeding textures images 		[Embed(source="resource/crateTextureImg.jpg")] static private const crateTextureImg:Class; 		[Embed(source="resource/floorTextureImg.png")] static private const floorTextureImg:Class; 		[Embed(source="resource/crateTopTextureImg.jpg")] static private const crateTopTextureImg:Class; 		[Embed(source="resource/crateTopGoalTextureImg.jpg")] static private const crateTopGoalTextureImg:Class; 		[Embed(source="resource/wallTextureImg.png")] static private const wallTextureImg:Class; 		[Embed(source="resource/goalTextureImg.jpg")] static private const goalTextureImg:Class; 		[Embed(source="resource/playerTextureImg.jpg")] static private const playerTextureImg:Class; 		[Embed(source="resource/backBitmapImg.jpg")] static private const backTextureImg:Class; 		[Embed(source="resource/backBottomBitmapImg.jpg")] static private const backBottomTextureImg:Class;  		// sokobal demo level and player position 		private var levels:Array=[[1,1,1,1,0,0,0,0],[1,0,0,1,1,1,1,1],[1,0,2,0,0,3,0,1],[1,0,3,0,0,2,4,1],[1,1,1,0,0,1,1,1],[0,0,1,1,1,1,0,0]]; 		private var playerCol:uint; 		private var playerRow:uint; 		private var playerRotation:Number=0; 		private var playerAngle:Number=0; 		private var playerMovement:Number=0; 		private var dRow:int; 		private var dCol:int; 		 		// alternativa3d  engine variables 		private var camera:Camera3D; 		private var controller:SimpleObjectController; 		private var container:ConflictContainer;			 		private var frame:Sprite = new Sprite(); 		public var player:Sphere;// Sphere primitive representing the player 		public var cplayer:SimpleObjectController; //controller for player object 		public var conplayer:Object3DContainer; //container for player 		private var movingCrate:Box;// cube primitive representing the moving crate		 			 		// textures		 		private var crateTexture:TextureMaterial = new TextureMaterial(new crateTextureImg().bitmapData); 		private var floorTexture:TextureMaterial = new TextureMaterial(new floorTextureImg().bitmapData); 		private var crateTopTexture:TextureMaterial = new TextureMaterial(new crateTopTextureImg().bitmapData); 		private var crateTopGoalTexture:TextureMaterial = new TextureMaterial(new crateTopGoalTextureImg().bitmapData); 		private var wallTexture:TextureMaterial = new TextureMaterial(new wallTextureImg().bitmapData); 		private var goalTexture:TextureMaterial = new TextureMaterial(new goalTextureImg().bitmapData); 		private var playerTexture:TextureMaterial = new TextureMaterial(new playerTextureImg().bitmapData); 		// SkyBox textures 		private var backTexture:TextureMaterial = new TextureMaterial(new backTextureImg().bitmapData); 		private var backBottomTexture:TextureMaterial = new TextureMaterial(new backBottomTextureImg().bitmapData); 						 		public function alternativa3dSokoban()  		{			 			stage.scaleMode = StageScaleMode.NO_SCALE; 			stage.align = StageAlign.TOP_LEFT; 			stage.quality = StageQuality.BEST; 			 			// Camera 			camera = new Camera3D(); 			camera.view = new View(640, 480); 			addChild(camera.view); 						 			// Camera controller 			controller = new SimpleObjectController(stage, camera, 200, 3); 			 			// Root object 			container = new ConflictContainer(); 			container.resolveByAABB = true; 			container.resolveByOOBB = true; 			 			//Player controller 			conplayer = new Object3DContainer(); 			cplayer = new SimpleObjectController(stage, player, 3); 			 //i am not shure about SkyBox in Alternativa and will prepare it manually 			var backBottom:Plane = new Plane(200*CUBESIZE/2,200*CUBESIZE/2); 			backBottom.setMaterialToAllFaces(backBottomTexture); 			backBottom.x = 0; 			backBottom.y = -100*CUBESIZE/2; 			backBottom.z = 0; 			backBottom.rotationX = 90*Math.PI/180; 			container.addChild(backBottom); 			 			var backLeft:Plane = new Plane(200*CUBESIZE/2,200*CUBESIZE/2); 			backLeft.setMaterialToAllFaces(backTexture); 			backLeft.x = 0; 			backLeft.y = 0; 			backLeft.z = 100*CUBESIZE/2; 			container.addChild(backLeft);  			var backRight:Plane = new Plane(200*CUBESIZE/2,200*CUBESIZE/2); 			backRight.setMaterialToAllFaces(backTexture); 			backRight.x = 0; 			backRight.y = 0; 			backRight.z = -100*CUBESIZE/2; 			container.addChild(backRight);  			var backFront:Plane = new Plane(200*CUBESIZE/2,200*CUBESIZE/2); 			backFront.setMaterialToAllFaces(backTexture); 			backFront.x = -100*CUBESIZE/2; 			backFront.y = 0; 			backFront.z = 0; 			backFront.rotationY = 90*Math.PI/180; 			container.addChild(backFront);  			var backBack:Plane = new Plane(200*CUBESIZE/2,200*CUBESIZE/2); 			backBack.setMaterialToAllFaces(backTexture); 			backBack.x = 100*CUBESIZE/2; 			backBack.y = 0; 			backBack.z = 0; 			backBack.rotationY = 90*Math.PI/180; 			container.addChild(backBack); // end SkyBox 			 			var box:Box; 			/* 			[[1,1,1,1,0,0,0,0], 			 [1,0,0,1,1,1,1,1], 			 [1,0,2,0,0,3,0,1], 			 [1,0,3,0,0,2,4,1], 			 [1,1,1,0,0,1,1,1], 			 [0,0,1,1,1,1,0,0]]; 			*/ 			// level construction 			for (var i:uint=0; i<6; i++)  			{ 				for (var j:uint=0; j<8; j++)  				{ 					switch (levels[i][j])  					{ 						case 0 : 							box = new Box(CUBESIZE,CUBESIZE/2,CUBESIZE,1,1); 							box.setMaterialToAllFaces(floorTexture); 							box.x = CUBESIZE*j; 							box.y = 0; 							box.z = CUBESIZE*i; 							container.addChild(box); 							break; 						case 1 : 							box = new Box(CUBESIZE,CUBESIZE/2,CUBESIZE,1); 							box.setMaterialToAllFaces(floorTexture); 							box.x = CUBESIZE*j; 							box.y = 0; 							box.z = CUBESIZE*i; 							container.addChild(box); 							 							box = new Box(CUBESIZE,CUBESIZE,CUBESIZE,1); 							box.setMaterialToAllFaces(wallTexture); 							box.x = CUBESIZE*j; 							box.y = CUBESIZE*3/4; 							box.z = CUBESIZE*i; 							container.addChild(box); 							break; 						case 2 : 							box = new Box(CUBESIZE,CUBESIZE/2,CUBESIZE,1); 							box.setMaterialToAllFaces(goalTexture); 							box.x = CUBESIZE*j; 							box.y = 0; 							box.z = CUBESIZE*i; 							container.addChild(box); 							break; 						case 3 : 							box = new Box(CUBESIZE,CUBESIZE/2,CUBESIZE,1); 							box.setMaterialToAllFaces(floorTexture); 							box.x = CUBESIZE*j; 							box.y = 0; 							box.z = CUBESIZE*i; 							container.addChild(box); 							box = new Box(CUBESIZE,CUBESIZE,CUBESIZE,1); 							box.name = "crate_"+i+"_"+j; 							box.setMaterialToAllFaces(crateTexture); 							box.x = CUBESIZE*j; 							box.y = CUBESIZE*3/4; 							box.z = CUBESIZE*i; 							box.rotationX -= 90*Math.PI/180; 							// top of the crate 							box.faces[4].material=crateTopTexture; 							box.faces[5].material=crateTopTexture;  							container.addChild(box); 							break; 						case 4 : 							box = new Box(CUBESIZE,CUBESIZE/2,CUBESIZE,1); 							box.setMaterialToAllFaces(floorTexture); 							box.x = CUBESIZE*j; 							box.y = 0; 							box.z = CUBESIZE*i; 							container.addChild(box); 														 							player = new Sphere(CUBESIZE/2,16,16,false,playerTexture);  							conplayer.addChild(player); 							conplayer.visible = true; 							conplayer.x = CUBESIZE*j; 							conplayer.y = CUBESIZE*3/4; 							conplayer.z = CUBESIZE*i; 							conplayer.rotationX -= 90*Math.PI/180; 							container.addChild(conplayer); 							playerCol=j; 							playerRow=i; 							break; 					} 				} 			}  			// Adding camera 			container.addChild(camera); 			 			// View frame 			addChild(frame);												 			onResize();		 			stage.addEventListener(Event.ENTER_FRAME, updateEvent);			 			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDwn);		 			stage.addEventListener(Event.RESIZE, onResize); 		}  		private function onKeyDwn(e:KeyboardEvent):void  		{ 			if (playerRotation==0&&playerMovement==0)  			{ 				switch (e.keyCode)  				{ 					case Keyboard.LEFT : 						playerRotation=+9; 						playerAngle+=90; 						break; 					case Keyboard.RIGHT : 						playerRotation=-9; 						playerAngle-=90; 						break; 					case Keyboard.UP : 						movingCrate=null; 						playerAngle=Math.round(conplayer.rotationY*180/Math.PI)%360; 						if (playerAngle<0)  						{ 							playerAngle+=360; 						} 						// we have to determine the difference between current row and column 						// and the new row and column according to player heading 						switch (playerAngle)  						{ 							case 0 : 								dRow=0; 								dCol=-1; 								break; 							case 90 : 								//dRow=-1; 								dRow=1; 								dCol=0; 								break; 							case 180 : 								dRow=0; 								dCol=1; 								break; 							case 270 : 								//dRow=1; 								dRow=-1; 								dCol=0; 								break; 						} 						if (levels[playerRow+dRow][playerCol+dCol]==0||levels[playerRow+dRow][playerCol+dCol]==2)  						{ 							// the player can move 							playerMovement=-CUBESIZE/10; 						}  						else  						{ 							if (levels[playerRow+dRow][playerCol+dCol]==3||levels[playerRow+dRow][playerCol+dCol]==5) { 								if (levels[playerRow+2*dRow][playerCol+2*dCol]==0||levels[playerRow+2*dRow][playerCol+2*dCol]==2) { 									// the player can move and can push a crate 									movingCrate=container.getChildByName("crate_"+(playerRow+dRow)+"_"+(playerCol+dCol))as Box; 									playerMovement=-CUBESIZE/10; 								} 							} 						} 						break;  				} 			} 		}   		public function updateEvent(e:Event):void  		{		 				if (playerRotation)  				{ 					conplayer.rotationY+=playerRotation*Math.PI/180; 					 					if (Math.abs(Math.round(conplayer.rotationY*180/Math.PI))%90==0) 					{ 						playerRotation=0; 					} 				} 				 				if (playerMovement)  				{					 					switch (playerAngle)  					{ 					case 0 : 						conplayer.x += playerMovement; 						player.rotationY -= 18*Math.PI/180; 					break; 					case 90 : 						conplayer.z += -playerMovement; 						player.rotationY -= 18*Math.PI/180; 					break; 					case 180 : 						conplayer.x += -playerMovement; 						player.rotationY -= 18*Math.PI/180; 						break; 					case 270 : 						conplayer.z += playerMovement; 						player.rotationY -= 18*Math.PI/180; 						break; 					} 					 					if (movingCrate)  					{ 						switch (playerAngle)  						{ 							case 0 : 								movingCrate.x += playerMovement; 								break; 							case 90 : 								movingCrate.z += -playerMovement; 								break; 							case 180 : 								movingCrate.x += -playerMovement; 								break; 							case 270 : 								movingCrate.z += playerMovement; 								break; 						} 					}  					// we need this to know if the player stopped on the destination tile 					if ((playerAngle%180==0&&(Math.round(conplayer.x*10)/10)%CUBESIZE==0)||(playerAngle%180!=0&&(Math.round(conplayer.z*10)/10)%CUBESIZE==0))  					{ 						playerMovement=0; 						levels[playerRow+dRow][playerCol+dCol]+=4; 						levels[playerRow][playerCol]-=4; 						if (movingCrate) { 							levels[playerRow+2*dRow][playerCol+2*dCol]+=3; 							if (levels[playerRow+2*dRow][playerCol+2*dCol]==5) { 								// changing materials on the fly 								movingCrate.setMaterialToAllFaces(crateTexture); 								// top of the crate on goal 								movingCrate.faces[4].material=crateTopGoalTexture; 								movingCrate.faces[5].material=crateTopGoalTexture;								  							} 							else  							{ 								//movingCrate.setMaterialToAllFaces(crateMaterial); 								movingCrate.setMaterialToAllFaces(crateTexture); 								// top of the crate 								movingCrate.faces[4].material=crateTopTexture; 								movingCrate.faces[5].material=crateTopTexture;								 							} 							levels[playerRow+dRow][playerCol+dCol]-=3; 							movingCrate.name="crate_"+(playerRow+2*dRow)+"_"+(playerCol+2*dCol); 						} 						playerCol+=dCol; 						playerRow+=dRow; 					} 				}  				onEnterFrame(); 		}			  		public function correct_camera_angles():void 		{ 			//set camera position 			var r:Number = 10*CUBESIZE/3;			 			var a:Number = -conplayer.rotationY; 			var cx:Number = conplayer.x+Math.cos(a)*r; 			var cz:Number = conplayer.z+Math.sin(a)*r; 			var cy:Number = conplayer.y+r;			 			controller.setObjectPosXYZ(cx,cy,cz); 			 			//look at player box 			controller.lookAtXYZ(conplayer.x,conplayer.y,conplayer.z); 			 			//correct camera angles			 				var cprotY:Number; 				 				cprotY=Math.round(conplayer.rotationY*180/Math.PI)%360;			 				if (cprotY<0)  				{ 					cprotY+=360; 				} 				if (cprotY>180) 				{ 					camera.rotationX = camera.rotationX + (90*Math.PI/180)*Math.sin((cprotY%180)*Math.PI/180); 				}										 				camera.rotationY = camera.rotationY+90*Math.PI/180-conplayer.rotationY; 		} 		 		public function onEnterFrame(e:Event = null):void  		{ 			controller.update(); 			correct_camera_angles(); 			cplayer.update(); 			camera.render();		 		} 		  		public function onResize(e:Event = null):void  		{ 			//here you can add border size for view 			var pd:Number = 0; 			camera.view.width = stage.stageWidth - pd*2; 			camera.view.height = stage.stageHeight - pd*2; 			camera.view.x = pd; 			camera.view.y = pd; 			 			frame.graphics.clear(); 			frame.graphics.beginFill(0x000000, 0); 			frame.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); 			//frame.graphics.lineStyle(0, 0x7F7F7F); 			frame.graphics.drawRect(pd, pd, camera.view.width, camera.view.height); 			frame.graphics.endFill(); 		} 	} }

Here you can download sources.



gembin 2012-07-21 22:58 鍙戣璇勮
]]>
Embedding fonts into ActionScript 3 projecthttp://www.8634070.com/gembin/archive/2012/07/21/383676.htmlgembingembinSat, 21 Jul 2012 14:56:00 GMThttp://www.8634070.com/gembin/archive/2012/07/21/383676.htmlhttp://www.8634070.com/gembin/comments/383676.htmlhttp://www.8634070.com/gembin/archive/2012/07/21/383676.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383676.htmlhttp://www.8634070.com/gembin/services/trackbacks/383676.html闃?#29831;诲叏?#26499;

gembin 2012-07-21 22:56 鍙戣璇勮
]]>
Setting up the VNC Server in Mac OS X Lionhttp://www.8634070.com/gembin/archive/2012/07/14/383070.htmlgembingembinFri, 13 Jul 2012 16:00:00 GMThttp://www.8634070.com/gembin/archive/2012/07/14/383070.htmlhttp://www.8634070.com/gembin/comments/383070.htmlhttp://www.8634070.com/gembin/archive/2012/07/14/383070.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383070.htmlhttp://www.8634070.com/gembin/services/trackbacks/383070.html

VNC server is included in every edition of Mac OS X, including Mac OS X 10.6 –aka Snow Leopard. You can start the server through a hidden check box in the Sharing preferences.

VNC server lets you control your Mac from another computer using the VNCprotocol. With recent editions of Mac OS X, Apple has moved to a more sophisticated method of screen sharing. However, a traditional VNC server is still included but is turned off by default.

Starting the Mac OS X VNC Server
  1. Launch the System Preferences.

    Launch the System Preferences

    Launch the System Preferences

  2. Select the Sharingpreferences.

    Select the Sharing preferences icon

    Select the Sharing preferences icon

  3. Enable Screen Sharing within the Servicelist.

    Enable the Screen Sharing service

    Enable the Screen Sharing service

  4. Click Computer Settings…to show the VNC password setting.

    Enable VNC and choose a password

    Enable VNC and choose a password

  5. Enable VNC viewers may control screen with password:.
  6. Enter a strong password.
  7. Click OK to save your settings.

Your Mac is now running a traditional VNC server. You can now connect to your Mac using a VNC client running on another Mac, Windows, or Linux computer.

NOTE: the default vnc listening port is 5900



gembin 2012-07-14 00:00 鍙戣璇勮
]]>
Enable Telnet in MAC OS X Lionhttp://www.8634070.com/gembin/archive/2012/07/13/383063.htmlgembingembinFri, 13 Jul 2012 14:43:00 GMThttp://www.8634070.com/gembin/archive/2012/07/13/383063.htmlhttp://www.8634070.com/gembin/comments/383063.htmlhttp://www.8634070.com/gembin/archive/2012/07/13/383063.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/383063.htmlhttp://www.8634070.com/gembin/services/trackbacks/383063.html[gembin@localhost bin]$ sudo launchctl
Password:
launchd% 
launchd% load -F /System/Library/LaunchDaemons/telnet.plist
launchd% exit

and now the telnet is enabled, try to test it.
[gembin@localhost bin]$ telnet localhost
Trying ::1...
Connected to localhost.
Escape character is '^]'.
login: gembin
Password:
Last login: Fri Jul 13 22:21:08 on ttys002


gembin 2012-07-13 22:43 鍙戣璇勮
]]>
Comparing the syntax of Java 5 and ActionScript 3http://www.8634070.com/gembin/archive/2012/07/07/382482.htmlgembingembinSat, 07 Jul 2012 14:44:00 GMThttp://www.8634070.com/gembin/archive/2012/07/07/382482.htmlhttp://www.8634070.com/gembin/comments/382482.htmlhttp://www.8634070.com/gembin/archive/2012/07/07/382482.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/382482.htmlhttp://www.8634070.com/gembin/services/trackbacks/382482.html

This list is not complete, and your input is appreciated.

Concept/Language Construct

Java 5.0

ActionScript 3.0

Class library packaging

.jar

.swc

Inheritance

class Employee extends Person{…}

class Employee extends Person{…}

Variable declaration and initialization

String firstName=”John”;

Date shipDate=new Date();

int i;

int a, b=10;

double salary;

var firstName:String=”John”;

var shipDate:Date=new Date();

var i:int;

var a:int, b:int=10;

var salary:Number;

Undeclared variables

n/a

It’s an equivalent to the wild card type notation *. If you declare a variable but do not specify its type, the * type will apply.

A default value: undefined

var myVar:*;

Variable scopes

block: declared within curly braces,
local: declared within a method or a block

member: declared on the class level

no global variables

No block scope: the minimal scope is a function

local: declared within a function

member: declared on the class level

If a variable is declared outside of any function or class definition, it has global scope.

Strings

Immutable, store sequences of two-byte Unicode characters

Immutable, store sequences of two-byte Unicode characters

Terminating statements with semicolons

A must

If you write one statement per line you can omit it.

Strict equality operator

n/a

===

for strict non-equality use

!==

Constant qualifier

The keyword final

final int STATE=”NY”;

The keyword const

const STATE:int =”NY”;

Type checking

Static (checked at compile time)

Dynamic (checked at run-time) and static (it’s so called ‘strict mode’, which is default in Flex Builder)

Type check operator

instanceof

is – checks data type, i.e. if (myVar is String){…}

The is operator is a replacement of older instanceof

The as operator

n/a

Similar to is operator, but returns not Boolean, but the result of expression:

var orderId:String=”123”;

var orderIdN:Number=orderId as Number;

trace(orderIdN);//prints 123

Primitives

byte, int, long, float, double,short, boolean, char

all primitives in ActionScript areobjects.
Boolean, int, uint, Number, String

The following lines are equivalent;

var age:int = 25;

var age:int = new int(25);

Complex types

n/a

Array, Date, Error, Function, RegExp, XML, and XMLList

Array declaration and instantiation

int quarterResults[];

quarterResults =
new int[4];

int quarterResults[]={25,33,56,84};

var quarterResults:Array
=new Array();

or

var quarterResults:Array=[];

var quarterResults:Array=
[25, 33, 56, 84];

AS3 also has associative arrays that uses named elements instead of numeric indexes (similar to Hashtable).

The top class in the inheritance tree

Object

Object

Casting syntax: cast the class Object to Person:

Person p=(Person) myObject;

var p:Person= Person(myObject);

or

var p:Person= myObject as Person;

upcasting

class Xyz extends Abc{}

Abc myObj = new Xyz();

class Xyz extends Abc{}

var myObj:Abc=new Xyz();

Un-typed variable

n/a

var myObject:*

var myObject:

packages

package com.xyz;

class myClass {…}

package com.xyz{

class myClass{…}

}

ActionScript packages can include not only classes, but separate functions as well

Class access levels

public, private, protected

if none is specified, classes have package access level

public, private, protected

if none is specified, classes haveinternal access level (similar to package access level in Java)

Custom access levels: namespaces

n/a

Similar to XML namespaces.

namespace abc;

abc function myCalc(){}

or

abc::myCalc(){}

use namespace abc ;

Console output

System.out.println();

// in debug mode only

trace();

imports

import com.abc.*;

import com.abc.MyClass;

import com.abc.*;

import com.abc.MyClass;

packages must be imported even if the class names are fully qualified in the code.

Unordered key-value pairs

Hashtable, Map

Hashtable friends = new Hashtable();

friends.put(“good”,
“Mary”);

friends.put(“best”,
“Bill”);

friends.put(“bad”,
“Masha”);

String bestFriend= friends.get(“best”);

// bestFriend is Bill

Associative Arrays

Allows referencing its elements by names instead of indexes.

var friends:Array=new Array();
friends["good"]=”Mary”;

friends["best"]=”Bill”;

friends["bad"]=”Masha”;

var bestFriend:String= friends[“best”]

friends.best=”Alex”;

Another syntax:

var car:Object = {make:”Toyota”, model:”Camry”};

trace (car["make"], car.model);

// Output: Toyota Camry

Hoisting

n/a

Compiler moves all variable declarations to the top of the function, so you can use a variable name even before it’s been explicitly declared in the code.

Instantiation objects from classes

Customer cmr = new Customer();

Class cls = Class.forName(“Customer”);

Object myObj= cls.newInstance();

var cmr:Customer = new Customer();

var cls:Class = flash.util.getClassByName(“Customer”);
var myObj:Object = new cls();

Private classes

private class myClass{…}

There is no private classes in AS3.

Private constructors

Supported. Typical use: singleton classes.

Not available. Implementation of private constructors is postponed as they are not the part of the ECMAScript standard yet.

To create a Singleton, use public static getInstance(), which sets a private flag instanceExists after the first instantiation. Check this flag in the public constructor, and if instanceExists==true, throw an error.

Class and file names

A file can have multiple class declarations, but only one of them can be public, and the file must have the same name as this class.

A file can have multiple class declarations, but only one of them can be placed inside the package declaration, and the file must have the same name as this class.

What can be placed in a package

Classes and interfaces

Classes, interfaces, variables, functions, namespaces, and executable statements.

Dynamic classes (define an object that can be altered at runtime by adding or changing properties and methods).

n/a

dynamic class Person {

var name:String;

}

//Dynamically add a variable // and a function

var p:Person = new Person();

p.name=”Joe”;

p.age=25;

p.printMe = function () {

trace (p.name, p.age);

}

p.printMe(); // Joe 25

function closures

n/a. Closure is a proposed addition to Java 7.

myButton.addEventListener(“click”, myMethod);

A closure is an object that represents a snapshot of a function with its lexical context (variable’s values, objects in the scope). A function closure can be passed as an argument and executed without being a part of any object

Abstract classes

supported

n/a

Function overriding

supported

Supported. You must use the override qualifier

Function overloading

supported

Not supported.

Interfaces

class A implements B{…}

interfaces can contain method declarations and final variables.

class A implements B{…}

interfaces can contain only function declarations.

Exception handling

Keywords: try, catch, throw, finally, throws

Uncaught exceptions are propagated to the calling method.

Keywords: try, catch, throw, finally

A method does not have to declare exceptions.

Can throw not only Error objects, but also numbers:

throw 25.3;

Flash Player terminates the script in case of uncaught exception.

Regular expressions

Supported

Supported




gembin 2012-07-07 22:44 鍙戣璇勮
]]>
MySQL basishttp://www.8634070.com/gembin/archive/2012/05/22/378747.htmlgembingembinMon, 21 May 2012 16:25:00 GMThttp://www.8634070.com/gembin/archive/2012/05/22/378747.htmlhttp://www.8634070.com/gembin/comments/378747.htmlhttp://www.8634070.com/gembin/archive/2012/05/22/378747.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/378747.htmlhttp://www.8634070.com/gembin/services/trackbacks/378747.htmlbasic steps to play with mysql

# 1) login mysql with root
     mysql -u root -p
# 2) update password for root (optional)
UPDATE mysql.user SET password=PASSWORD('newPasswordForRoot'WHERE User='root';
FLUSH PRIVILEGES;

# 3) create a new user 'user1'

CREATE USER user1 IDENTIFIED BY 'mypassword'
# 4) grant all privileges for this user 
GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost' IDENTIFIED BY 'mypassword'
FLUSH PRIVILEGES;

# 5) create a database with char set utf-8

create database mydatabase character set utf8;
set character_set_client=utf8;
set character_set_connection=utf8;
set character_set_database=utf8;
set character_set_results=utf8;
set character_set_server=utf8;


# 6) switch to a database
use mydatabase;
show tables;

# 7) Sample JDBC connection URL

jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false




gembin 2012-05-22 00:25 鍙戣璇勮
]]>
Spring AOP: JDK Dynamic Proxy vs. CGLib proxyhttp://www.8634070.com/gembin/archive/2012/05/03/377268.htmlgembingembinThu, 03 May 2012 05:16:00 GMThttp://www.8634070.com/gembin/archive/2012/05/03/377268.htmlhttp://www.8634070.com/gembin/comments/377268.htmlhttp://www.8634070.com/gembin/archive/2012/05/03/377268.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/377268.htmlhttp://www.8634070.com/gembin/services/trackbacks/377268.htmlSpring's AOP is proxy-based. Spring provides two different options to create the proxies. One is based on JDK dynamic proxies and works with interfaces, the other one utilizes CGLib and is based on classes. (That's why the property is called proxyTargetClass respectively proxy-target-class.) For the moment I just want to provide a quick summary on the pros and cons of both options:

JDK dynamic proxies:

  • The class has to implement interfaces. Otherwise you will get ClassCastExceptions saying that $Proxy0 can not be casted to the particular class.

  • Eventually dynamic proxies force you to program to interfaces since you can not cast the proxy to the class - a feature I really like about them.


CGLib proxies:

  • The proxies are created by sub-classing the actual class. This means wherever an instance of the class is used it is also possible to use the CGLib proxy.

  • The class needs to provide a default constructor, i.e. without any arguments. Otherwise you'll get an IllegalArgumentException: "Superclass has no null constructors but no arguments were given." This makes constructor injection impossible.

  • The proxying does not work with final methods since the proxy sub class can not override the class' implementation.

  • The CGLib proxy is final, so proxying a proxy does not work. You will get an IllegalArgumentException saying "Cannot subclass final class $Proxy0". But this feature is usually not needed anyway. 

  • Since two objects are created (the instance of the class and the proxy as instance of a sub class) the constructor is called twice. In general this should not matter. I consider changing the class' state based on constructor calls a code smell anyway.

  • You have CGLib as additional dependency.

    ref:  

    gembin 2012-05-03 13:16 鍙戣璇勮
    ]]>Deep Copy And Shallow Copyhttp://www.8634070.com/gembin/archive/2012/04/07/373545.htmlgembingembinSat, 07 Apr 2012 10:41:00 GMThttp://www.8634070.com/gembin/archive/2012/04/07/373545.htmlhttp://www.8634070.com/gembin/comments/373545.htmlhttp://www.8634070.com/gembin/archive/2012/04/07/373545.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373545.htmlhttp://www.8634070.com/gembin/services/trackbacks/373545.htmlLets first separate it out and see what each one means.

    What is Shallow Copy?

    Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.

    Shallow Copy

    In this figure, the MainObject1 have fields "field1" of int type, and "ContainObject1" of ContainObject type. When you do a shallow copy of MainObject1, MainObject2 is created with "field3" containing the copied value of "field1" and still pointing to ContainObject1 itself. Observe here and you will find that since field1 is of primitive type, the values of it are copied to field3 but ContainedObject1 is an object, so MainObject2 is still pointing to ContainObject1. So any changes made to ContainObject1 in MainObject1 will reflect in MainObject2.

    Now if this is shallow copy, lets see what's deep copy?

    What is Deep Copy?

    A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.

    Deep Copy

    In this figure, the MainObject1 have fields "field1" of int type, and "ContainObject1" of ContainObject type. When you do a deep copy of MainObject1, MainObject2 is created with "field3" containing the copied value of "field1" and "ContainObject2" containing the copied value of ContainObject1.So any changes made to ContainObject1 in MainObject1 will not reflect in MainObject2.

    Well, here we are with what shallow copy and deep copy are and obviously the difference between them. Now lets see how to implement them in java.

    How to implement shallow copy in java?

    Here is an example of Shallow Copy implementation

     1 class Subject {
     2 
     3   private String name;
     4 
     5   public String getName() {
     6     return name;
     7   }
     8 
     9   public void setName(String s) {
    10     name = s;
    11   }
    12 
    13   public Subject(String s) {
    14     name = s;
    15   }
    16 }
    17 
    18 class Student implements Cloneable {
    19   //Contained object
    20   private Subject subj;
    21 
    22   private String name;
    23 
    24   public Subject getSubj() {
    25     return subj;
    26   }
    27 
    28   public String getName() {
    29     return name;
    30   }
    31 
    32   public void setName(String s) {
    33     name = s;
    34   }
    35 
    36   public Person(String s, String sub) {
    37     name = s;
    38     subj = new Subject(sub);
    39   }
    40 
    41   public Object clone() {
    42     //shallow copy
    43     try {
    44       return super.clone();
    45     } catch (CloneNotSupportedException e) {
    46       return null;
    47     }
    48   }
    49 }
    50 
    51 public class CopyTest {
    52 
    53   public static void main(String[] args) {
    54     //Original Object
    55     Student stud = new Student("John", "Algebra");
    56 
    57     System.out.println("Original Object: " + stud.getName() + " - "
    58         + stud.getSubject().getName());
    59 
    60     //Clone Object
    61     Student clonedStud = (Student) stud.clone();
    62 
    63     System.out.println("Cloned Object: " + clonedStud.getName() + " - "
    64         + clonedStud.getSubject().getName());
    65 
    66     stud.setStudentName("Dan");
    67     stud.getSubject().setSubjectName("Physics");
    68 
    69     System.out.println("Original Object after it is updated: " 
    70         + stud.getName() + " - " + stud.getStudent().getName());
    71 
    72     System.out.println("Cloned Object after updating original object: "
    73         + clonedStud.getName() + " - " + clonedStud.getSubject().getName());
    74 
    75   }
    76 }

    Output is:
    Original Object: John - Algebra
    Cloned Object: John - Algebra
    Original Object after it is updated: Dan - Physics
    Cloned Object after updating original object: John - Physics

    In this example, all I did is, implement the class that you want to copy with Clonable interface and override clone() method of Object class and call super.clone() in it. If you observe, the changes made to "name" field of original object (Student class) is not reflected in cloned object but the changes made to "name" field of contained object (Subject class) is reflected in cloned object. This is because the cloned object carries the memory address of the Subject object but not the actual values. Hence any updates on the Subject object in Original object will reflect in Cloned object.

     

    How to implement deep copy in java?

    Here is an example of Deep Copy implementation. This is the same example of Shallow Copy implementation and hence I didnt write the Subject and CopyTest classes as there is no change in them.

     1 class Student implements Cloneable {
     2   //Contained object
     3   private Subject subj;
     4 
     5   private String name;
     6 
     7   public Subject getSubj() {
     8     return subj;
     9   }
    10 
    11   public String getName() {
    12     return name;
    13   }
    14 
    15   public void setName(String s) {
    16     name = s;
    17   }
    18 
    19   public Person(String s, String sub) {
    20     name = s;
    21     subj = new Subject(sub);
    22   }
    23 
    24   public Object clone() {
    25     //deep copy
    26     try {
    27       //Deep copy
    28       Student s = new Student(name, subj.getName());
    29       return s;
    30     } catch (CloneNotSupportedException e) {
    31       return null;
    32     }
    33   }
    34 }
     
     Output is:
     Original Object: John - Algebra
     Cloned Object: John - Algebra
     Original Object after it is updated: Dan - Physics
     Cloned Object after updating original object: Dan - Physics

     

    Well, if you observe here in the "Student" class, you will see only the change in the "clone()" method. Since its a deep copy, you need to create an object of the cloned class. Well if you have have references in the Subject class, then you need to implement Cloneable interface in Subject class and override clone method in it and this goes on and on.

    There is an alternative way for deep copy.

    Yes, there is. You can do deep copy through serialization. What does serialization do? It writes out the whole object graph into a persistant store and read it back when needed, which means you will get a copy of the whole object graph whne you read it back. This is exactly what you want when you deep copy an object. Note, when you deep copy through serialization, you should make sure that all classes in the object's graph are serializable. Let me explain you this alternative way with an example.

     1 public class ColoredCircle implements Serializable
     2 {
     3     private int x;
     4     private int y;
     5 
     6     public ColoredCircle(int x, int y){
     7         this.x = x;
     8         this.y = y;
     9     }
    10 
    11     public int getX(){
    12         return x;
    13     }
    14 
    15     public void setX(int x){
    16         this.x = x;
    17     }
    18 
    19     public int getY(){
    20         return y;
    21     }
    22 
    23     public void setX(int x){
    24         this.x = x;
    25     }
    26 }
    27 
    28 public class DeepCopy
    29 {
    30     static public void main(String[] args)
    31     {
    32         ObjectOutputStream oos = null;
    33         ObjectInputStream ois = null;
    34 
    35         try
    36         {
    37             // create original serializable object
    38             ColoredCircle c1 = new ColoredCircle(100,100);
    39             // print it
    40             System.out.println("Original = " + c1);
    41 
    42             ColoredCircle c2 = null;
    43 
    44             // deep copy
    45             ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
    46             oos = new ObjectOutputStream(bos); 
    47             // serialize and pass the object
    48             oos.writeObject(c1);   
    49             oos.flush();               
    50             ByteArrayInputStream bin = 
    51                     new ByteArrayInputStream(bos.toByteArray()); 
    52             ois = new ObjectInputStream(bin);                  
    53             // return the new object
    54             c2 = ois.readObject(); 
    55 
    56             // verify it is the same
    57             System.out.println("Copied   = " + c2);
    58             // change the original object's contents
    59             c1.setX(200);
    60             c1.setY(200);
    61             // see what is in each one now
    62             System.out.println("Original = " + c1);
    63             System.out.println("Copied   = " + c2);
    64         }
    65         catch(Exception e)
    66         {
    67             System.out.println("Exception in main = " +  e);
    68         }
    69         finally
    70         {        
    71             oos.close();
    72             ois.close();
    73         }
    74     }
    75 }

     The output is:
     Original = x=100,y=100
     Copied   = x=100,y=100
     Original = x=200,y=200
     Copied   = x=100,y=100

    All you need to do here is:
    • Ensure that all classes in the object's graph are serializable.
    • Create input and output streams.
    • Use the input and output streams to create object input and object output streams.
    • Pass the object that you want to copy to the object output stream.
    • Read the new object from the object input stream and cast it back to the class of the object you sent.

    In this example, I have created a ColoredCircle object, c1 and then serialized it (write it out to ByteArrayOutputStream). Then I deserialed the serialized object and saved it in c2. Later I modified the original object, c1. Then if you see the result, c1 is different from c2. c2 is deep copy of first version of c1. So its just a copy and not a reference. Now any modifications to c1 wont affect c2, the deep copy of first version of c1.

    Well this approach has got its own limitations and issues:

    As you cannot serialize a transient variable, using this approach you cannot copy the transient variables. 
    Another issue is dealing with the case of a class whose object's instances within a virtual machine must be controlled. This is a special case of the Singleton pattern, in which a class has only one object within a VM. As discussed above, when you serialize an object, you create a totally new object that will not be unique. To get around this default behavior you can use the readResolve() method to force the stream to return an appropriate object rather than the one that was serialized. In this particular case, the appropriate object is the same one that was serialized.
    Next one is the performance issue. Creating a socket, serializing an object, passing it through the socket, and then deserializing it is slow compared to calling methods in existing objects. I say, there will be vast difference in the performance. If your code is performance critical, I suggest dont go for this approach. It takes almost 100 times more time to deep copy the object than the way you do by implementing Clonable interface.

    When to do shallow copy and deep copy?

    Its very simple that if the object has only primitive fields, then obviously you will go for shallow copy but if the object has references to other objects, then based on the requiement, shallow copy or deep copy should be chosen. What I mean here is, if the references are not modified anytime, then there is no point in going for deep copy. You can just opt shallow copy. But if the references are modified often, then you need to go for deep copy. Again there is no hard and fast rule, it all depends on the requirement.

    Finally lets have a word about rarely used option - Lazy copy

    A lazy copy is a combination of both shallow copy and deep copy. When initially copying an object, a (fast) shallow copy is used. A counter is also used to track how many objects share the data. When the program wants to modify the original object, it can determine if the data is shared (by examining the counter) and can do a deep copy at that time if necessary.

    Lazy copy looks to the outside just as a deep copy but takes advantage of the speed of a shallow copy whenever possible. It can be used when the references in the original object are not modified often. The downside are rather high but constant base costs because of the counter. Also, in certain situations, circular references can also cause problems.



    gembin 2012-04-07 18:41 鍙戣璇勮
    ]]>
    SAX vs. DOMhttp://www.8634070.com/gembin/archive/2012/04/01/373206.htmlgembingembinSun, 01 Apr 2012 08:32:00 GMThttp://www.8634070.com/gembin/archive/2012/04/01/373206.htmlhttp://www.8634070.com/gembin/comments/373206.htmlhttp://www.8634070.com/gembin/archive/2012/04/01/373206.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373206.htmlhttp://www.8634070.com/gembin/services/trackbacks/373206.htmlWhile comparing two entities, we tend to see both of them as competitors and consequently comparing them to find a winner. This of course is not applicable in every case - not at least in the case of SAX and DOM. Both have their own pros and cons and they are certainly not in direct competition with each other.

    SAX vs. DOM

    Main differences between SAX and DOM, which are the two most popular APIs for processing XML documents in Java, are:-
    • Read v/s Read/Write: SAX can be used only for reading XML documents and not for the manipulation of the underlying XML data whereas DOM can be used for both read and write of the data in an XML document.
    • Sequential Access v/s Random Access: SAX can be used only for a sequential processing of an XML document whereas DOM can be used for a random processing of XML docs. So what to do if you want a random access to the underlying XML data while using SAX? You got to store and manage that information so that you can retrieve it when you need.
    • Call back v/s Tree: SAX uses call back mechanism and uses event-streams to read chunks of XML data into the memory in a sequential manner whereas DOM uses a tree representation of the underlying XML document and facilitates random access/manipulation of the underlying XML data.
    • XML-Dev mailing list v/s W3C: SAX was developed by the XML-Dev mailing list whereas DOM was developed by W3C (World Wide Web Consortium).
    • Information Set: SAX doesn't retain all the info of the underlying XML document such as comments whereas DOM retains almost all the info. New versions of SAX are trying to extend their coverage of information.
    Usual Misconceptions
    • SAX is always faster: this is a very common misunderstanding and one should be aware that SAX may not always be faster because it might not enjoy the storage-size advantage in every case due to the cost of call backs depending upon the particular situation, SAX is being used in.
    • DOM always keeps the whole XML doc in memory: it's not always true. DOM implementations not only vary in their code size and performance, but also in their memory requirements and few of them don't keep the entire XML doc in memory all the time. Otherwise, processing/manipulation of very large XML docs may virtually become impossible using DOM, which is of course not the case.

    How to choose one between the two?

    It primarily depends upon the requirement. If the underlying XML data requires manipulation then almost always DOM will be used as SAX doesn't allow that. Similarly if the nature of access is random (for example, if you need contextual info at every stage) then DOM will be the way to go in most of the cases. But, if the XML document is only required to be read and that too sequentially, then SAX will probably be a better alternative in most of the cases. SAX was developed mainly for pasring XML documents and it's certainly good at it. SO, if you need to process an XML document maybe to update a datasource, SAX will probably make a alternative.
    Requirements may certainly fall between the two extremes discussed above and for any such situation you should weight both the alternatives before picking any of the two. There are applications where a combination of both SAX and DOM are used for XML processing so that might also be an alternative in your case. But, basically it would be a design decision and evidently it would require a thorough analysis of the pros and cons of all possible approaches in that situation.


    gembin 2012-04-01 16:32 鍙戣璇勮
    ]]>
    Top Ten Reasons not to use the C shellhttp://www.8634070.com/gembin/archive/2012/04/01/373205.htmlgembingembinSun, 01 Apr 2012 08:30:00 GMThttp://www.8634070.com/gembin/archive/2012/04/01/373205.htmlhttp://www.8634070.com/gembin/comments/373205.htmlhttp://www.8634070.com/gembin/archive/2012/04/01/373205.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373205.htmlhttp://www.8634070.com/gembin/services/trackbacks/373205.html http://www.grymoire.com/Unix/CshTop10.txt

    gembin 2012-04-01 16:30 鍙戣璇勮
    ]]>
    Get substring of a string under UNIX/Linuxhttp://www.8634070.com/gembin/archive/2012/04/01/373200.htmlgembingembinSun, 01 Apr 2012 07:38:00 GMThttp://www.8634070.com/gembin/archive/2012/04/01/373200.htmlhttp://www.8634070.com/gembin/comments/373200.htmlhttp://www.8634070.com/gembin/archive/2012/04/01/373200.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373200.htmlhttp://www.8634070.com/gembin/services/trackbacks/373200.htmlthere many ways to do so.


    str="hello world"

    1) cut
    Where -cN-M tells the cut command to return columns N to M, inclusive. 
    cut -cN-M

    start=1
    end=5
    sub_str=`echo ${str} | cut -c${start}-${end}`
    output: hello

    2) bash 
    Note: if you are not sure of having bash, consider using cut. 
    ${str:offset}
    $
    {str:offset:length}

    sub_str=${str:0:5}
    output: hello

    3) expr

    expr substr string position length 
    sub_str=`expr substr $str 1 5`
    output: hello

     



    gembin 2012-04-01 15:38 鍙戣璇勮
    ]]>
    Get the length of a string under UNIX/Linuxhttp://www.8634070.com/gembin/archive/2012/04/01/373199.htmlgembingembinSun, 01 Apr 2012 07:14:00 GMThttp://www.8634070.com/gembin/archive/2012/04/01/373199.htmlhttp://www.8634070.com/gembin/comments/373199.htmlhttp://www.8634070.com/gembin/archive/2012/04/01/373199.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373199.htmlhttp://www.8634070.com/gembin/services/trackbacks/373199.htmlthere many ways to do so.

    str="hello world"

    len=`expr length ${str}`

    len=${#str}

    len=`echo ${str} | awk "{ print length }"`

    len=`echo -n ${str} | wc -c` 

     



    gembin 2012-04-01 15:14 鍙戣璇勮
    ]]>
    TreeSet vs HashSet vs LinkedHashSethttp://www.8634070.com/gembin/archive/2012/03/31/373111.htmlgembingembinSat, 31 Mar 2012 03:30:00 GMThttp://www.8634070.com/gembin/archive/2012/03/31/373111.htmlhttp://www.8634070.com/gembin/comments/373111.htmlhttp://www.8634070.com/gembin/archive/2012/03/31/373111.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/373111.htmlhttp://www.8634070.com/gembin/services/trackbacks/373111.html
    TreeSetHashSetLinkedHashSet
    public class TreeSet
    extends AbstractSet
    implements SortedSetCloneableSerializable
    public class HashSet
    extends AbstractSet
    implements SetCloneableSerializable
    public class LinkedHashSet
    extends HashSet
    implements SetCloneableSerializable
    unique valuesunique valuesUnique values
    It stores its elements in a red-black treeIt stores its elements in a hash tableis implemented as a hash table with a linked list running through it
    Order : ascending orderundefinedinsertion order
    Performance : Slowbetter than LinkedHashSethas fast adding to the start of the list, and fast deletion from the interior via iteration
    operations (addremove and contains)operations (addremovecontains and size)operations (addcontains and remove)
    add, addAll,ceiling,clear,clone,comparator,contains,
    descendingIterator,descendingSet,first,floor,
    hashSet,higher,isEmpty,iterator,last,lower,pollFirst,
    remove,size,subSet,tailSet
    addclearclonecontainsisEmpty,iteratorremovesizeaddclearclonecontainsisEmpty,iteratorremovesize
    From AbstractSet:
    equalshashCoderemoveAll
    equalshashCoderemoveAllequalshashCoderemoveAll
    containsAllretainAlltoArraytoArray,toStringAbstractCollection:
    addAllcontainsAllretainAlltoArray,toArraytoString
    addAllcontainsAllretainAlltoArray,toArraytoString
    Set:
    containsAllequalshashCoderemoveAll,retainAlltoArraytoArray
    addAllcontainsAllequalshashCode,removeAllretainAlltoArraytoArrayaddaddAllclearcontainscontainsAll,equalshashCodeisEmptyiteratorremove,removeAllretainAllsizetoArraytoArray



    gembin 2012-03-31 11:30 鍙戣璇勮
    ]]>
    Objective-C NSString formatting http://www.8634070.com/gembin/archive/2012/03/04/371188.htmlgembingembinSat, 03 Mar 2012 16:27:00 GMThttp://www.8634070.com/gembin/archive/2012/03/04/371188.htmlhttp://www.8634070.com/gembin/comments/371188.htmlhttp://www.8634070.com/gembin/archive/2012/03/04/371188.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/371188.htmlhttp://www.8634070.com/gembin/services/trackbacks/371188.htmlThe format specifiers supported by the NSString formatting methods and CFString formatting
    functions follow the IEEE printf specification; the specifiers are summarized in Table 1.
    Note that you can also use the “n$” positional specifiers such as %1$@ %2$s.
    For more details, see the IEEE printf specification. You can also use these format specifiers with the NSLog function.

    Table 1 Format specifiers supported by the NSString formatting methods and CFString formatting functions
    瀹?#28052;?/td>璇?#37828;?/td>
    %@Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.
    %%‘%’ character
    %d, %D, %iSigned 32-bit integer (int)
    %u, %UUnsigned 32-bit integer (unsigned int)
    %hiSigned 16-bit integer (short)
    %huUnsigned 16-bit integer (unsigned short)
    %qiSigned 64-bit integer (long long)
    %quUnsigned 64-bit integer (unsigned long long)
    %xUnsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f
    %XUnsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F
    %qxUnsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and lowercase a–f
    %qXUnsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and uppercase A–F
    %o, %OUnsigned 32-bit integer (unsigned int), printed in octal
    %f64-bit floating-point number (double)
    %e64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent
    %E64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent
    %g64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise
    %G64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise
    %c8-bit unsigned character (unsigned char), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
    %C16-bit Unicode character (unichar), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
    %sNull-terminated array of 8-bit unsigned characters. %s interprets its input in the system encoding rather than, for example, UTF-8.
    %SNull-terminated array of 16-bit Unicode characters
    %pVoid pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x
    %LLength modifier specifying that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument
    %a64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent
    %A64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent
    %F64-bit floating-point number (double), printed in decimal notation
    %zLength modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument
    %tLength modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument
    %jLength modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument


    Mac OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a
    consistent means of representing values in 32- and 64-bit environments. In a 32-bit environment,
    NSInteger and NSUInteger are defined as int and unsigned int, respectively. In 64-bit environments,
    NSInteger and NSUInteger are defined as long and unsigned long, respectively. To avoid the need to
    use different printf-style type specifiers depending on the platform, you can use the specifiers shown
    in Table 2. Note that in some cases you may have to cast the value.

    Table 2 Format specifiers for data types
    绫诲瀷瀹?#28052;?/td>?#32531;璁?/td>
    NSInteger%ld or %lxCast the value to long
    NSUInteger%lu or %lxCast the value to unsigned long
    CGFloat%f or %g%f works for floats and doubles when formatting; but see below warning when scanning
    CFIndex%ld or %lxThe same as NSInteger
    pointer%p%p adds 0x to the beginning of the output. If you don’t want that, use %lx and cast to long.
    long long%lld or %llxlong long is 64-bit on both 32- and 64-bit platforms
    unsigned long long%llu or %llxunsigned long long is 64-bit on both 32- and 64-bit platforms

    The following example illustrates the use of %ld to format an NSInteger and the use of a cast.

    1
    2
    NSInteger i = 42;
    printf("%ld\n", (long)i);

    In addition to the considerations mentioned in Table 2, there is one extra case with scanning:
    you must distinguish the types for float and double. You should use %f for float, %lf for double.
    If you need to use scanf (or a variant thereof) with CGFloat, switch to double instead, and copy the double to CGFloat.

    1
    2
    3
    4
    CGFloat imageWidth;
    double tmp;
    sscanf (str, "%lf", &amp;tmp);
    imageWidth = tmp;

    It is important to remember that %lf does not represent CGFloat correctly on either 32- or 64-bit platforms.
    This is unlike %ld, which works for long in all cases.







    gembin 2012-03-04 00:27 鍙戣璇勮
    ]]>
    Sharing Objective-C, Cocoa and iOS [ebooks]http://www.8634070.com/gembin/archive/2012/03/03/371166.htmlgembingembinSat, 03 Mar 2012 07:43:00 GMThttp://www.8634070.com/gembin/archive/2012/03/03/371166.htmlhttp://www.8634070.com/gembin/comments/371166.htmlhttp://www.8634070.com/gembin/archive/2012/03/03/371166.html#Feedback2http://www.8634070.com/gembin/comments/commentRss/371166.htmlhttp://www.8634070.com/gembin/services/trackbacks/371166.htmli got several objective-c & iOS related books collected from the internet for sharing.


    Hope u will like it.






































































    Pro_Objective-C_Design_Patterns_for_iOS.pdf


    =====================================
    =  others
    =====================================

    Learn_Objective-C_for_Java_Developers.pdf








    gembin 2012-03-03 15:43 鍙戣璇勮
    ]]>
    Giulia - Ce Frumoasa E Iubirea (鐖辨儏澶氱編涓?http://www.8634070.com/gembin/archive/2012/01/21/368811.htmlgembingembinSat, 21 Jan 2012 03:21:00 GMThttp://www.8634070.com/gembin/archive/2012/01/21/368811.htmlhttp://www.8634070.com/gembin/comments/368811.htmlhttp://www.8634070.com/gembin/archive/2012/01/21/368811.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/368811.htmlhttp://www.8634070.com/gembin/services/trackbacks/368811.html
    Ce frumoasa e iubirea 鐖辨儏澶氱編涓?
    Fiecare clipa pictata-n roz, ?#30241;涓鍒嗘瘡涓绉?#38318;芥?#20635;垚浜嗙帿鐟拌壊
    Tre'sa recunosc,iti apartine... 鎴戝?#21620;寰?#37813;?#29825;?#38171;岃繖灞?#27996;?#28003;?
    Si nici macar eu nu ma cunosc 鎴?#23480;?#37827;?#23049;?#29825;?#29831;嗚嚜宸?
    Asa cum ma stii pe mine.. 鍙?#37832;?#28003;?#27996;嗚鐪?#23005;殑鎴?
    Ma tem uneori ca ai sa pleci 鏈夋椂鍊?#37812;戞?#21613;績浣?#28751;嗙?#35826;幓锛?
    Si nu vreau sa ma lasi fara tine...?#31497;瑕佺涓嬪鍗曠殑鎴?
    Iar eu nu sunt eu...鑰?#37812;?#23480;蹭笉鏄?#37812;?#38171;?
    De fapt,fara tine,sunt nimeni...浜?#28729;?#28051;?#38171;屾病鏈?#28003;?#38171;?#37812;戜篃灏?#37827;?#23049;曞?#27194;湪
    Refren: Ce frumoasa e iubirea 锛岀?#36776;儏澶氱?#24225;憖锛?
    Cand ma alinti cu zambetul tau curat! ?#32139;浣?#37922;?#32510;?#23090;佺殑寰?#32471;戠埍鎶?#37812;戞椂
    Ce frumoasa e iubirea 鐖辨儏澶氱?#24225;憖
    Cand tot ce spui devine adevarat!?#32139;浣?#29831;寸殑璇?#37812;愮?#29114;殑閭?#28051;鍒?
    (bis)

    Ficare clipa trecuta-n alb 鐧?#37827;?#38322;屽害杩囩殑?#30241;涓鍒?
    A insemna ca tu esti departe 鍛?#29831;?#28003;?#23480;?#29863;?#26473;?
    Uneori ma intreb daca esti real 鏈夋椂鍊?#37812;?#38338;?#38007;?#23480;?#28003;?#37828;?#37722;?#37930;熺殑瀛樺湪
    Sau inchipuit din printr-o carte! 涔?#29825;?#28003;?#37721;?#37828;?#28052;?#28051;?#37928;勮?#27692;够
    Ma tem uneori ca ai sa pleci 鏈夋椂鎷呭績浣犱細绂诲幓
    Si nu vreau sa ma lasi fara tine... ?#31497;瑕佺涓嬪鍗曠殑鎴?
    Iar eu nu sunt eu... 鑰?#37812;?#23480;蹭笉鏄?#37812;?
    De fapt,fara tine,sunt nimeni... 娌?#37832;?#28003;?#38171;?#37812;戜篃灏嗕笉鍐嶅?#27194;湪
    Refren: Ce frumoasa e iubirea 鐖辨儏澶氱?#24225;憖
    Cand ma alinti cu zambetul tau curat! ?#32139;浣?#37922;?#32510;?#23090;佺殑寰?#32471;戠埍鎶?#37812;戞椂
    Ce frumoasa e iubirea 鐖辨儏澶氱?#24225;憖
    Cand tot ce spui devine adevarat! ?#32139;浣犵殑璇?#29831;?#37812;愮?#29112;椂
    (bis)
    Ma cuprinzi incet..ma stangi la piept 鎱?#37809;?#28751;?#37812;戞鍏?#37804;涓?
    Imi spui ca nu..n-ai sa pleci prea curand... 瀵规?#25123;?#32736;笉銆?#37510;?#37510;備笉瑕侀涓婄珛寮鎴?
    (bis)
    Refren: Ce frumoasa e iubirea 鐖辨儏澶氱?#24225;憖
    Cand ma alinti cu zambetul tau curat! ?#32139;浣?#37922;?#32510;?#23090;佺殑寰?#32471;戠埍鎶?#37812;戞椂
    Ce frumoasa e iubirea 鐖辨儏澶氱?#24225;憖
    Cand tot ce spui devine adevarat! ?#32139;浣犵殑璇?#29831;?#37812;愮?#29112;椂
    (bis)


    gembin 2012-01-21 11:21 鍙戣璇勮
    ]]>
    Mac Keyboard Shortcutshttp://www.8634070.com/gembin/archive/2012/01/21/368798.htmlgembingembinFri, 20 Jan 2012 16:57:00 GMThttp://www.8634070.com/gembin/archive/2012/01/21/368798.htmlhttp://www.8634070.com/gembin/comments/368798.htmlhttp://www.8634070.com/gembin/archive/2012/01/21/368798.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/368798.htmlhttp://www.8634070.com/gembin/services/trackbacks/368798.html闃?#29831;诲叏?#26499;

    gembin 2012-01-21 00:57 鍙戣璇勮
    ]]>
    蹇?#37918;嗗鑻辨枃璇嶆http://www.8634070.com/gembin/archive/2012/01/14/368493.htmlgembingembinSat, 14 Jan 2012 07:19:00 GMThttp://www.8634070.com/gembin/archive/2012/01/14/368493.htmlhttp://www.8634070.com/gembin/comments/368493.htmlhttp://www.8634070.com/gembin/archive/2012/01/14/368493.html#Feedback0http://www.8634070.com/gembin/comments/commentRss/368493.htmlhttp://www.8634070.com/gembin/services/trackbacks/368493.html闃?#29831;诲叏?#26499;

    gembin 2012-01-14 15:19 鍙戣璇勮
    ]]>
    ˫ɫֱ
    <div id="k0jz6"><tr id="k0jz6"></tr></div>
      <sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup>
      <div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div><em id="k0jz6"></em>
      <dl id="k0jz6"><ins id="k0jz6"></ins></dl><dl id="k0jz6"></dl>
        <div id="k0jz6"></div>

        <sup id="k0jz6"></sup><dl id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></dl>
          <div id="k0jz6"><tr id="k0jz6"></tr></div>
            <sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup>
            <div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div><em id="k0jz6"></em>
            <dl id="k0jz6"><ins id="k0jz6"></ins></dl><dl id="k0jz6"></dl>
              <div id="k0jz6"></div>

              <sup id="k0jz6"></sup><dl id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></dl>