Recent Notes
Displaying keyword search results 1 - 10
Created by magnum on October 22, 2012 15:46:44
Last update: October 22, 2012 15:46:44
Example code from the Linux Programmer's Manual:
#include <stdio.h>
#include <stdlib.h>
#incl...
Created by voodoo on September 17, 2012 15:02:15
Last update: September 17, 2012 15:02:15
Start gdb with the executable and coredump:
$ gdb <path to executable> core
While in the debugger, use the following commands:
(gdb) where ("shows a summary of the stack")
...
Example debug session from Debugging Under Unix: gdb Tutorial :
Use backtrace (or bt ) to see the callstack:
(gdb) backtrace
#0 Node<int>::next (this=0x0) ...
Inspect the value of item_to_remove at address 0xffbef014 (the value is 1):
(gdb) x 0xffbef014
0xffbef014: 0x00000001
(g...
Note: The program must be compiled with the debug switch -g in order to see the source code.
More resources:
Linux software debugging with GDB
Debugging with gdb
Created by Fang on April 16, 2012 13:18:40
Last update: April 16, 2012 13:18:40
Simply call pageContext.setAttribute() to export a variable from within a JSP custom tag:
public class MyCustomVarTag extends TagSupport {
...
The availability of the exported variable can be limited in the TLD:
<tag>
<name>setVar</name>
<tag-class...
The availability scopes are:
Value Availability
NESTED Between the start tag and the end tag.
AT_BEGIN From the start tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the end of the page.
AT_END After the end tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the end of the page.
Created by Fang on April 16, 2012 12:58:35
Last update: April 16, 2012 12:58:35
To implement a JSP custom tag with dynamic attributes (for example, to pass-thru arbitrary attributes not handled by the JSP tag):
Set the dynamic-attributes element to true in the TLD:
<tag>
<name>mark</name>
<tag-class>c...
The tag handler must implement javax.servlet.jsp.tagext.DynamicAttributes :
package com.example.jsp;
import java.io.*;
...
Created by Fang on January 28, 2012 13:24:09
Last update: January 28, 2012 13:31:22
This is a simple JSP custom tags library with tag body. Just like the JSF counterpart , it splits a string and repeats the body for each word, i.e., with this markup:
<%@ taglib uri="http://custom.tag.com/demo" prefix...
output:
<html>
<body>
<p>Hello Tigger!</p>
<p>H...
With Maven, this is the directory structure:
./src
./src/main
./src/main/resources
./s...
There are three files to write:
pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0"...
src/main/java/tagdemo/IterateTag.java :
package tagdemo;
import java.io.IOException...
src/main/resources/META-INF/demotag.tld :
<?xml version="1.0" encoding="UTF-8"?>
<!DO...
Build with:
mvn clean install
To use it as a dependency in other Maven projects:
<dependency>
<groupId>tag-demo</groupId>
...
Created by Fang on December 01, 2011 18:54:54
Last update: December 01, 2011 18:54:54
Use the varStatus attribute with the ui:repeat tag to get the iteration index:
<ui:repeat varStatus="status" var="item" value="#{...
The varStatus attribute specifies the name of the exported request scoped variable for the status of the iteration.The object is a POJO with the following read-only JavaBeans properties. This scoped variable has nested visibility.
begin of type Integer
end of type Integer
index of type int
step of type Integer
even of type boolean
odd of type boolean
first of type boolean
last of type boolean
Created by Fang on November 22, 2011 10:40:16
Last update: November 22, 2011 10:40:16
This is an example that uses tag handler, UI component and renderer together to support a custom taglib. The main purpose is to show how these components play together.
The tag renders
<ui:param name="extra" value="el interpreted"/>
...
as
<h3>my:foreach</h3>
<ul class="css class" extra...
These are the files:
The tag handler ( src/main/java/com/example/ForeachTagHandler.java ):
package com.example;
import java.util.Map;
...
The UI component ( src/main/java/com/example/UIForeach.java ):
package com.example;
import java.io.IOExcep...
The renderer ( src/main/java/com/example/ForeachRenderer.java ):
package com.example;
import java.io.IOExcep...
Faces config ( src/main/resources/META-INF/faces-config.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<faces-c...
Taglib config ( src/main/resources/META-INF/foreach.taglib.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<facelet...
Created by Fang on November 08, 2011 20:55:00
Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print
<p>john</p> <p>steve</p> <p>mike</p> with custom tag <my:foreach> : <my:foreach var="who" value="john steve mike"> ... These are the files: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/com/example/UIForeash.java : package com.example; import java.io.IOExcep... src/main/resources/META-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <faces-c... src/main/resources/META-INF/foreach.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by magnum on October 20, 2011 20:44:23
Last update: October 20, 2011 20:53:26
Copied verbatim from The GNU C Library Manual . When you have finished using a socket, you can simply close its file descriptor with close ; see Opening and Closing Files . If there is still data waiting to be transmitted over the connection, normally close tries to complete this transmission. You can control this behavior using the SO_LINGER socket option to specify a timeout period; see Socket Options . You can also shut down only reception or transmission on a connection by calling shutdown , which is declared in sys/socket.h . Function: int shutdown (int socket, int how) The shutdown function shuts down the connection of socket socket. The argument how specifies what action to perform: 0 - Stop receiving data for this socket....
Created by magnum on October 06, 2011 14:35:20
Last update: October 06, 2011 14:35:20
The longjmp function jumps to the line where setjmp was last called. In return, setjmp returns the value passed in as the second parameter to longjmp .
#include <stdio.h>
#include <stdlib.h>
#incl...
Result:
$ ./longjmp
val is 0
val is 1
--> val is ...