RSS

run google as root :D

http://yeslinux.blogspot.com/2011/11/run-google-chrome-as-root-in-ubuntu.html

 
Để lại phản hồi

Posted by on Tháng Hai 8, 2012 in Uncategorized

 

How Browsers Work

Preface

This comprehensive primer on the internal operations of WebKit and Gecko is the result of much research done by Israeli developer Tali Garsiel. Over a few years, she reviewed all the published data about browser internals (see Resources) and spent a lot of time reading web browser source code. She wrote:

In the years of IE 90% dominance there was nothing much to do but regard the browser as a “black box”, but now, with open source browsers having more than half of the usage share, it’s a good time to take a peek under the engine’s hood and see what’s inside a web browser. Well, what’s inside are millions of C++ lines…

Tali published her research on her site, but we knew it deserved a larger audience, so we’ve cleaned it up and republished it here.

As a web developer, learning the internals of browser operations helps you make better decisions and know the justifications behind development best practices. While this is a rather lengthy document, we recommend you spend some time digging in; we guarantee you’ll be glad you did. Paul Irish, Chrome Developer Relations

http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#The_HTML_grammar_definition

 
Để lại phản hồi

Posted by on Tháng Mười Hai 29, 2011 in Uncategorized

 

JSON to Java with JDK6

JSON to Java with JDK6

There are multiple frameworks for transforming a JSON expression to a Java object tree, but the Java Platform does not come out of the box with some javax.json package (I heard there are plans for that).

Today I will show that you can easily transform a JSON expression to a simple Java object tree (map, arrays, primitive wrappers and string) with Java 6 and no additional framework.

Obviously, it may not be the best way to proceed, specially when it comes to speed, security or java mapping. However this solution is appropriate if those are not a concern and you don’t want to add a dependency to an external library for parsing JSON expressions.

The solution relies on the javax.script package and its Javascript binding. Indeed what’s best than Javascript to parse JavaScript Object Notation ?

The scripting API provides evaluation of any Javascript which is nice, unfortunately native Javascript objects are not usable from Java, but the magic of Javascript will come to the rescue!

Javascript is a dynamic language which allows to modify its meta object protocol (MOP) to add new functions on native Javascript objects, through the concept of prototypes. We can modify each of the base Javascript type’s prototypes to add a toJava function that will return a Java version of the object:

Object.prototype.toJava = function() {
var m = new java.util.HashMap();
for (var key in this)
if (this.hasOwnProperty(key))
m.put(key, this[key].toJava());
return m;
};
Array.prototype.toJava = function() {
var l = this.length;
var a = new java.lang.reflect.Array.newInstance(java.lang.Object, l);
for (var i = 0;i < l;i++)
a[i] = this[i];
return a;
};
String.prototype.toJava = function() {
return new java.lang.String(this);
};
Boolean.prototype.toJava = function() {
return java.lang.Boolean.valueOf(this);
};
Number.prototype.toJava = function() {
return java.lang.Integer(this);
};

view raw json2java.js This Gist brought to you by GitHub.

Now you probably get the idea, each toJava function returns the Java counterpart of the Javascript object. Initially I wanted to iterate the object tree, but extending the types thanks to the prototype is a much better solution.

We also need to add the missing Java part that loads this JS and uses it to create our Java objects. This is trivial to do thanks to the scripting API, here is how to load the Javascript and setup the engine:

String init = read(Tools.class.getResource("json2java.js"));
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
engine.eval(init);
jsonParser = engine;

view raw setup This Gist brought to you by GitHub.

Now we need to use the engine to convert JSON expressions:

Bindings bindings = new SimpleBindings();
String eval = "var tmp = (" + json + ");var o = new AtomicReference(tmp.toJava());";
jsonParser.eval(eval, bindings);
AtomicReference ret = (AtomicReference)bindings.get("o");
return ret.get();

view raw parse This Gist brought to you by GitHub.

Here there is a little trick: you can remark the usage of AtomicReference and it may look inappropriate since we are not dealing with concurrent programming. The trick is that if we return a String from the engine to Java, the engine will wrap it as a Javascript string and we want to avoid that. The AtomicReference makes the value opaque to Javascript and the Java code will unwrap it.

Those three pieces together makes a lightweight solution to transform JSON expressions to Java objects. There are certainly corner case not handled in this code, but it’s a solid basis to start with, I saved the code in a GitHub gist there.

http://blog.julienviet.com/2011/12/26/json-to-java-with-jdk6/

 
Để lại phản hồi

Posted by on Tháng Mười Hai 28, 2011 in Uncategorized

 

Ru doi di nhe

 
Để lại phản hồi

Posted by on Tháng Mười Một 30, 2011 in Uncategorized

 

chot nhan ra hom nay van the

chot nhan ra hom nay van the, nhu hom wa va giong ngay mai.minh chua co dinh duong cu the…

 
2 phản hồi

Posted by on Tháng Mười Một 24, 2011 in Uncategorized

 

 
2 phản hồi

Posted by on Tháng Mười Một 24, 2011 in Uncategorized

 

 
Để lại phản hồi

Posted by on Tháng Mười Một 23, 2011 in Uncategorized