Recent Notes
Displaying notes 61 - 70
Created by Dr. Xi on January 07, 2010 23:47:36
This is a utility to generate a "create role" script for Oracle for an existing schema. import java.io.*; import java.sql.*; public class GenerateRoleScript { private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; private static final String JDBC_URL = "jdbc:oracle:thin:@10.200.100.80:1521:MY_SCHEMA"; private static final String JDBC_USER = "MY_SCHEMA"; private static final String JDBC_PASSWD = "MY_PASSWORD"; public static void main(String[] args) throws Exception { if (args.length < 1) { usage(); System.exit(1); } String roleName = args[0]; Class.forName(JDBC_DRIVER); Connection conn = null; try { conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWD); generateRoleScript(conn, roleName); } finally { if (conn != null) conn.close(); } } private static void generateRoleScript(Connection conn, String roleName) throws Exception { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT " + "owner, " + "table_name, " + "privilege, " ...
Created by Dr. Xi on January 07, 2010 23:40:28
Last update: February 09, 2010 03:24:35
This is a utility to generate SQL insert statements for Oracle for one table, or a set of tables. It doesn't cover all possibilities but should be good enough for most cases. import java.io.*; import java.sql.*; import java.text.SimpleDateFormat; public class GenerateInsertStatements { private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; private static final String JDBC_URL = "jdbc:oracle:thin:@10.200.100.80:1521:MY_SID"; private static String JDBC_USER = "MY_SCHEMA"; private static String JDBC_PASSWD = "THE_PASSWORD"; private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); public static void main(String[] args) throws Exception { if (args.length < 1) { usage(); System.exit(1); } int i = 0; String tableName = args [i] ; String fileName = null; if (tableName.contains("/")) { // username/password provided String[] uid_pass = args[0].split("/"); if ((uid_pass.length != 2) || (args.length < 2)) ...
Created by Fang on January 07, 2010 23:20:45
Last update: January 07, 2010 23:23:16
I got this error executing maven: Failure executing javac, but could not parse the error: The system is out of resources. Consult the following stack trace for details. java.lang.OutOfMemoryError: Java heap space The solution is to increase the heap size with MAVEN_OPTS: MAVEN_OPTS=-Xmx512m -Xms512m mvn package
Created by Dr. Xi on January 07, 2010 22:56:20
Last update: January 25, 2010 16:27:45
If the error reads: java.lang.LinkageError: Class javax/xml/rpc/encoding/TypeMappingRegistry violates loader constraints then the class javax.xml.rpc.encoding. TypeMappingRegistry is loaded by two or more different class loaders, and the versions are not compatible. For example, one might be under WEB-INF/lib, another might be loaded through an EJB. The solution is to get rid of the duplicate versions .
Created by Dr. Xi on January 07, 2010 20:02:00
Last update: January 07, 2010 20:07:19
If all you want is a quick way to format some numbers, a sample program speaks more words than the full documentation. import java.text.DecimalFormat; public class TestNumberFormat { public static void main(String[] args) throws Exception { double[] n = { 1, 12.0, 123.9, 123.456, 123E5, 123E-5 }; // 0 represents 1 digit DecimalFormat f = new DecimalFormat("00.00"); System.out.println("Formatting with 0.00"); for (int i = 0; i < n.length; i++) { System.out.println(n [i] + ": " + f.format(n [i] )); } // # is one digit, but can be omitted if it is 0 f = new DecimalFormat("#0.0#"); System.out.println("\nFormatting with #0.0#"); for (int i = 0; i < n.length; i++) { System.out.println(n [i] + ": " + f.format(n [i] )); } // prefixes and suffixes can ...
Created by Dr. Xi on January 04, 2010 05:04:10
Last update: January 07, 2010 15:59:25
This is the error: >>> import urllib2 >>> f = urllib2.urlopen('https://www.google.com') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 121, in urlopen return _opener.open(url, data) File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 374, in open response = self._open(req, data) File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 397, in _open 'unknown_open', req) File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 353, in _call_chain result = func(*args) File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 1134, in unknown_open raise URLError('unknown url type: %s' % type) urllib2.URLError: <urlopen error unknown url type: https> >>> Reason: SSL is not supported in Python installation. >>> import httplib >>> hasattr(httplib, 'HTTPS') False >>> import socket >>> hasattr(socket, 'ssl') False >>> import _ssl Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named _ssl Solution: recompile Python with SSL ...
Created by Dr. Xi on January 02, 2010 16:37:13
Last update: January 02, 2010 16:37:57
Use the del operator to delete one key, or clear method to delete all keys: >>> d = { 'a': 1, 'b': 2, 'c' : 3 } >>> del d['f'] Traceback (most recent call last): File "<stdin>", line 1, in ? KeyError: 'f' >>> del d['a'] >>> d {'c': 3, 'b': 2} >>> d.clear() >>> d {} >>>
Created by woolf on January 01, 2010 03:59:28
Last update: January 01, 2010 04:03:33
With mencoder: mplayer -dumpaudio nodame_theme.flv -dumpfile nodame_theme.mp3 With ffmpeg: ffmpeg -i nodame_theme.flv -ab 128 -ar 44100 nodame_theme.mp3
Created by woolf on December 28, 2009 00:11:20
Last update: January 15, 2010 04:01:46
From http://www.videohelp.com/tools/MJPEG_Tools : A sample command line to deinterlace dv footage, give a slight film look, pass it through a Spatial-Pre-Filter, Temporal-Noise-Filter, and a Spatial-Post-Filter, then encode to DVD complient mpeg2 video looks like this - lav2yuv capture.dv | yuvdeinterlace -f | yuvdenoise -G 1,2,2 | mpeg2enc -f 8 -b 6000 -q 2 -o out.m2v From http://www.linux.com/archive/feature/40069 , the actual video file can be used in place of edit list (eli) file: # de-noice the video and scale for DVD output lav2yuv myvideo.eli | yuvdenoise | yuvscaler -O DVD | ... # add another filter lav2yuv myvideo.eli | yuvdenoise | yuvscaler -O DVD | yuvmedianfilter -T 3 | ... # pipe the output to yuvplay lav2yuv myvideo.eli | yuvdenoise | yuvscaler -O DVD | yuvmedianfilter ...
Created by Dr. Xi on December 25, 2009 03:23:36
Last update: December 25, 2009 03:23:51
Suppose User is the model class, this is the code to catch DoesNotExist : >>> try: ... u = User.objects.get(name='Django Reinhardt') ... except User.DoesNotExist: ... print 'Not found!' ... Not found! >>>