??xml version="1.0" encoding="utf-8" standalone="yes"?>四川福利彩票快乐12:BlogJava - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/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 >About Me</a> <script type="text/javascript" src="//platform.linkedin.com/in.js"></script><script type="in/share" data-counter="right"></script> zh-cnTue, 16 Oct 2018 03:47:54 GMTTue, 16 Oct 2018 03:47:54 GMT60Overriding Vs Hiding - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2014/05/29/414246.htmlgembingembinThu, 29 May 2014 07:52:00 GMT//www.ot7t.com.cn/gembin/archive/2014/05/29/414246.html//www.ot7t.com.cn/gembin/comments/414246.html//www.ot7t.com.cn/gembin/archive/2014/05/29/414246.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/414246.html//www.ot7t.com.cn/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: //www.coderanch.com/how-to/java/OverridingVsHiding



gembin 2014-05-29 15:52 发表评论
]]>
Fuck GFW - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2014/05/18/413795.htmlgembingembinSat, 17 May 2014 16:21:00 GMT//www.ot7t.com.cn/gembin/archive/2014/05/18/413795.html//www.ot7t.com.cn/gembin/comments/413795.html//www.ot7t.com.cn/gembin/archive/2014/05/18/413795.html#Feedback1//www.ot7t.com.cn/gembin/comments/commentRss/413795.html//www.ot7t.com.cn/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,the son of a bitch!!!!
 

gembin 2014-05-18 00:21 发表评论
]]>
A web-based monitoring tool for WebSphere MQ - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/12/04/407231.htmlgembingembinWed, 04 Dec 2013 15:22:00 GMT//www.ot7t.com.cn/gembin/archive/2013/12/04/407231.html//www.ot7t.com.cn/gembin/comments/407231.html//www.ot7t.com.cn/gembin/archive/2013/12/04/407231.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/407231.html//www.ot7t.com.cn/gembin/services/trackbacks/407231.html
My developerWorks article on WebSphere MQ


gembin 2013-12-04 23:22 发表评论
]]>
How JavaScript Timers Work - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/05/27/399816.htmlgembingembinMon, 27 May 2013 05:50:00 GMT//www.ot7t.com.cn/gembin/archive/2013/05/27/399816.html//www.ot7t.com.cn/gembin/comments/399816.html//www.ot7t.com.cn/gembin/archive/2013/05/27/399816.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/399816.html//www.ot7t.com.cn/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: //ejohn.org/blog/how-javascript-timers-work/




gembin 2013-05-27 13:50 发表评论
]]>
Tip of changing the language settings for Websphere MQ Explorer - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/03/23/396905.htmlgembingembinSat, 23 Mar 2013 09:26:00 GMT//www.ot7t.com.cn/gembin/archive/2013/03/23/396905.html//www.ot7t.com.cn/gembin/comments/396905.html//www.ot7t.com.cn/gembin/archive/2013/03/23/396905.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/396905.html//www.ot7t.com.cn/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盘、移动硬盘在苹果电脑和Windows PC都能识别/读写,且支持4GB大文件:exFAT格式 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/03/12/396297.htmlgembingembinMon, 11 Mar 2013 17:27:00 GMT//www.ot7t.com.cn/gembin/archive/2013/03/12/396297.html//www.ot7t.com.cn/gembin/comments/396297.html//www.ot7t.com.cn/gembin/archive/2013/03/12/396297.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/396297.html//www.ot7t.com.cn/gembin/services/trackbacks/396297.html 如果您的 U 盘、移动硬盘既要用?PC 又要用于苹果电脑,Mac OS X 系统?HFS??Windows ?NTFS 格式显然都不?#8230;…HFS+ ?Windows 下不识别,NTFS 格式?U 盘、移动硬盘插在苹果电脑上只能读不能写。格式化?FAT32 显然可以支持两个系统,但单一文件大于 4GB 就歇菜?/span>

exFAT 格式

    但苹果电?Mac OS X 10.6.5 系统做出了一项意义重大的升级:支?exFAT 磁盘格式,格式化?exFAT 格式?U 盘、移动硬盘在 Windows PC 上和苹果电脑 Mac OS X 系统下均能读写,而且支持超过单个体积超过 4 GB 的大文件?/p>

    下面是将 U 盘、移动硬盘格式化?exFAT 格式的方法,以及 exFAT、FAT32、HFS?三种格式下同一?U 盘的读写速度测试

苹果电脑 Mac OS X 系统下把U盘、移动硬盘格式化成exFAT格式
苹果电脑 Mac OS X 系统下把U盘、移动硬盘格式化成exFAT格式

    点击苹果电脑屏幕右上角的放大镜按钮,Sportlight 搜索“磁盘工具”,在磁盘工具侧边栏选择要格式化?U 盘或移动硬盘分区,右侧选择“抹掉”标签,在格式下拉菜单里选择 ExFAT 即可。如上图所示?/p>

Windows 系统下把U盘、移动硬盘格式化成exFAT格式
Windows 系统下把U盘、移动硬盘格式化成exFAT格式

    Windows 7 ?Vista 默认就支?exFAT 格式,如果是 XP 系统,要下载 KB955704 补丁?u style="margin: 0px auto; padding: 0px;">//www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=1cbe3906-ddd1-4ca2-b727-c2dff5e30f61

    至于 exFAT 格式?U 盘的读写速度,下面是同一?U 盘在同一台电脑(我的 Macbook Pro)上的读写速度测试,测试软件为 以前介绍的免费软件:AJA System Test?br style="margin: 0px auto; padding: 0px;" />

