Skip to content

Instantly share code, notes, and snippets.

@alexzhan
alexzhan / YangInitial1.java
Created November 6, 2010 09:33
more precise version of web page url lister with some bugs
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
@alexzhan
alexzhan / likesearch
Created November 10, 2010 00:07
getHibernate find like search
Object[] objs = new Object[]{"%" + keyword.toLowerCase() + "%", category, region};
List<SnVideo> snVideos = videoDAO.getHibernateTemplate().find(" from SnVideo where lower(name) LIKE ? and lower(category)= ? and lower(region)= ?",objs);
@alexzhan
alexzhan / likesearch by template
Created November 10, 2010 00:33
findbyname lowersearch search likesearch like hibernate
public List findByName(String name) {
String query = "from SnVideo s where lower(s.name) like :name";
return getHibernateTemplate().findByNamedParam(query, "name", "%" + name.toLowerCase() + "%");
}
@alexzhan
alexzhan / InfoUpdate.java
Created November 14, 2010 12:42
update some fields of one database of mysql using the contents of some other fields by selecting the same database
import java.util.Date;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class InfoUpdate {
private static String url = "jdbc:mysql://localhost:3306/Yourdatabase";
@alexzhan
alexzhan / FashionGenerate.java
Created November 15, 2010 00:43
To Generate the count of special values with category from one field in one table of mysql
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class FashionGenerate {
private static String url = "jdbc:mysql://localhost:3306/Database";
private static String user = "UserName";
@alexzhan
alexzhan / FashionCount.java
Created November 15, 2010 00:44
To Generate the count of special values without category from one field in one table of mysql
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class FashionCount {
private static String url = "jdbc:mysql://localhost:3306/ItemsInfo2";
private static String user = "root";
@alexzhan
alexzhan / Number of files in directory
Created November 15, 2010 05:37
Number of files in directory
# the number of files and directories in a directory
ls | wc -l
# A directory is a file but its not a regular file, so the question is not clear enough
# If he does not want directory, then something awfull like this should do:
echo $(($(ls -l | grep -v ^d | wc -l)-1))
ls *.jpg | wc
ls *.jpg | wc -l
ls -l | grep ^- | wc
ls -l | grep ^- | wc -l
@alexzhan
alexzhan / find and delete command
Created November 15, 2010 06:52
linux find command
find command:http://www.oreillynet.com/linux/cmd/cmd.csp?path=f/find
find . -maxdepth 1/2/..../n
%to just find them and printout:
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n'
%delete them, may be modified to use
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n' | xargs rm
http://content.hccfl.edu/pollock/unix/findcmd.htm
@alexzhan
alexzhan / TestFileCharSet.java
Created November 22, 2010 13:34
To change the charset of one file name
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
//import org.apache.commons.io.FileUtils;
public class TestFileCharSet {
protected static String urlEncode(String string) {
try {
@alexzhan
alexzhan / add auto_increment id set primary
Created November 28, 2010 13:41
add auto_increment id set primary
对于item_detail:
先用
alter table item_detail drop primary key;
删除原来的主键;
然后用:
alter table item_detail add column id int unsigned not null auto_increment primary key;
增加自增的主键id