Bootstrap 3简单实现Dropdown on Hover — 2014-11-03
配置Tomcat支持远程调试 — 2014-10-30
Java压缩解压工具类 — 2014-10-11

Java压缩解压工具类

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream;

import java.io.*;
import java.util.Enumeration;

/**
 * 解压压缩工具类
 * Created by fangshuai on 2014-09-12-0012.
 */
public class ZipUtils {
    public static final String ENCODING_DEFAULT = "UTF-8";

    public static final int BUFFER_SIZE_DIFAULT = 128;

    public static void makeZip(String[] inFilePaths, String zipPath)
            throws Exception {
        makeZip(inFilePaths, zipPath, ENCODING_DEFAULT);
    }

    public static void makeZip(String[] inFilePaths, String zipPath,
                               String encoding) throws Exception {
        File[] inFiles = new File[inFilePaths.length];
        for (int i = 0; i < inFilePaths.length; i++) {
            inFiles[i] = new File(inFilePaths[i]);
        }
        makeZip(inFiles, zipPath, encoding);
    }

    public static void makeZip(File[] inFiles, String zipPath) throws Exception {
        makeZip(inFiles, zipPath, ENCODING_DEFAULT);
    }

    public static void makeZip(File[] inFiles, String zipPath, String encoding)
            throws Exception {
        ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipPath)));
        zipOut.setEncoding(encoding);
        for (int i = 0; i < inFiles.length; i++) {
            File file = inFiles[i];
            doZipFile(zipOut, file, file.getParent());
        }
        zipOut.flush();
        zipOut.close();
    }

    private static void doZipFile(ZipOutputStream zipOut, File file,
                                  String dirPath) throws IOException {
        if (file.isFile()) {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
            String zipName = file.getPath().substring(dirPath.length());
            while (zipName.charAt(0) == '\' || zipName.charAt(0) == '/') {
                zipName = zipName.substring(1);
            }
            ZipEntry entry = new ZipEntry(zipName);
            zipOut.putNextEntry(entry);
            byte[] buff = new byte[BUFFER_SIZE_DIFAULT];
            int size;
            while ((size = bis.read(buff, 0, buff.length)) != -1) {
                zipOut.write(buff, 0, size);
            }
            zipOut.closeEntry();
            bis.close();
        } else {
            File[] subFiles = file.listFiles();
            for (File subFile : subFiles) {
                doZipFile(zipOut, subFile, dirPath);
            }
        }
    }

    public static void unZip(String zipFilePath, String storePath) throws IOException {
        unZip(new File(zipFilePath), storePath);
    }

    public static void unZip(File zipFile, String storePath) throws IOException {
        if (!new File(storePath).exists()) {
            new File(storePath).mkdirs();
        }

        ZipFile zip = new ZipFile(zipFile);
        Enumeration<ZipEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            if (zipEntry.isDirectory()) {
                // TODO
            } else {
                String zipEntryName = zipEntry.getName();
                if (zipEntryName.indexOf(File.separator) > 0) {
                    String zipEntryDir = zipEntryName.substring(0, zipEntryName.lastIndexOf(File.separator) + 1);
                    String unzipFileDir = storePath + File.separator + zipEntryDir;
                    File unzipFileDirFile = new File(unzipFileDir);
                    if (!unzipFileDirFile.exists()) {
                        unzipFileDirFile.mkdirs();
                    }
                }

                InputStream is = zip.getInputStream(zipEntry);
                File entryFile = new File(storePath + File.separator + zipEntryName);
                if(!entryFile.getParentFile().exists())
                    entryFile.getParentFile().mkdirs();
                FileOutputStream fos = new FileOutputStream(entryFile);
                byte[] buff = new byte[BUFFER_SIZE_DIFAULT];
                int size;
                while ((size = is.read(buff)) > 0) {
                    fos.write(buff, 0, size);
                }
                fos.flush();
                fos.close();
                is.close();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        String rootDir = "D:\SWFTools";
        String zipPath = "D:\SWFTools.zip";
        //makeZip(new String[]{rootDir}, zipPath);
        unZip(zipPath, "D:\temp");
    }
}
Balsamiq Mockups注册码 — 2014-09-25

Balsamiq Mockups注册码

Mockups之小巧、强悍,会用的人都知道~~~~
这玩意是ADOBE AIR格式,所以需要先安装air,好处是adobeair能安装到哪,你就能在哪使用。
下载地址:mockups

首先还是希望大家多多支持正版!序列号仅供参考,切勿用于商业,一切后果与本人无关!

Name: personal

Key: eJzzzU/OLi0odswsqilILSrOz0vMqbFEAjXONYY1fu6ufgA/CA4X
Name: helloWorld
Key: eJzzzU/OLi0odswsqslIzcnJD88vykmpsUQCNc41hjV+7q5+AF74Ds8=
Name: china
Key: eJzzzU/OLi0odswsqknOyMxLrLFEAjXONYY1fu6ufgAJ5gy2
Name: ketty
Key: eJzzzU/OLi0odswsqslOLSmprLFEAjXONYY1fu6ufgAOOwzk
Visual Studio2013激活码一枚 — 2014-09-22
Ubuntu 14.04 下的MAC OS X 主题安装 — 2014-09-20
Sublime Text 设置不记住打开的文件 —
npm设置淘宝镜像 — 2014-08-31

npm设置淘宝镜像

淘宝npm镜像是国内最大的,访问速度快的npm镜像,设置方法如下:

  1. 打开.npmrc文件(在用户主目录下)
  2. 加入以下配置信息:

registry = http://registry.npm.taobao.org

搞定!

解决Shiro注解无效的问题 — 2014-08-30

解决Shiro注解无效的问题

当Shiro集成到Spring mvc中,却发现shiro的权限注解不起作用,官方的配置是要支持注解,只需要将以下代码加到spring 配置文件中即可:

    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
        <property name="proxyTargetClass" value="true" />
    </bean>

    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager"/>
    </bean>

后来研究发现,不起作用是因为代码放的位置不对,需要将上面代码放到视图的配置文件中,如:spring-mvc.xml

解决windows下通过ssh-keygen产生的密钥无法连接github的问题 — 2014-08-29

解决windows下通过ssh-keygen产生的密钥无法连接github的问题

windows下安装Git Extensions后,打开gitbash可以通过ssh-keygen生成密钥,导入github就可以连接。具体方法如:

http://wincn.net/2013/08/git%E8%BF%9E%E6%8E%A5github%E5%AE%8C%E6%95%B4%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95/

这个方法在Linux上是没问题的,但是在windows上却老是无法连通github返回错误信息如下:


通过以下命令测试:

ssh -vT git@github.com

输出结果为:

注意标红的部分。ssh回去用户目录下的.ssh文件夹下找私钥:id_rsa或id_dsa。现在问题找到了,是生成密钥的时候必须固定名字:

ssh-keygen -C "gefangshuai@163.com" -f ~/.ssh/id_rsa

这样就可能正常连接github了!