FAT32、HFS+、exFAT 格式?U 盘读写速度测试
FAT32、HFS+、exFAT 格式?U 盘读写速度测试

    顺时针依次是 FAT32、HFS+、exFAT 格式?U 盘读写速度测试结果,不太妙。所以:只把 U 盘和移动硬盘的一个分区(专门用于 PC、Mac 之间交换文件)格式化?exFAT 就行了?br />KEEP FOR REF: //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 Concepts - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/03/07/396169.htmlgembingembinThu, 07 Mar 2013 08:58:00 GMT//www.ot7t.com.cn/gembin/archive/2013/03/07/396169.html//www.ot7t.com.cn/gembin/comments/396169.html//www.ot7t.com.cn/gembin/archive/2013/03/07/396169.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/396169.html//www.ot7t.com.cn/gembin/services/trackbacks/396169.html
keep it for reference
//tomee.apache.org/jpa-concepts.html
//www.jpalace.org/docs/tutorials/jee/jpa_2.html


gembin 2013-03-07 16:58 发表评论
]]>
JPA Criteria API - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/03/06/396131.htmlgembingembinWed, 06 Mar 2013 05:44:00 GMT//www.ot7t.com.cn/gembin/archive/2013/03/06/396131.html//www.ot7t.com.cn/gembin/comments/396131.html//www.ot7t.com.cn/gembin/archive/2013/03/06/396131.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/396131.html//www.ot7t.com.cn/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.1 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/02/14/395312.htmlgembingembinThu, 14 Feb 2013 08:28:00 GMT//www.ot7t.com.cn/gembin/archive/2013/02/14/395312.html//www.ot7t.com.cn/gembin/comments/395312.html//www.ot7t.com.cn/gembin/archive/2013/02/14/395312.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/395312.html//www.ot7t.com.cn/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 at//www.computerhistory.org/collections/accession/102640940

and the 1990 Adobe Photoshop tutorial is at//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:  
//computerhistory.org/atchm/adobe-photoshop-source-code/



gembin 2013-02-14 16:28 发表评论
]]>
Thread-safety when injecting JPA EntityManager - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2013/02/04/395088.htmlgembingembinMon, 04 Feb 2013 02:49:00 GMT//www.ot7t.com.cn/gembin/archive/2013/02/04/395088.html//www.ot7t.com.cn/gembin/comments/395088.html//www.ot7t.com.cn/gembin/archive/2013/02/04/395088.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/395088.html//www.ot7t.com.cn/gembin/services/trackbacks/395088.html阅读全文

gembin 2013-02-04 10:49 发表评论
]]>
Java Exception Practices - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/12/26/393525.htmlgembingembinWed, 26 Dec 2012 15:56:00 GMT//www.ot7t.com.cn/gembin/archive/2012/12/26/393525.html//www.ot7t.com.cn/gembin/comments/393525.html//www.ot7t.com.cn/gembin/archive/2012/12/26/393525.html#Feedback1//www.ot7t.com.cn/gembin/comments/commentRss/393525.html//www.ot7t.com.cn/gembin/services/trackbacks/393525.htmlJust keep it for reference.

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

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

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

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

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

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

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


gembin 2012-12-26 23:56 发表评论
]]>
The Trouble with Checked Exceptions - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/12/26/393523.htmlgembingembinWed, 26 Dec 2012 15:35:00 GMT//www.ot7t.com.cn/gembin/archive/2012/12/26/393523.html//www.ot7t.com.cn/gembin/comments/393523.html//www.ot7t.com.cn/gembin/archive/2012/12/26/393523.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/393523.html//www.ot7t.com.cn/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.

    四川福利彩票快乐12: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:  //www.artima.com/intv/handcuffs.html



gembin 2012-12-26 23:35 发表评论
]]>
CentOS 6 安装后基本配?/title><link>//www.ot7t.com.cn/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>//www.ot7t.com.cn/gembin/archive/2012/12/23/393380.html</guid><wfw:comment>//www.ot7t.com.cn/gembin/comments/393380.html</wfw:comment><comments>//www.ot7t.com.cn/gembin/archive/2012/12/23/393380.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/gembin/comments/commentRss/393380.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/gembin/services/trackbacks/393380.html</trackback:ping><description><![CDATA[<p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong class="yibqv">1</strong><strong class="yibqv">.网络配?/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地址、子网掩?br /># route add default gw 192.168.0.1 dev eth0  //网关<br /># hostname centos   //计算机名</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">?)文件配?br /><1>修改IP地址<br />修改对应网卡的IP地址的配置文?br /># vi /etc/sysconfig/network-scripts/ifcfg-eth0<br />DEVICE=eth0 (描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0)<br />BOOTPROTO=static (设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址)<br />BROADCAST=192.168.0.255 (对应的子网广播地址)<br />HWADDR=00:07:E9:05:E8:B4  (对应的网卡物理地址)<br />IPADDR=12.168.1.2 (如果设置网卡获得ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址)<br />IPV6INIT=no  (开启或关闭IPv6;关闭no,开启yes)<br />IPV6_AUTOCONF=no  (开启或关闭IPv6自动配置;关闭no,开启yes)<br />NETMASK=255.255.255.0 (网卡对应的网络掩?<br />NETWORK=192.168.1.0 (网卡对应的网络地址)<br />ONBOOT=yes (系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备)<br /><br /><2>修改网关<br />修改对应网卡的网关的配置文件<br /># vi /etc/sysconfig/network<br />NETWORKING=yes (表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络,而且很多系统服务程序将无法启?<br />HOSTNAME=centos (设置本机的主机名,这里设置的主机名要?etc/hosts中设置的主机名对?<br />GATEWAY=192.168.1.1 (设置本机连接的网关的IP地址。例如,网关?0.0.0.2)<br /><br /><3>修改DNS<br />修改对应网卡的DNS的配置文?br /># vi /etc/resolv.conf<br />nameserver 202.101.224.68 (域名服务?<br />nameserver 202.101.224.69 (域名服务?<br /><br /><4>重新启动网络配置<br /># service network restart<br />?br /># /etc/init.d/network restart<br /><br /><strong class="yibqv">2</strong><strong class="yibqv">.软件源配置</strong></p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">国内速度较快的常用更新源如下?br />//mirrors.163.com/centos/ 163-网易<br />//mirrors.ta139.com/centos/ 中国移动通信(山东移动)<br />//centos.ustc.edu.cn/centos/ 中国科学技术大?br />//mirror.neu.edu.cn/centos/ 东北大学</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; "><strong class="yibqv">编辑yum</strong><strong class="yibqv">配置文件?nbsp;</strong><br />#vi /etc/yum.repos.d/CentOS-Base.repo<br />[base]<br />name=CentOS-$releasever - Base<br />mirrorlist=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os<br />#baseurl=//mirror.centos.org/centos/$releasever/os/$basearch/<br />baseurl=//mirrors.163.com/centos/$releasever/os/$basearch/<br />//mirrors.ta139.com/centos/$releasever/os/$basearch/<br />//centos.ustc.edu.cn/centos/$releasever/os/$basearch/<br />//mirror.neu.edu.cn/centos/$releasever/os/$basearch/<br />gpgcheck=1<br />gpgkey=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates<br />#baseurl=//mirror.centos.org/centos/$releasever/updates/$basearch/<br />baseurl=//mirrors.163.com/centos/$releasever/updates/$basearch/<br />//mirrors.ta139.com/centos/$releasever/updates/$basearch/<br />//centos.ustc.edu.cn/centos/$releasever/updates/$basearch/<br />//mirror.neu.edu.cn/centos/$releasever/updates/$basearch/<br />gpgcheck=1<br />gpgkey=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras<br />#baseurl=//mirror.centos.org/centos/$releasever/extras/$basearch/<br />baseurl=//mirrors.163.com/centos/$releasever/extras/$basearch/<br />//mirrors.ta139.com/centos/$releasever/extras/$basearch/<br />//centos.ustc.edu.cn/centos/$releasever/extras/$basearch/<br />//mirror.neu.edu.cn/centos/$releasever/extras/$basearch/<br />gpgcheck=1<br />gpgkey=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus<br />#baseurl=//mirror.centos.org/centos/$releasever/centosplus/$basearch/<br />baseurl=//mirrors.163.com/centos/$releasever/centosplus/$basearch/<br />//mirrors.ta139.com/centos/$releasever/centosplus/$basearch/<br />//centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/<br />//mirror.neu.edu.cn/centos/$releasever/centosplus/$basearch/<br />gpgcheck=1<br />enabled=0<br />gpgkey=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib<br />#baseurl=//mirror.centos.org/centos/$releasever/contrib/$basearch/<br />baseurl=//mirrors.163.com/centos/$releasever/contrib/$basearch/<br />//mirrors.ta139.com/centos/$releasever/contrib/$basearch/<br />//centos.ustc.edu.cn/centos/$releasever/contrib/$basearch/<br />//mirror.neu.edu.cn/centos/$releasever/contrib/$basearch/<br />gpgcheck=1<br />enabled=0<br />gpgkey=//mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">然后使用如下命令更新到最新系统:</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 class="yibqv">3</strong><strong class="yibqv">.安装语言?/strong></p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">从安装盘进行安装,找到对应rpm包:<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; ">可以通过yum进行安装,安装办法为?br />#yum groupinstall <language>-support</p><p style="font-family: verdana; font-size: 13px; line-height: normal; background-color: #ffffff; ">?上面的命令中?lt;language> 是下列之一: 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 class="yibqv">4</strong><strong class="yibqv">.解压缩软件 </strong><br />#yum install unrar unzip p7zip-full</p><img src ="//www.ot7t.com.cn/gembin/aggbug/393380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.ot7t.com.cn/gembin/" target="_blank">gembin</a> 2012-12-23 22:57 <a href="//www.ot7t.com.cn/gembin/archive/2012/12/23/393380.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VirtualBox 安装Centos 之访问虚拟机里面的服务受阻解决方?/title><link>//www.ot7t.com.cn/gembin/archive/2012/12/23/393378.html</link><dc:creator>gembin</dc:creator><author>gembin</author><pubDate>Sun, 23 Dec 2012 14:40:00 GMT</pubDate><guid>//www.ot7t.com.cn/gembin/archive/2012/12/23/393378.html</guid><wfw:comment>//www.ot7t.com.cn/gembin/comments/393378.html</wfw:comment><comments>//www.ot7t.com.cn/gembin/archive/2012/12/23/393378.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/gembin/comments/commentRss/393378.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/gembin/services/trackbacks/393378.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">情况是这样的,我学习cenots一直是在系统中采用virtualbox里面安装一个虚拟系统的方式。每次安装之后,都发现不能访问里面的80?1?306等这些常用的端口。也就是说,我只能在本机访问这些端口,想从其他机器访问不OK了。想起以前自己为了这件事花了整整一周的时候才知道是端口的问题。今天一定要记录下来,免得下次又忘记了?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">开?0?1?306端口?/p><pre prettyprint"="" style="margin-top: 6px; margin-bottom: 6px; padding: 2px 7px; font-family: 'Courier New', Courier, monospace, Fixed; overflow: auto; background-color: #f0f6e9; border: 1px solid #cccccc; font-size: 12.3px; line-height: 16px; width: 645.816650390625px; color: #333333; "><span style="margin: 0px; padding: 0px; color: #008800; ">/sbin/</span><span style="margin: 0px; padding: 0px; color: #000000; ">iptables </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">I INPUT </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">p tcp </span><span style="margin: 0px; padding: 0px; color: #666600; ">--</span><span style="margin: 0px; padding: 0px; color: #000000; ">dport </span><span style="margin: 0px; padding: 0px; color: #006666; ">80</span> <span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">j ACCEPT <br /></span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">sbin</span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">iptables </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">I INPUT </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">p tcp </span><span style="margin: 0px; padding: 0px; color: #666600; ">--</span><span style="margin: 0px; padding: 0px; color: #000000; ">dport </span><span style="margin: 0px; padding: 0px; color: #006666; ">3306</span> <span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">j ACCEPT <br /></span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">sbin</span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">iptables </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">I INPUT </span><span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">p tcp </span><span style="margin: 0px; padding: 0px; color: #666600; ">--</span><span style="margin: 0px; padding: 0px; color: #000000; ">dport </span><span style="margin: 0px; padding: 0px; color: #006666; ">21</span> <span style="margin: 0px; padding: 0px; color: #666600; ">-</span><span style="margin: 0px; padding: 0px; color: #000000; ">j ACCEPT <br /></span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">etc</span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">init</span><span style="margin: 0px; padding: 0px; color: #666600; ">.</span><span style="margin: 0px; padding: 0px; color: #000000; ">d</span><span style="margin: 0px; padding: 0px; color: #666600; ">/</span><span style="margin: 0px; padding: 0px; color: #000000; ">iptables save <br />service iptables restart</span></pre><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">其实,刚刚看了以前写过的一篇文章。发现此文已经是多余的了。唉。既然写了。就写完整一点吧?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">一般来说,我们不会使用linux自带的防火墙的。在IDC机房,人家的防火墙是硬件。肯定比软件要强大得多?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">可以使用如下方式对操作防火墙?br style="margin: 0px; padding: 0px; " />永久性关掉防火墙shell?/p><pre prettyprint"="" style="margin-top: 6px; margin-bottom: 6px; padding: 2px 7px; font-family: 'Courier New', Courier, monospace, Fixed; overflow: auto; background-color: #f0f6e9; border: 1px solid #cccccc; font-size: 12.3px; line-height: 16px; width: 645.816650390625px; color: #333333; "><span style="margin: 0px; padding: 0px; color: #000000; ">chkconfig </span><span style="margin: 0px; padding: 0px; color: #666600; ">--</span><span style="margin: 0px; padding: 0px; color: #000000; ">level </span><span style="margin: 0px; padding: 0px; color: #006666; ">35</span><span style="margin: 0px; padding: 0px; color: #000000; "> iptables off</span></pre><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">通过如下命令查看防火墙是否关闭:</p><pre prettyprint"="" style="margin-top: 6px; margin-bottom: 6px; padding: 2px 7px; font-family: 'Courier New', Courier, monospace, Fixed; overflow: auto; background-color: #f0f6e9; border: 1px solid #cccccc; font-size: 12.3px; line-height: 16px; width: 645.816650390625px; color: #333333; "><span style="margin: 0px; padding: 0px; color: #000000; ">service iptables status</span></pre><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">如果已经正确关闭,则会输出如下信息:</p><pre prettyprint"="" style="margin-top: 6px; margin-bottom: 6px; padding: 2px 7px; font-family: 'Courier New', Courier, monospace, Fixed; overflow: auto; background-color: #f0f6e9; border: 1px solid #cccccc; font-size: 12.3px; line-height: 16px; width: 645.816650390625px; color: #333333; "><span style="margin: 0px; padding: 0px; color: #000000; ">iptables</span><span style="margin: 0px; padding: 0px; color: #666600; ">:未运行防火墙?/span></pre><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">如果,你的是英文版本,则可能提示信息不太一样?br style="margin: 0px; padding: 0px; " />如果没有输出类似防火墙关闭的信息,直接重启系统或者执行如下命令试一试:</p><pre prettyprint"="" style="margin-top: 6px; margin-bottom: 6px; padding: 2px 7px; font-family: 'Courier New', Courier, monospace, Fixed; overflow: auto; background-color: #f0f6e9; border: 1px solid #cccccc; font-size: 12.3px; line-height: 16px; width: 645.816650390625px; color: #333333; "><span style="margin: 0px; padding: 0px; color: #000000; ">service iptables stop</span></pre><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">关掉防火墙之后,那么所有开启的端口都将会暴露给互联网所有人。那么,可能会导致别有用心的人针对你的系统漏洞做出一些破坏的事情?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: 微软雅黑, Verdana, Tahoma, 'BitStream vera Sans', Arial, Helvetica, sans-serif; font-size: 13px; line-height: 26px; background-color: #fcfff6; ">除了这个还有一个东西是就SELINUX这个玩意儿。如果防火墙放开了端口也无法进行访问。说明这个玩意做了限制,大家将它关闭即可?/p><img src ="//www.ot7t.com.cn/gembin/aggbug/393378.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.ot7t.com.cn/gembin/" target="_blank">gembin</a> 2012-12-23 22:40 <a href="//www.ot7t.com.cn/gembin/archive/2012/12/23/393378.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VirtualBox 安装 CentOs 6.3 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/12/23/393376.htmlgembingembinSun, 23 Dec 2012 14:15:00 GMT//www.ot7t.com.cn/gembin/archive/2012/12/23/393376.html//www.ot7t.com.cn/gembin/comments/393376.html//www.ot7t.com.cn/gembin/archive/2012/12/23/393376.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/393376.html//www.ot7t.com.cn/gembin/services/trackbacks/393376.html一、环境及资源准备?br style="margin: 0px; padding: 0px; " />1)虚拟机VritualBox 4.2版本。百度搜索下载此软件很容易下载,我一般是去天空软件和华军软件网站去下载?br style="margin: 0px; padding: 0px; " />2)CentOs版本采用的是CentOS-6.3-x86_64-minimal.iso,即最小化安装的版本。最小化安装版本没有图形界面,这样消耗CPU和内存的大大减少,所以,常常用来安装服务器系统使用。而桌面版本学习使用居多。而我们的目的就是要以服务器配置为目标进行?br style="margin: 0px; padding: 0px; " />CentOS 6.3 64位下载地址?a title="//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; ">//mirror.bit.edu.cn/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-minimal.iso
3)我的系统是Win7 64位的?windows xp 和windows 7 32位均可?/p>

