background preloader

PhantomJS: Headless WebKit with JavaScript API

PhantomJS: Headless WebKit with JavaScript API

Vimcasts - free screencasts about the text editor Vim IAmDann Java Anti-Patterns This page collects some bad code that may not look so obviously bad to beginners. Beginners often struggle with the language syntax. They also have little knowledge about the standard JDK class library and how to make the best use of it. Some of these may seem like micro-optimization, premature optimization without profiling or constant factor optimizations. If you are interested in how to pogram compiler friendly, look at the JDK Performance Wiki. In the end a lot of your application's performance depends on the overall quality of your code. Compare these scenarios (assume 100MB young generation): In the slower scenario the transaction duration is 10 times longer. String concatenation String s = ""; for (Person p : persons) { s += ", " + p.getName(); } s = s.substring(2); //remove first comma This is a real memory waster. Lost StringBuffer performance StringBuffer sb = new StringBuffer(); sb.append("Name: "); sb.append(name + '\n'); sb.append("!") String s = "Name: " + name + "\n!"

RESTful web services with MongoDB A few tutorials ago,in the tutorial about RestEasy and Hibernate, we saw how we could integrate RESTEasy with Hibernate.Now in this tutorial we will see how can we create Restful web services with RestEasy and MongoDB. As an example we will see how to expose the documents of collection named Categories.The service class will be: Since our service class is ready we now need to create the Application class: package com.javaonly.service; import java.util.HashSet; import java.util.Set; import javax.ws.rs.core.Application; public class CategoryApplication extends Application { private Set<Class<?>> classes=new HashSet<Class<? Finally, in order to configure RESTEasy we must add the following snippet in the web.xml: Now every DAO class will extend AbstractDAO class.So in the case of categoryDAO we will have: package com.javaonly.mongo.daos; public class CategoryDao extends AbstractDao{ public CategoryDao(){ super(); } } As can see in the above class we've used a class named MongoDBUtil.

Don't write on the whiteboard :: Joseph Perla I recently interviewed at a major technology company. I won't mention the name because, honestly, I can't remember whether I signed an NDA, much less how strong it was. I did well. Mostly because of luck. 1. When I interviewed at Palantir around 5 years ago, I had a lot of trouble with this. Most people think you have to write on the whiteboard. The interviewer started by asking me to code up a simple recursive calculation, using any language I wanted. The interviewers don't care. 2. So I asked for some paper and a pen. You should always have paper and pen anyway to write down ideas. Some of the best programmers figure out the high-level overview on paper before they write a single line of new code. 3. Even if you are a C++ systems guru. You will waste a lot of time writing string manipulation code and initialization code that you can do in one line of Python. All I had was a post-it note, a tiny amount of space. 4. Five minutes later, I had my algorithm. 5. 6. Don't just read blogs. 7.

Binary Trees by Nick Parlante This article introduces the basic concepts of binary trees, and then works through a series of practice problems with solution code in C/C++ and Java. Binary trees have an elegant recursive pointer structure, so they are a good way to learn recursive pointer algorithms. Contents Section 1. Stanford CS Education Library -- #110 This is article #110 in the Stanford CS Education Library. Related CSLibrary Articles Linked List Problems ( -- a large collection of linked list problems using various pointer techniques (while this binary tree article concentrates on recursion) Pointer and Memory ( -- basic concepts of pointers and memory The Great Tree-List Problem ( -- a great pointer recursion problem that uses both trees and lists Section 1 -- Introduction To Binary Trees Binary Search Tree Niche Basically, binary search trees are fast at insert and lookup. Strategy Lookup() 1.

Tree List Recursion Abstract Stanford CS Education Library: one of the neatest recursive pointer problems ever devised. This is an advanced recursive pointer problem that uses a binary tree and a doubly linked list. You should be comfortable with pointers and recursion to understand this problem. This article introduces the problem with a few memory diagrams, gives some hints, and provides solution code in both Java and C/C++. See: TreeListRecursion.html Or as a PDF: TreeListRecursion.pdf -- the same content, but in PDF, so both the text and images are in the one file See also... Linked Lis tBasics -- introduction to linked lists Linked List Problems -- more advanced linked list problems Binary Trees -- introduction to binary trees Downloading help Up to the CS Education Library Home Tricks with Direct Memory Access in Java « Highly Scalable Blog Java was initially designed as a safe, managed environment. Nevertheless, Java HotSpot VM contains a “backdoor” that provides a number of low-level operations to manipulate memory and threads directly. This backdoor – sun.misc.Unsafe – is widely used by JDK itself in the packages like java.nio or java.util.concurrent. Obtaining Unsafe The sun.misc.Unsafe class is so unsafe that JDK developers added special checks to restrict access to it. Fortunately there is theUnsafe field that can be used to retrieve Unsafe instance. In the next sections we will study several tricks that become possible due to the following methods of Unsafe: sizeof() Function The first trick we will do is C-like sizeof() function, i.e. function that returns shallow object size in bytes. As so, we can implement sizeof() as follows: We need to use normalize() function because addresses between 2^31 and 2^32 will be automatically converted to negative integers, i.e. stored in complement form. Direct Memory Management

learn.knockoutjs.com In this first tutorial you'll experience some of the basics of building a web UI with the Model-View-ViewModel (MVVM) pattern using knockout.js. You'll learn how to define a UI's appearance using views and declarative bindings, its data and behavior using viewmodels and observables, and how everything stays in sync automatically thanks to Knockout's dependency tracking (even with arbitrary cascading chains of data). Using bindings in the view In the bottom-right corner, you've got a viewmodel containing data about a person. Modify the two <strong> elements in the view, adding data-bind attributes to display the person's name: <p>First name: <strong data-bind="text: firstName"></strong></p><p>Last name: <strong data-bind="text: lastName"></strong></p> data-bind attributes are how Knockout lets you declaratively associate viewmodel properties with DOM elements. Running the code To run your updated application, click Run in the bottom-left pane, or press Ctrl+Enter. Having trouble?

Related: