jQuery: eq() vs. get()

There are several ways to access queried DOM elements. You get either a DOM element using get() or a jQuery object using eq(). This can be confusing while you try to call jQuery API functions on DOM elements.

The example shows how to get the first array element on three different ways.

<ul>
  <li></li>
  <li></li>
  <li></li>
</ul>

<script type="text/javascript">
    $(document).ready(function(){
        var elems, elem;
        elems = $("li"); // get an array of all the list items

        // This is a jQuery object that you can call jQuery related methods on.
        elem = elems.eq(0); 

        // This is the DOM element itself that lets you access the native
        // javascript attributes and methods.
        elem = elems.get(0); 

        // This is the DOM element too.
        elem = elems[0];
    });
</script>

Instead of using the filter method eq() you can combine the filter with the selector like this

var elem = $("li:eq(0)");

or

var elem = $("li:first");

To turn a DOM element into a jQuery object you can wrap it with jQuery(element) or $(element) if you’re not in conflict mode. But keep in mind that this creates a new object which wastes consumes memory so pay attention if you do this in a loop.

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

Java kills people

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

Matlab commands for feedback controls

Here is a small matlab reference for feedback calculations or simulations:

  • roots: Find polynomial roots
  • poly: Convert roots to polynomial
  • conv: Convolution and polynomial multiplication
  • polyval: Evaluate polynomial
  • tf: Creation of transfer functions or conversion to transfer function
  • pzmap: Pole-zero map of LTI models
  • pole: Compute the poles of LTI models
  • zero: Computes the transmission zeros of LTI models
  • series: Series interconnection of the two LTI models
  • parallel: Parallel interconnection of two LTI models
  • feedback: Feedback connection of two LTI models
  • minreal: Minimal realization and pole-zero cancellation
  • step: Step response of LTI models
  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

Accessing the right method in Java

A inner class can call methods of an outer class.

public class Dummy1
{
	private class Dummy2
	{
		public Dummy2()
		{
			method();
		}
	}

	private void method() { }
}

So far so good but if the inner class has the same method this will be called instead. To avoid this ambiguity one can call the method in a more specific way. To be able to call the method of the outer class the prefix Dummy1.this can be added.

public class Dummy1
{
	private class Dummy2
	{
		public Dummy2()
		{
			Dummy1.this.method();
		}

		private void method() { }
	}

	private void method() { }
}
  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark

Urinal manual

Based on the tikz flowchart example I created my first flowchart in Latex. Creating such a flowchart with Latex is not as easy as it looks like. Sometimes you don’t get an error message even if there is an error (especially missing semicolons) in the code. In my case pdftex just hang up. One thing was a bit tricky but first have a look at my code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]

\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=4cm, text centered, rounded corners, minimum height=4em, minimum width=4.5cm]

\tikzstyle{line} = [draw, -latex']

\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]

\begin{tikzpicture}[node distance = 3cm, auto]
% The nodes
\node[cloud] (business) {Business};
\node[block, below of=business] (person) {i:=person};
\node[decision, below of=person] (sex) { i.sex = male ?};
\node[decision, below of=sex, node distance=4cm] (sex2) { i.sex = pre-op transsexuel female ?};    

\node[block, right of=sex2, node distance=6cm] (execution_block_1) {i.enter(toilet)\\
i.open(trousers)\\
i.target(eyes, center)\\
i.target(hands, center)
};

\node[block, below of=execution_block_1] (open_bladder) { i.open(bladder) };
\node [decision, below of=open_bladder, text width=2cm] (bladder_empty) {i.bladder = empty?};

\node[block, below of=bladder_empty] (execution_block_2) { i.close(bladder)\\
 i.close(trousers)\\
 i.flush(urinal)
 };

\node [block, below of=execution_block_2] (exit) { i.exit() };

% The connections
\path [line] (business) -- (person);
\path [line] (person) -- (sex);
\path [line] (execution_block_1) -- (open_bladder);
\path [line] (execution_block_2) -- (exit);

\path [line] (sex) -- node [near start] {no} (sex2);
\path [line] (sex) -| node [near start] {yes} (execution_block_1);
\path [line] (sex2) -- node [near start] {no} (execution_block_1);
\path [line] (sex2) |- node [near start] {yes} (exit);
\path [line] (open_bladder) -- (bladder_empty);
\path [line] (bladder_empty) -- node [near start] {yes} (execution_block_2);
\path [line] (bladder_empty) -- +(4,0) -- +(4,3) -- node [near start] {no} (open_bladder);
\end{tikzpicture}

\end{document}

The decision block with the bladder emptiness check has more than one curve. -| or |- didn’t work so the trick here is that you have to add coordinates (x,y) to the connection line where it should curve.

  • Delicious
  • Digg
  • Technorati Favorites
  • Reddit
  • LinkedIn
  • Facebook
  • Spurl
  • Twitter
  • Webnews
  • YiGG
  • MySpace
  • Yahoo Bookmarks
  • FriendFeed
  • Google Bookmarks
  • LiveJournal
  • Share/Bookmark