二、安装配置虚拟机系统
1?打虚拟机。然后,选择虚拟机工具栏上的“新建”按钮。如图:

 

 

 

 

 

 

 

 

 

 

 

 

2)点?#8220;新建”按钮后,弹出如下弹出框,我们在名称项里面输入:centos 6.3 mini。这个位置随便填写没有任何问题。如果,你填写的是windows xp的话,则类型会自动变成windows,版本自动会变成windows xp。当我们填写centos 6.3的时候,类型会自动变成Linux,版本会变成 Red Hat。但是,我们安装的是64位的,所以,要修改Red Hat (64 bit)?br style="margin: 0px; padding: 0px; " />

3)点?#8220;下一?#8221;,弹出内存分配的选项框。这个地方特别要注意,内存在768MB这个位置是一个分水岭。如果低于这个这个值,则安装的时候会进入字符安装模式。大于等于这个值会进入图形安装界面。刚开始我不太熟悉字符安装模式,一直在这里纠结了很久都不知道为什么。后面,百度搜索答案的时候,发现官方已经有说明。如图,我分配了1024MB的内存。图中的绿色的线代表是内存最佳的分配值,超过这个值,可能会造成系统内存不足的问题?br style="margin: 0px; padding: 0px; " />

4)点?#8220;下一?#8221;保持默认的选项不变,如图:

