Java Cons class
public class Cons<T,U> { private T car; private U cdr; public Cons( T carArg, U cdrArg ) { car = carArg; cdr = cdrArg; } public T getCar(){ return car; } public U getCdr(){ return cdr; } }
11348 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
public class Cons<T,U> { private T car; private U cdr; public Cons( T carArg, U cdrArg ) { car = carArg; cdr = cdrArg; } public T getCar(){ return car; } public U getCdr(){ return cdr; } }
String s; int width, height; Graphics g; FontMetrics fm = getFontMetrics(ftDefault); Rectangle2D textsize = fm.getStringBounds(s, g); int xPos = (width - textsize.getWidth()) / 2; int yPos = (height - textsize.getHeight()) / 2 + fm.getAscent(); g.drawString(s, xPos, yPos);
// generate a key -- make it long lived so we dont have to do this again keytool -genkey -alias tomcat -keyalg RSA -validity 3650 -storepass changeit // export cert to a file keytool -export -rfc -v -file tomcatCert.crt -alias tomcat -storepass changeit // look at the cert in the file keytool -printcert -file tomcatCert.crt -storepass changeit // delete pre-existing cert keytool -delete -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit // import cert into a keystore keytool -import -file tomcatCert.crt -trustcacerts -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit // look at the imported cert keytool -list -alias tomcat -keystore c:/apps/jdk/jre/lib/security/cacerts -storepass changeit
ArrayList<Object> list = new ArrayList<Object>();
String myParameter = context.getExternalContext().getRequestParameterMap().get("myParameterPath");
<form:select path="myParameterPath" id="myParameterId"> ... </form:select>
<select name="myParameterPath" id="myParameterId"> ... </select>
Elephant elephant = ...; // get the elephant from somewhere while (!elephant.isEatenCompletely()) { elephant.haveOneBite(); }
private static Date cvtToGmt( Date date ) { TimeZone tz = TimeZone.getDefault(); Date ret = new Date( date.getTime() - tz.getRawOffset() ); // if we are now in DST, back off by the delta. Note that we are checking the GMT date, this is the KEY. if ( tz.inDaylightTime( ret )) { Date dstDate = new Date( ret.getTime() - tz.getDSTSavings() ); // check to make sure we have not crossed back into standard time // this happens when we are on the cusp of DST (7pm the day before the change for PDT) if ( tz.inDaylightTime( dstDate )) { ret = dstDate; } } return ret; }
// insert code here..
python AddLicense.py ${path} where ${path} defines user project root directory.1:# Python script to add the LGPL notices to each java file of the FileContentManager project. 2:import os, glob, sys 3:License = """\ 4:/** 5:*FileContentManager is a Java based file manager desktop application, 6:*it can show, edit and manipulate the content of the files archived inside a zip. 7:* 8:*Copyright (C) 2008 9:* 10:*Created by Camila Sanchez [http://mimix.wordpress.com/], Rafael Naufal [http://rnaufal.livejournal.com] 11:and Rodrigo [rdomartins@gmail.com] 12:* 13:*FileContentManager is free software; you can redistribute it and/or 14:*modify it under the terms of the GNU Lesser General Public 15:*License as published by the Free Software Foundation; either 16:*version 2.1 of the License, or (at your option) any later version. 17:* 18:*This library is distributed in the hope that it will be useful, 19:*but WITHOUT ANY WARRANTY; without even the implied warranty of 20:*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21:*Lesser General Public License for more details. 22:* 23:*You should have received a copy of the GNU Lesser General Public 24:*License along with FileContentManager; if not, write to the Free Software 25:*Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ 26: 27:size = len(sys.argv) 28:if size == 1 or size > 2: 29: print "Usage: AddLicense.py $1" 30: sys.exit(1) 31:inputPath = sys.argv[1] 32:if not os.path.exists(inputPath): 33: print inputPath, "does not exist on disk" 34: sys.exit(1) 35:if not os.path.isdir(inputPath): 36: print inputPath, "isn't a dir" 37: sys.exit(1) 38:for path, dirs, files in os.walk(inputPath): 39: fileWithLicense = '' 40: for filepath in [ os.path.join(path, f) 41: for f in files if f.endswith(".java")]: 42: content = file(filepath).read() 43: f = file(filepath, "w") 44: print >>f, License + "\n" + content 45: f.close() 46: 47:
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"> <etl> <connection id="db" driver="auto" url="jdbc:hsqldb:mem:tst" user="sa" password="" classpath="../lib/hsqldb.jar"/> <connection id="js" driver="script"/> <connection id="log" driver="text"/> <!-- For printing debug information on the console --> <script connection-id="db"> CREATE TABLE Table_In ( Error_Code INT ); CREATE TABLE Table_Out ( Error VARCHAR(10) ); INSERT INTO Table_IN VALUES (1); INSERT INTO Table_IN VALUES (7); </script> <query connection-id="db"> SELECT * FROM Table_In <script connection-id="log"> Transforming $Error_Code </script> <!-- Transformation is described as an enclosing query which is executed before nested elements --> <query connection-id="js"> <![CDATA[ if (Error_Code < 5) { Error_Code='WARNING'; //Set a transformed value } else { Error_Code='ERROR'; //Set a transformed value } query.next(); //Don't forget to trigger nested scripts execution ]]> <script connection-id="db"> <!-- Insert transformed value --> INSERT INTO Table_Out VALUES (?Error_Code); </script> <script connection-id="log"> Transformed to $Error_Code </script> </query> </query> </etl>