Recent Notes
Displaying notes 91 - 100
Created by Dr. Xi on October 23, 2009 23:26:44
<c:choose> <c:when test="${case == 1}"> Case one </c:when> <c:when test="${case == 2}"> Case two </c:when> <c:otherwise> Everything else </c:otherwise> </c:choose>
Created by Dr. Xi on October 18, 2009 04:25:25
start python with python -v import django and print version: Type "help", "copyright", "credits" or "license" for more information. >>> import django import django # directory /usr/local/python/lib/python2.5/site-packages/django # /usr/local/python/lib/python2.5/site-packages/django/__init__.pyc matches /usr/local/python/lib/python2.5/site-packages/django/__init__.py import django # precompiled from /usr/local/python/lib/python2.5/site-packages/django/__init__.pyc >>> print django.VERSION (1, 0, 2, 'final', 0) >>>
Created by James on October 11, 2009 21:15:53
Last update: October 11, 2009 21:19:39
Many techniques for making rounded corners do not work well when the element being rounded is displayed on a background with a different color (or multiple colors). Example 1: Nifty Cube with JavaScript <html> <head> <base href="http://www.html.it/articoli/niftycube/"/> <style type="text/css"> body { background: url(file:///C:/images/background.png) repeat-x; } #content { margin: 20px; margin-top: 40px; background: #42424B; color: #FFF; padding: 20px; width: 150px; } #content h1 { font: lighter 150% "Trebuchet MS",Arial sans-serif; color: #208BE1; } </style> <script type="text/javascript" src="niftycube.js"></script> <script type="text/javascript"> NiftyLoad = function() { Nifty("div#content", "big"); } </script> </head> <body> <div id="content"> <h1>Nifty Cube</h1> </div> </body> </html> Example 2: modx Simple Rounded Corner Box <html> <head> <title>Round Corner</title> <style type="text/css"> body { background: url(file:///C:/images/background.png) repeat-x; font-family: verdana,sans-serif; } /* set the image to use and establish the ...
Created by Dr. Xi on October 09, 2009 19:27:22
Last update: October 09, 2009 19:30:01
PL/SQL code from Pandazen : CREATE OR REPLACE FUNCTION GET_INSERT_SCRIPT(V_TABLE_NAME VARCHAR2) RETURN VARCHAR2 AS B_FOUND BOOLEAN := FALSE; V_TEMPA VARCHAR2 (8000); V_TEMPB VARCHAR2 (8000); V_TEMPC VARCHAR2 (255); BEGIN FOR TAB_REC IN (SELECT TABLE_NAME FROM ALL_TABLES WHERE TABLE_NAME = UPPER (V_TABLE_NAME)) LOOP B_FOUND := TRUE; V_TEMPA := 'select ''insert into ' || TAB_REC.TABLE_NAME || ' ('; FOR COL_REC IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = TAB_REC.TABLE_NAME ORDER BY COLUMN_ID) LOOP IF COL_REC.COLUMN_ID = 1 THEN V_TEMPA := V_TEMPA || '''||chr(10)||'''; ELSE V_TEMPA := V_TEMPA || ',''||chr(10)||'''; V_TEMPB := V_TEMPB || ',''||chr(10)||'''; END IF; V_TEMPA := V_TEMPA || COL_REC.COLUMN_NAME; IF INSTR (COL_REC.DATA_TYPE, 'CHAR') > 0 THEN V_TEMPC := '''''''''||' || COL_REC.COLUMN_NAME || '||'''''''''; ELSIF INSTR (COL_REC.DATA_TYPE, 'DATE') > 0 THEN V_TEMPC := '''to_date(''''''||to_char(' || COL_REC.COLUMN_NAME || ...
Created by Dr. Xi on October 09, 2009 03:39:22
Last update: October 09, 2009 19:25:50
Luhn algorithm in Python just for the heck of it. def doLuhn(s, evenPos): s = str(s) sum = 0 for d in reversed(s): d = int(d) assert 0 <= d <= 9 if evenPos: d *= 2 if d > 9: d = (d % 10) + 1 sum += d evenPos = not evenPos return sum def luhnValidation(n): return doLuhn(n, False) % 10 == 0 def generateCheckDigit(n): return 10 - (doLuhn(n, True) % 10) if __name__ == '__main__': import sys if len(sys.argv) < 2: print "%s <number> [g] " % sys.argv[0] sys.exit(1) elif len(sys.argv) == 2: n = sys.argv[1] if luhnValidation(n): print "%s is valid" % n else: print "%s is not valid" % n else: n = sys.argv[1] print "%s%s" % (n, generateCheckDigit(n))
Created by Dr. Xi on October 09, 2009 02:56:44
The Luhn algorithm is used to validate credit card numbers. This class provides two methods: one to validate that a number passes the Luhn algorithm validation, the other to generate a check digit that makes a number pass the Luhn validation. public class Luhn { public static void main(String[] args) { if (args.length < 1) { System.err.println("Usage: number [g] "); System.exit(1); } String n = args[0]; if (args.length == 2) { System.out.println(n + generateDigit(n)); } else if (isValidNumber(n)) { System.out.println(n + " is valid"); } else { System.out.println(n + " is NOT valid"); } } private static boolean isValidNumber(String s) { return doLuhn(s, false) % 10 == 0; } private static String generateDigit(String s) { int digit = 10 - doLuhn(s, true) % 10; return ...
Created by voodoo on October 03, 2009 21:34:35
Last update: October 03, 2009 21:34:56
One liners: Oldest find . -printf "%T@ %Tx %TX %p\n" | sort -n | head | cut -d ' ' -f 2- Newest find . -printf "%T@ %Tx %TX %p\n" | sort -n -r | head | cut -d ' ' -f 2- Shell scripts: Oldest #!/bin/ksh touch -t $(($(date "+%Y") + 1))$(date "+%m%d%H%M") compareTo OLDEST=compareTo find . -type f | while read f; do [[ $f -ot $OLDEST ]] && OLDEST=$f done echo oldest file: $OLDEST rm compareTo Newest #!/bin/ksh touch -t 197001010000 compareTo NEWEST=compareTo find . -type f | while read f; do [[ $f -nt $NEWEST ]] && NEWEST=$f done echo newest file: $NEWEST rm compareTo
Created by James on September 23, 2009 03:56:46
This trick came from quirksmode . With this CSS: div.container { border: 1px solid #000000; } div.left { width: 45%; float: left; } div.right { width: 45%; float: right; } the container DIV height remains 0 no matter how tall the contained floats are. Two tricks were offered: Add a DIV after the two floats with clear:both Change the container CSS to: div.container { border: 1px solid #000000; overflow: auto; /* hidden and scroll also works */ width: 100% }
Created by Dr. Xi on September 20, 2009 16:52:19
Last update: September 20, 2009 16:56:48
When I assemble a session bean without the proprietary deployment descriptor ( orion-ejb-jar.xml ), OC4J generates one like this (as can be seen from the OC4J management console): <?xml version="1.0" encoding="utf-8"?> <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="10.1.3.3.0" deployment-time="123d598f9ca" schema-major-version="10" schema-minor-version="0" > <enterprise-beans> <session-deployment name="SimpleBean" location="SimpleBean" local-location="simpleEjb_SimpleBeanLocal" persistence-filename="SimpleBean.test_default_group_1"> </session-deployment> </enterprise-beans> <assembly-descriptor> <default-method-access> <security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" /> </default-method-access> </assembly-descriptor> </orion-ejb-jar> So I use this code to lookup the EJB: import javax.naming.Context; import javax.naming.InitialContext; . . . Context ctx = new InitialContext(); Simple s = (Simple) ctx.lookup("simpleEjb_SimpleBeanLocal"); OC4J throws ClassCastException : java.lang.ClassCastException: com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.ejb.StatelessSessionDefaultLocalHomeImpl The JNDI browser (OC4J container home -> Administration -> JNDI browser) shows that the name simpleEjb_SimpleBeanLocal is bound to: com.evermind.server.ejb.StatelessSessionDefaultLocalHomeImpl Solution: Change the local name in the OC4J generated orion-ejb-jar.xml to ...
Created by Fang on September 19, 2009 21:16:52
Last update: March 02, 2010 05:13:04
Before you can build a Java EE project with Maven, you need to add the Java EE dependencies. And you need to tell Maven where to find the repositories for the Java EE artifacts. For JDK 5 & Java EE 5: ~/.m2/settings.xml : <?xml version="1.0" encoding="UTF-8"?> <settings> <profiles> <profile> <id>DefaultProfile</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> </repository> </repositories> </profile> </profiles> </settings> pom.xml : <dependencies> <dependency> <groupId>javaee</groupId> <artifactId>javaee-api</artifactId> <version>5</version> <scope>provided</scope> </dependency> </dependencies> For JDK 6 & Java EE 6: ~/.m2/settings.xml : <?xml version="1.0" encoding="UTF-8"?> <settings> <profiles> <profile> <id>DefaultProfile</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> </repository> </repositories> </profile> </profiles> </settings> pom.xml : <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0-SNAPSHOT</version> <scope>provided</scope> </dependency> </dependencies>