5)点?#8220;创建”,弹出选项框,保持默认不变。如图:

6)点?#8220;下一?#8221;,弹出虚拟硬盘空间分配的方式。一般保持默认不变。如图:

7)点?#8220;下一?#8221;,设置虚拟硬盘位置和大小。我将虚拟硬盘文件的位置放置在了G:\VBoxs中,大小配置20GB。如图:

8)点?#8220;创建”按钮,即完成了对虚拟机的创建。但是,此时只是把配置做好了。即下来的操作才是安装系统。此时,在VBox列表里面已经有了刚才创建的虚拟机。如图:

9)到此一步,我们的配置并没有结束。因为,很多机器现在的内存都已经4GB了。这会给32位的系统安装造成一些问题。所以,我们还需要来消除这些问题。右键选中,VBox列表中刚才创建的虚拟机,选择“设置”,选择“系统”,再选择“处理?P)”,会看到一项:扩展特性。我们把它勾选上,让虚拟机支?GB以上的内存。如图:

10)现在我们要把Centos ISO镜像文件加载到虚拟机中。在上图中的左侧中选择“储存”。然后根据下图中的操作进行:

11)虚拟机除了镜像还可以使用电脑的光驱进行安装。如图:

然后点击“确定”即可?/p>

12)此时,我们再点击VBox工具样上?#8220;启动”按钮。点击之前,必须先选中刚才我们创建的虚拟机。就会到达如下界面:

如果,你进入这个界面之前,弹出如下错误提示:
VT-x/AMD-V 硬件加速器已被启动,但当前处于无效状态。您虚拟电脑内的操作系统将无法检测到64位的CPU,因此也将无法启?#8230;.

那么,你要确定你的CPU是支?4位的,可以按照如下方式进行解决:
1、请确认你的iso文件或DVD?4位的IOS文件?br style="margin: 0px; padding: 0px; " />2、请确认你的CPU?4位的CPU?br style="margin: 0px; padding: 0px; " />3、请确认BIOS的Virtualization是否为Enabled。设置方法:进入BIOS—->Advanced BIOS Features—–>Virtualization—->Disabled(预设?修改为Enabled,储?save),重启。有些BIOS设置方法与此并不相同,比如,有些笔记本Virualization这个选项进去是将VT-x与AMD-v两项设置分开的。所以,要将两个选项都要设置为Enabled?/p>

13)我们选择”Install or upgrade an existsing system”,然后,敲击回车键往下安装?/p>

14)接下来会的界面是让你检测要安装的系统介质是否完整有效。因为我是从正规渠道下载的系统ISO,所以,基本上不会出现问题。所以,我选择?#8220;Skip”选项跳过介质检测。如图:

 

15)回?#8220;Skip”之后出现如下界面,选择点击“Next”?/p>

16)此时会出现一个选择当前系统语言的选项,我们肯定是选择简体中文了,选择之后点击下一步。如图:

17)此时会出现一个键盘语言的选择,我们肯定是选择“美国式英?#8221;了。也就是保持默认选项,点?#8220;下一?#8221;即可。如图:

18)出现如下界面,保持默认即可,然后点?#8220;下一?#8221;继续往下安装。如图:

19)出现如下界面,点击“是,忽略所有数?#8221;。因为,在VirtualBox里面,所做的任何操作都不会影响到真实系统里面的数据。所以,放心大胆地选择此项吧。如图:

20)然后出现如下界面,要求我们为这台计算机取一个名字。很简单,我们按照要求填写即可。如图:

21)接下来的界面是让我们为电脑设置一个时区。我的选择如图所示:

22)即下来,会要求我们为默认的root系统账户设置一个密码。如图:

如果,你设置的密码过于简单。如?23456这样的密码,则系统会提示我们,密码强度不够安全。我们不管它,直接选择“无论如何都使?U)” 即可。如图:

23)在接下来的界面中,我们选择“使用所有空?#8221;的选项进行安装。如果,你想在电脑上装双系统,那么请不要选择此项。我们是用VittualBox完全不用担心硬盘会被格式化的问题。如图:

24)点?#8220;下一?#8221;会弹出如下提示框,我们选择“将修改写入硬?#8221;选择?/p>

25)OK。一切完毕之后,就该执行安装过程了。我们能做的就是等待。当安装进度100%的时候,会提示我们重新引导系统。到时候记得点击即可。如图:

 
可选的类型说明如下?nbsp;
Desktop  :基本的桌面系统,包括常用的桌面软件,如文查看工具?/span>
Minimal Desktop :基本的桌面系统,包含的软件更少?/span>
Minimal :基本的系统,不含有任何可选的软件包?/span>
Basic Server  :安装的基本系统的平台支持,不包含桌面?/span>
Database Server :基本系统平台,加上MySQL和PostgreSQL数据库,无桌面?/span>
Web Server ?/strong>基本系统平台,加上PHP,Web server,还有MySQL和PostgreSQL数据库的客户端,无桌面?/span>
Virtual Host :基本系统加虚拟平台?/span>
Software Development Workstation :包含软件包较多,基本系统,虚拟化平台,桌面环境,开发工具?/span>

到此关于VirtualBox安装Centos 6.3 最小化安装已经介绍完了?/p>

gembin 2012-12-23 22:15 发表评论
]]>
CentOS-语言设置 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/12/23/393375.htmlgembingembinSun, 23 Dec 2012 14:08:00 GMT//www.ot7t.com.cn/gembin/archive/2012/12/23/393375.html//www.ot7t.com.cn/gembin/comments/393375.html//www.ot7t.com.cn/gembin/archive/2012/12/23/393375.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/393375.html//www.ot7t.com.cn/gembin/services/trackbacks/393375.html查看所有的locale语言

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

■ 查看当前操作系统使用的语言

  1. # echo $LANG 

■ 设置系统locale语言为中文环境(永久生效?/p>

# vi /etc/sysconfig/i18n

  1. LANG="zh_CN.UTF-8" 

■ 设置系统locale语言为英文环境(永久生效?/p>

  1. LANG="en_US.UTF-8" 

■ 临时改变系统locale语言(退出本次登录立即失效)

  1. # export LANG=zh_CN.UTF-8 

■ 安装中文字体

  1. # yum install fonts-chinese.noarch 

■ 指定中文字体路径

# 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

    修改CentOS运行环境的默认语言环境变量?/p>

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

    找到export语句,在语句前面加入

    LANG=”en_US.UTF-8″

    再在export后面追加LANG

    export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC LANG

    保存配置,修改CentOS语言完成?/p>



gembin 2012-12-23 22:08 发表评论
]]>
MySQL on Mac OS X - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/09/22/388351.htmlgembingembinSat, 22 Sep 2012 15:38:00 GMT//www.ot7t.com.cn/gembin/archive/2012/09/22/388351.html//www.ot7t.com.cn/gembin/comments/388351.html//www.ot7t.com.cn/gembin/archive/2012/09/22/388351.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/388351.html//www.ot7t.com.cn/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
//www.sequelpro.com/


gembin 2012-09-22 23:38 发表评论
]]>
ethtool and mii-tool - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/09/07/387249.htmlgembingembinFri, 07 Sep 2012 06:41:00 GMT//www.ot7t.com.cn/gembin/archive/2012/09/07/387249.html//www.ot7t.com.cn/gembin/comments/387249.html//www.ot7t.com.cn/gembin/archive/2012/09/07/387249.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/387249.html//www.ot7t.com.cn/gembin/services/trackbacks/387249.htmlmii-tool(这是Linux下专门设置网卡工作模式的命令?/span>
  1. 查看网卡的工作模式,输入命令?/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
  从以上信息中可以看出,这块网卡工作在100M全双工自适应模式下,“100BaseTx-FD”意为100M Full Duplex?/span>
  2. 更改网卡的工作模式,输入命令?/span>
  #mii-tool -F media [interface]
  media可选的模式?00baseTx-FD?00baseTx-HD?0baseT-FD?0baseT-HD等?Interface代表所选择的网卡,如eth0、eth1等,默认为eth0?/span>
  例如,设置网卡工作在10M半双工模式下,输入命令:
  #mii-tool -F 10baseT-HD eth0
  3. 恢复网卡的自适应工作模式,输入命令:
  #mii-tool -r eth0
  更详细的使用方法可以用mii-tool -h来获得?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:

//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 Conventions - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/08/25/386269.htmlgembingembinSat, 25 Aug 2012 08:43:00 GMT//www.ot7t.com.cn/gembin/archive/2012/08/25/386269.html//www.ot7t.com.cn/gembin/comments/386269.html//www.ot7t.com.cn/gembin/archive/2012/08/25/386269.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/386269.html//www.ot7t.com.cn/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 renderer - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/21/383681.htmlgembingembinSat, 21 Jul 2012 15:16:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/21/383681.html//www.ot7t.com.cn/gembin/comments/383681.html//www.ot7t.com.cn/gembin/archive/2012/07/21/383681.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383681.html//www.ot7t.com.cn/gembin/services/trackbacks/383681.html

gembin 2012-07-21 23:16 发表评论
]]>
Flash 3d Sokoban Prototype With Alternativa3d - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/21/383679.htmlgembingembinSat, 21 Jul 2012 15:03:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/21/383679.html//www.ot7t.com.cn/gembin/comments/383679.html//www.ot7t.com.cn/gembin/archive/2012/07/21/383679.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383679.html//www.ot7t.com.cn/gembin/services/trackbacks/383679.html阅读全文

