Memo: complie tex with texstudio

March 17th, 2015 by xrigher No comments »

In texstudio, the right procedures to compile your document do this steps:

  1. compile ‘main.tex’ using latex or pdflatex
  2. compile ‘main.tex’ (NOT ‘ref.bib’) using bibtex => this step will generate main.aux file
  3. compile twice ‘main.tex’ using latex or pdflatex

Otherwise, you may find your bib list not updated or get errors like:

I couldn’t open file name `bibi.aux’

Source: http://tex.stackexchange.com/questions/166831/cant-open-reference-aux

Memo: log4j in tomcat (备忘:Tomcat中配置log4j)

March 9th, 2015 by xrigher 1 comment »

In a tomcat project, we can configure log4j to write logs in a file with:
log4j.appender.rollingFile.File=${catalina.home}/logs/services.log.
This will put all the log files in the /log dir under tomcat root dir.

Here is a full version of the sample log4j.properties.

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# log message format: 10:48:40,399 INFO Test:36 - [3, 2, 1]
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct log messages to file ###
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=${catalina.home}/logs/services.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=5
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
# log message format: INFO main wp.newsbag.Test - message ...
#log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.rollingFile.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %5p %c:%L - %m%n
log4j.logger.wp.newsbag=ERROR
#log4j.rootLogger=debug, stdout
log4j.rootLogger=debug, rollingFile

Location of tomcat work dir in eclipse (Eclipse中tomcat工作目录)

March 9th, 2015 by xrigher No comments »

The default dir for eclipse to publish we apps in tomcat is WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmpX, where X could be 0, 1, 2, depending on how servers you have configured. Of course, the dir can be changed as shown in the Server project, as shown in the pic below:

Configure work dir for tomcat in Eclipse

————————–

备忘:Eclipse中tomcat的默认工作目录为:WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmpX,X可能为0,1,2….。当然,这个目录可以在Server Project中修改,如上图所示。

Configure an Oracle Database Connection for Remote Access

January 13th, 2015 by xrigher No comments »

Two key points to configure oracle for remote access:

  1. use your remote IP address in tnsnames.ora. see: http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vsphere.install.doc%2FGUID-25AD990F-3E1C-4F34-84E1-C0B311F80808.html
  2. Allow remote access through firewall.

Android修改Hosts以便测试微信应用

December 27th, 2014 by xrigher 1 comment »

微信公众帐号应用需要在公众帐号的后台设置网站应用,设置的地址往往都是真实域名。这带来一个问题,我们修改调试都需要将代码push到生产环境,遇到bug,又要在本地修复,然后再push到线上。如此反复,效率低下。最好的办法就是将设置的域名在Android测试机上的hosts中的ip改为我们的开发机ip。那么问题来了,如何在android中修改hosts文件:
1. 将机器ROOT,本人使用的测试机小米3,MIUI6,没法直接使用系统设置和应用进行设置,需要使用360ROOT进行。
2. 安装ROOT Explorer(RE),使用读写模式加载文件系统。进入/system/etc/目录。
3. 打开编辑hosts文件,注意换行必须是\n。还有最后一定要空一行,否则hosts将无效
4. 重启系统。
#DONE

当然还有另外一种方式使用adb终端或者adb shell命令行方式直接修改hosts文件。
adb终端推荐使用超级终端专业版,安装可参考:http://www.tttabc.com/android/Android-Shell.html. Adb操作hosts可参考:Android下修改hosts文件-重启有效

maven and nexus

September 28th, 2014 by xrigher No comments »

maven仓库快速镜像

国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用。
====================国内OSChina提供的镜像,非常不错===================
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
========================================================

maven中央仓库在国内经常不能正常访问,怎么办?

maven中央仓库在国内经常不能正常访问,具体表现为连接超时,不能下载资源等,那是因为咱们国家的伟大防火墙在起作用。怎么办呢?在pom.xml文件中添加可用的镜像来保证maven依赖包的正常下载。例如下面的就是一个可以用的镜像,如何这个也过期了,可以到网上再去找到其他一些镜像地址。
<mirrors>
<mirror>
<id>ibiblio.org</id>
<name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
<mirrorOf>central</mirrorOf>
<!– United States, North Carolina –>
</mirror>
<mirror>
<id>cica.es</id>
<url>http://ftp.cica.es/mirrors/maven2</url>
<mirrorOf>central</mirrorOf>
<!– Spain, Sevilla –>
</mirror>
</mirrors>

maven 建立本地仓库

ubuntu下将sonatype nexus设置为系统服务

你打开eclipse的 preferences -> maven -> User Settings 你就可以看到你的setting.xml文件的地址了。
然后将setting.xml文件打开。修改里面的mirror节点 。url指向远程仓库的地址。 这样设置之后你的所有项目都有作用。
<mirror>
<id>central_mirror</id>
<name>internal central_mirror epository</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>

如果不修改setting.xml ,也可以在你项目的pom.xml上加入
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<name>central</name>
</repository>
</repositories>
对当前的项目有效。

【转载】64位win7 plsql连接oracle找不到oci.dll及乱码

August 30th, 2014 by xrigher No comments »

转自:http://blog.csdn.net/tkts/article/details/8757093

连Oracle数据库Could not load “……\bin\oci.dll”
这个问题产生的原因是plsql对64位oracle客户端支持的不好, 在查找oci.dll时出错, 手动指定个可用的oci.dll即可。
1、下载Oracle InstantClient(下载地址:http://download.csdn.net/detail/tkts/5217879),我的数据库安装的是11.2.0.1.0,所以下载的InstantClient也是11.2.0.1.0版本的。将下载的文件解压到oracle的安装目录E:\oracle\product中,并将该目录加入到系统的环境变量path中。

2、打开plsql,取消登录,在程序的首选项中找到connection设置,设置ORACLE_HOME和OCI_LIBRARY,ORACLE_HOME设置为E:\oracle\product\instantclient_11_2,OCI_LIBRARY设置为instantclient目录下的oci.dll文件。关闭plsql。

3、在环境变量中增加一项:TNS_ADMIN=E:\oracle\product\11.2.0\client_2\network\admin

4、重新打开PLSQL,能在Database中显示之前配置的Oracle服务名,则可以正常使用plsql。

乱码解决办法:

在plsqldev.exe同级目录新建start.bat, 添加如下内容:

[plain] view plaincopy
rem 解决64位下plsql乱码问题
set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
start plsqldev.exe

启动此批处理文件即可。

另外批处理中start和call的一点区别:

start启动完程序后控制台窗口退出, call调用完程序后控制台窗口不退出。

Eclipse连接小米3进行Android App真机测试

May 12th, 2014 by xrigher No comments »

首先需要打开开发者模式,设置->全部设置->关于手机->连续点击Android版本4下。然后就可以在设置的倒数第二项找到“开发者选项”了。

进入设置->全部设置->开发者选项,开启“开发者选项”和“UBS调试”,取消“验证UBS APP”。

进入设置->安全,开启“未知源”APP安装。

进入拨号界面,输入*#*#717717#*#*,开启Diag USB port。

然后将手机通过USB连接电脑,在Eclipse中运行测试程序,应该就会弹出选择运行目标的选项,选择小米手机,使用真机进行测试。

参考了http://blog.csdn.net/lijihhhh/article/details/17380343,但不确定*#*#717717#*#*是否真正有关键作用,可以确定的是,输入*#*#717717#*#*无需ROOT权限。
参考了http://www.haogongju.net/art/2508327, 但第1步和第4步不是必须。
对以上两篇文章的作者表示真心感谢!

Create keyboard shortcut for console application with hidden form (c#)

April 18th, 2014 by xrigher No comments »

Here is good example from stackoverflow: http://stackoverflow.com/questions/3654787/global-hotkey-in-console-application。 It works like a charm!

Here I paste the code for your convenience (I don’t own the copyright).
The helper class for hotkey registry

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

  public class HotKeyManager
  {
    public static event EventHandler HotKeyPressed;

    public static int RegisterHotKey(Keys key, KeyModifiers modifiers)
    {
      int id = System.Threading.Interlocked.Increment(ref _id);
      RegisterHotKey(_wnd.Handle, id, (uint)modifiers, (uint)key);
      return id;
    }

    public static bool UnregisterHotKey(int id)
    {
      return UnregisterHotKey(_wnd.Handle, id);
    }

    protected static void OnHotKeyPressed(HotKeyEventArgs e)
    {
      if (HotKeyManager.HotKeyPressed != null)
      {
        HotKeyManager.HotKeyPressed(null, e);
      }
    }

    private static MessageWindow _wnd = new MessageWindow();

    private class MessageWindow : Form
    {
      protected override void WndProc(ref Message m)
      {
        if (m.Msg == WM_HOTKEY)
        {
          HotKeyEventArgs e = new HotKeyEventArgs(m.LParam);
          HotKeyManager.OnHotKeyPressed(e);
        }

        base.WndProc(ref m);
      }

      private const int WM_HOTKEY = 0x312;
    }

    [DllImport("user32")]
    private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

    [DllImport("user32")]
    private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

    private static int _id = 0;
  }


  public class HotKeyEventArgs : EventArgs
  {
    public readonly Keys Key;
    public readonly KeyModifiers Modifiers;

    public HotKeyEventArgs(Keys key, KeyModifiers modifiers)
    {
      this.Key = key;
      this.Modifiers = modifiers;
    }

    public HotKeyEventArgs(IntPtr hotKeyParam)
    {
      uint param = (uint)hotKeyParam.ToInt64();
      Key = (Keys)((param & 0xffff0000) >> 16);
      Modifiers = (KeyModifiers)(param & 0x0000ffff);
    }
  }

  [Flags]
  public enum KeyModifiers
  {
    Alt = 1,
    Control = 2,
    Shift = 4,
    Windows = 8,
    NoRepeat = 0x4000
  }

Example of using the helper class


using System;
using System.Windows.Forms;

namespace ConsoleHotKey
{
  class Program
  {
    static void Main(string[] args)
    {
      HotKeyManager.RegisterHotKey(Keys.A, KeyModifiers.Alt);
      HotKeyManager.HotKeyPressed += new EventHandler(HotKeyManager_HotKeyPressed);
      Console.ReadLine();      
    }

    static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
    {
      Console.WriteLine("Hit me!");
    }
  }
}

Java socket connection timout

March 13th, 2014 by xrigher No comments »

There are 2 places to set the timeout option of a socket, at connection and at reading.

  • Socket.connect(SocketAddress endpoint, int timeout) connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs. Here the timeout setting only affects the action of connecting!
  • Socket.setSoTimeout(int timeout) enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.