gembin 2012-07-21 23:03 发表评论
]]>
Flash 3d Sokoban Prototype With Alternativa3d Textured Version - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/21/383678.htmlgembingembinSat, 21 Jul 2012 15:00:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/21/383678.html//www.ot7t.com.cn/gembin/comments/383678.html//www.ot7t.com.cn/gembin/archive/2012/07/21/383678.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383678.html//www.ot7t.com.cn/gembin/services/trackbacks/383678.html阅读全文

gembin 2012-07-21 23:00 发表评论
]]>
Flash 3d Sokoban Prototype With Alternativa3d Textured Version - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/21/383677.htmlgembingembinSat, 21 Jul 2012 14:58:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/21/383677.html//www.ot7t.com.cn/gembin/comments/383677.html//www.ot7t.com.cn/gembin/archive/2012/07/21/383677.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383677.html//www.ot7t.com.cn/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 project - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/21/383676.htmlgembingembinSat, 21 Jul 2012 14:56:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/21/383676.html//www.ot7t.com.cn/gembin/comments/383676.html//www.ot7t.com.cn/gembin/archive/2012/07/21/383676.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383676.html//www.ot7t.com.cn/gembin/services/trackbacks/383676.html阅读全文

gembin 2012-07-21 22:56 发表评论
]]>
Setting up the VNC Server in Mac OS X Lion - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/14/383070.htmlgembingembinFri, 13 Jul 2012 16:00:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/14/383070.html//www.ot7t.com.cn/gembin/comments/383070.html//www.ot7t.com.cn/gembin/archive/2012/07/14/383070.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383070.html//www.ot7t.com.cn/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 Lion - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/13/383063.htmlgembingembinFri, 13 Jul 2012 14:43:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/13/383063.html//www.ot7t.com.cn/gembin/comments/383063.html//www.ot7t.com.cn/gembin/archive/2012/07/13/383063.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/383063.html//www.ot7t.com.cn/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 3 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/07/07/382482.htmlgembingembinSat, 07 Jul 2012 14:44:00 GMT//www.ot7t.com.cn/gembin/archive/2012/07/07/382482.html//www.ot7t.com.cn/gembin/comments/382482.html//www.ot7t.com.cn/gembin/archive/2012/07/07/382482.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/382482.html//www.ot7t.com.cn/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 basis - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/05/22/378747.htmlgembingembinMon, 21 May 2012 16:25:00 GMT//www.ot7t.com.cn/gembin/archive/2012/05/22/378747.html//www.ot7t.com.cn/gembin/comments/378747.html//www.ot7t.com.cn/gembin/archive/2012/05/22/378747.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/378747.html//www.ot7t.com.cn/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 proxy - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/05/03/377268.htmlgembingembinThu, 03 May 2012 05:16:00 GMT//www.ot7t.com.cn/gembin/archive/2012/05/03/377268.html//www.ot7t.com.cn/gembin/comments/377268.html//www.ot7t.com.cn/gembin/archive/2012/05/03/377268.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/377268.html//www.ot7t.com.cn/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:  //static.springsource.org/spring/docs/3.1.1.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#aop-introduction-proxies 




gembin 2012-05-03 13:16 发表评论
]]>
Deep Copy And Shallow Copy - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/04/07/373545.htmlgembingembinSat, 07 Apr 2012 10:41:00 GMT//www.ot7t.com.cn/gembin/archive/2012/04/07/373545.html//www.ot7t.com.cn/gembin/comments/373545.html//www.ot7t.com.cn/gembin/archive/2012/04/07/373545.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373545.html//www.ot7t.com.cn/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. DOM - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/04/01/373206.htmlgembingembinSun, 01 Apr 2012 08:32:00 GMT//www.ot7t.com.cn/gembin/archive/2012/04/01/373206.html//www.ot7t.com.cn/gembin/comments/373206.html//www.ot7t.com.cn/gembin/archive/2012/04/01/373206.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373206.html//www.ot7t.com.cn/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 shell - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/04/01/373205.htmlgembingembinSun, 01 Apr 2012 08:30:00 GMT//www.ot7t.com.cn/gembin/archive/2012/04/01/373205.html//www.ot7t.com.cn/gembin/comments/373205.html//www.ot7t.com.cn/gembin/archive/2012/04/01/373205.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373205.html//www.ot7t.com.cn/gembin/services/trackbacks/373205.html //www.grymoire.com/Unix/CshTop10.txt

gembin 2012-04-01 16:30 发表评论
]]>
Get substring of a string under UNIX/Linux - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/04/01/373200.htmlgembingembinSun, 01 Apr 2012 07:38:00 GMT//www.ot7t.com.cn/gembin/archive/2012/04/01/373200.html//www.ot7t.com.cn/gembin/comments/373200.html//www.ot7t.com.cn/gembin/archive/2012/04/01/373200.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373200.html//www.ot7t.com.cn/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/Linux - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/04/01/373199.htmlgembingembinSun, 01 Apr 2012 07:14:00 GMT//www.ot7t.com.cn/gembin/archive/2012/04/01/373199.html//www.ot7t.com.cn/gembin/comments/373199.html//www.ot7t.com.cn/gembin/archive/2012/04/01/373199.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373199.html//www.ot7t.com.cn/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 LinkedHashSet - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/03/31/373111.htmlgembingembinSat, 31 Mar 2012 03:30:00 GMT//www.ot7t.com.cn/gembin/archive/2012/03/31/373111.html//www.ot7t.com.cn/gembin/comments/373111.html//www.ot7t.com.cn/gembin/archive/2012/03/31/373111.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/373111.html//www.ot7t.com.cn/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 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/03/04/371188.htmlgembingembinSat, 03 Mar 2012 16:27:00 GMT//www.ot7t.com.cn/gembin/archive/2012/03/04/371188.html//www.ot7t.com.cn/gembin/comments/371188.html//www.ot7t.com.cn/gembin/archive/2012/03/04/371188.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/371188.html//www.ot7t.com.cn/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
定义说明
%@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
类型定义建议
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] - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/03/03/371166.htmlgembingembinSat, 03 Mar 2012 07:43:00 GMT//www.ot7t.com.cn/gembin/archive/2012/03/03/371166.html//www.ot7t.com.cn/gembin/comments/371166.html//www.ot7t.com.cn/gembin/archive/2012/03/03/371166.html#Feedback2//www.ot7t.com.cn/gembin/comments/commentRss/371166.html//www.ot7t.com.cn/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 (爱情多美? - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/01/21/368811.htmlgembingembinSat, 21 Jan 2012 03:21:00 GMT//www.ot7t.com.cn/gembin/archive/2012/01/21/368811.html//www.ot7t.com.cn/gembin/comments/368811.html//www.ot7t.com.cn/gembin/archive/2012/01/21/368811.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/368811.html//www.ot7t.com.cn/gembin/services/trackbacks/368811.html
Ce frumoasa e iubirea 爱情多美?
Fiecare clipa pictata-n roz, 每一分每一秒都涂成了玫瑰色
Tre'sa recunosc,iti apartine... 我必须得承认,这属于?
Si nici macar eu nu ma cunosc 我已无法认识自己
Asa cum ma stii pe mine.. 只有你了解真正的?
Ma tem uneori ca ai sa pleci 有时候我担心你将离去?
Si nu vreau sa ma lasi fara tine...不要留下孤单的我
Iar eu nu sunt eu...而我已不是我?
De fapt,fara tine,sunt nimeni...事实上,没有你,我也将无法存?
Refren: Ce frumoasa e iubirea ,爱情多美呀?
Cand ma alinti cu zambetul tau curat! 当你用纯洁的微笑爱抚我时
Ce frumoasa e iubirea 爱情多美呀
Cand tot ce spui devine adevarat!当你说的话成真的那一?
(bis)

Ficare clipa trecuta-n alb 白日里度过的每一?
A insemna ca tu esti departe 告诉你已走远
Uneori ma intreb daca esti real 有时候我问自己你是否真的存在
Sau inchipuit din printr-o carte! 也许你只是书中的虚幻
Ma tem uneori ca ai sa pleci 有时担心你会离去
Si nu vreau sa ma lasi fara tine... 不要留下孤单的我
Iar eu nu sunt eu... 而我已不是我
De fapt,fara tine,sunt nimeni... 没有你,我也将不再存?
Refren: Ce frumoasa e iubirea 爱情多美呀
Cand ma alinti cu zambetul tau curat! 当你用纯洁的微笑爱抚我时
Ce frumoasa e iubirea 爱情多美呀
Cand tot ce spui devine adevarat! 当你的话语成真时
(bis)
Ma cuprinzi incet..ma stangi la piept 慢慢将我拥入怀?
Imi spui ca nu..n-ai sa pleci prea curand... 对我说不。。。不要马上立开?
(bis)
Refren: Ce frumoasa e iubirea 爱情多美呀
Cand ma alinti cu zambetul tau curat! 当你用纯洁的微笑爱抚我时
Ce frumoasa e iubirea 爱情多美呀
Cand tot ce spui devine adevarat! 当你的话语成真时
(bis)


gembin 2012-01-21 11:21 发表评论
]]>
Mac Keyboard Shortcuts - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/gembin/archive/2012/01/21/368798.htmlgembingembinFri, 20 Jan 2012 16:57:00 GMT//www.ot7t.com.cn/gembin/archive/2012/01/21/368798.html//www.ot7t.com.cn/gembin/comments/368798.html//www.ot7t.com.cn/gembin/archive/2012/01/21/368798.html#Feedback0//www.ot7t.com.cn/gembin/comments/commentRss/368798.html//www.ot7t.com.cn/gembin/services/trackbacks/368798.html阅读全文

gembin 2012-01-21 00:57 发表评论
]]>
心理学英文词?/title><link>//www.ot7t.com.cn/gembin/archive/2012/01/14/368493.html</link><dc:creator>gembin</dc:creator><author>gembin</author><pubDate>Sat, 14 Jan 2012 07:19:00 GMT</pubDate><guid>//www.ot7t.com.cn/gembin/archive/2012/01/14/368493.html</guid><wfw:comment>//www.ot7t.com.cn/gembin/comments/368493.html</wfw:comment><comments>//www.ot7t.com.cn/gembin/archive/2012/01/14/368493.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/gembin/comments/commentRss/368493.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/gembin/services/trackbacks/368493.html</trackback:ping><description><![CDATA[     摘要: 心理?psychology心理现象 mental phenomenon心理过程 mental process心理状?mental state心理活动 mental activity意识 consciousness心理维度 psychological dimension心理运动 psychomotor内部活动 internal activity普通心理学 general psychology实验...  <a href='//www.ot7t.com.cn/gembin/archive/2012/01/14/368493.html'>阅读全文</a><img src ="//www.ot7t.com.cn/gembin/aggbug/368493.html" width = "1" height = "1" /><br><br><div align=right><a href="//www.ot7t.com.cn/" title="四川福利彩票快乐12">四川福利彩票快乐12</a> 2012-01-14 15:19 <a href="//www.ot7t.com.cn/gembin/archive/2012/01/14/368493.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <script>(function(){ var src = (document.location.protocol == "http:") ? "//js.passport.qihucdn.com/11.0.1.js?f7a6bc378844a5df707c414e6b6fea33":"https://jspassport.ssl.qhimg.com/11.0.1.js?f7a6bc378844a5df707c414e6b6fea33"; document.write('<script src="' + src + '" id="sozz"><\/script>'); })(); </script>