你在业余时间都开发过什么?

这多年来,我面试过很多程序员。最近,我在思考一个事情,究竟通过一个什么样的问题能够最大的获取一个人对于编程的能力和热忱的信息。

我总结出来,只有这个问题具有最强的钻透力:

你在业余时间都开发过什么?

我喜欢这个问题,因为它一次触及到了很多方面。业余时间是一种很宝贵的资源,你通常会把它用到你最感兴趣的事情上。如果把这种资源用于开发,这是一个 很强的信号,说明你热心于此。另一方面,如果得到的回复是“啊?”或“在业余时间?”,这也许能很好的提示你,他可能不是你要找的人。

而他们所做的是些什么事情,也是一个有趣的指示器。他们是否对开源项目捐赠过代码?是否有过把一种工具移植到一种新语言上?利用一些新科技开发出一些很酷的工具?根据他们开发的东西以及开发的原因,你能真正的洞悉他们的思想动机和挑战精神。

这个问题同样能让你了解到他们保持技术更新和自学的能力。如此多的新技术和新思想不断的产生,要想不落伍需要付出努力。你几乎不可能在“工作时间”做这种事情。

这就是我为什么喜欢这个问题、所有面试都要提出这个问题的原因。

你最喜欢的问题是什么?

更新:

非常感谢你们对这个特殊的话题的各种反应和观点。我完全没有想通过这么一个问题就简单的对应聘者进行分类的意思,这只是在我依据个人经验得出的一个小 小的观点。我主要想表达的是,我想弄清一个人究竟对什么感兴趣。如果有人说“一天的工作后,为什么我还要在家工作呢?”,我完全赞同!但这种事情不应该被 看成是“工作”。

也许,或者你应该偶然在家做的事情。我平均每周会用2-3小时在家去实现我的一些想法,或测试某些新技术,或只是读一本好书。这很难说无法做到。

而且,我认为,随着时间的积累,这越发显得重要。当你在某个领域积累了很深的知识和经验,这会成为你观察问题的多棱镜。扩展知识面会让你在新项目上产生有创意(甚至令人惊讶)的想法,对过去棘手的问题产生新思路,或带来很多个人乐趣。

关键就是对编程的一种渴望,如果不敲键盘,手会痒痒。

原文:Matan Amir
译文:外刊IT评论

resin 4 版破解方法。

how to crack resin 4.

工具:jd http://java.decompiler.free.fr/

利用jd打开resin 4目录下的lib/pro.jar

将源代码另存出来。再用eclipse打开LicenseStore.java

查找init()函数,将init()函数中的

/*  69 */     this._personalCount;

/*  70 */     this._professionalCount;

改为

/*  69 */     this._personalCount = 100;

/*  70 */     this._professionalCount = 100;

 

然后编译为class文件,用winrar将class文件加入到lib/pro.jar,覆盖原来的文件。

即可。

验证:运行 resin,在浏览器中打开http://127.0.0.1:8080/resin-admin。破解版是有图表的。

 

 

resin 3.1.xx版破解方法。

工具:jd http://java.decompiler.free.fr/

利用jd打开resin 3.1.xx目录下的lib/license.jar

将源代码另存出来。再用eclipse打开LicenseStore.java

查找init()函数,将init()函数中的

this._serverCount;

改为

this._serverCount = 100;

然后编译为class文件,用winrar将class文件加入到lib/license.jar,覆盖原来的文件。

即可。

验证:运行 resin,在浏览器中打开http://127.0.0.1:8080/resin-admin,查看config,看到connection-max为1048576,即破解成功。

 

TCP ports

hmux://127.0.0.1:6800
accept-thread-min 5 keepalive-max 128
accept-thread-max 10 keepalive-select-max -1
accept-listen-backlog 100 keepalive-timeout 15000
connection-max 1048576 socket-timeout 65000
keepalive-connection-time-max 600000 suspend-time-max 600000
http://*:8080
accept-thread-min 5 keepalive-max 128
accept-thread-max 10 keepalive-select-max -1
accept-listen-backlog 100 keepalive-timeout 15000
connection-max 1048576 socket-timeout 65000
keepalive-connection-time-max 600000 suspend-time-max 600000

 

Java: Reading a pdf file from URL into Byte array/ByteBuffer in an applet.

I’m trying to figure out why this particular snippet of code isn’t working for me. I’ve got an applet which is supposed to read a .pdf and display it with a pdf-renderer library, but for some reason when I read in the .pdf files which sit on my server, they end up as being corrupt. I’ve tested it by writing the files back out again.

I’ve tried viewing the applet in both IE and Firefox and the corrupt files occur. Funny thing is, when I trying viewing the applet in Safari (for Windows), the file is actually fine! I understand the JVM might be different, but I am still lost. I’ve compiled in Java 1.5. JVMs are 1.6. The snippet which reads the file is below.

public static ByteBuffer getAsByteArray(URL url) throws IOException {
        ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();

        URLConnection connection = url.openConnection();
        int contentLength = connection.getContentLength();
        InputStream in = url.openStream();
        byte[] buf = new byte[512];
        int len;
        while (true) {
            len = in.read(buf);
            if (len == -1) {
                break;
            }
            tmpOut.write(buf, 0, len);
        }
        tmpOut.close();
        ByteBuffer bb = ByteBuffer.wrap(tmpOut.toByteArray(), 0,
                                        tmpOut.size());
        //Lines below used to test if file is corrupt
        //FileOutputStream fos = new FileOutputStream("C:\\abc.pdf");
        //fos.write(tmpOut.toByteArray());
        return bb;
}

I must be missing something, and I’ve been banging my head trying to figure it out. Any help is greatly appreciated. Thanks.

 


 

Edit: To further clarify my situation, the difference in the file before I read then with the snippet and after, is that the ones I output after reading are significantly smaller than they originally are. When opening them, they are not recognized as .pdf files. There are no exceptions being thrown that I ignore, and I have tried flushing to no avail.

This snippet works in Safari, meaning the files are read in it’s entirety, with no difference in size, and can be opened with any .pdf reader. In IE and Firefox, the files always end up being corrupted, consistently the same smaller size.

I monitored the len variable (when reading a 59kb file), hoping to see how many bytes get read in at each loop. In IE and Firefox, at 18kb, the in.read(buf) returns a -1 as if the file has ended. Safari does not do this.

I’ll keep at it, and I appreciate all the suggestions so far.

 

come from : http://stackoverflow.com/questions/637100/java-reading-a-pdf-file-from-url-into-byte-array-bytebuffer-in-an-applet

Matcher: groupCount()

/*
Group 0: 1
Group 1: 1
Group 2: null
Group 3: null
Group 0: 2
Group 1: 2
Group 2: null
Group 3: null
Group 0: 3
Group 1: 3
Group 2: null
Group 3: null
Group 0: 4.5
Group 1: 4.5
Group 2: .5
Group 3: null
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {

public static void main(String[] av) {
String regEx = “[+|-]?(\\d+(\\.\\d*)?)|(\\.\\d+)”;
String str = “a b c d e 1 2 3 4.5 “;
Pattern pattern = Pattern.compile(regEx);
Matcher m = pattern.matcher(str);
while(m.find()) {
for(int i = 0; i<=m.groupCount() ; i++) {
System.out.println(“Group ” + i + “: ” + m.group(i)); // Group i substring
}
}
}

}

LVS+Keepalived 介绍

LVS+Keepalived 介绍

LVS

LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统。本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一。目前有三种IP负载均衡技术(VS/NAT、VS/TUN和VS/DR);
十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq)。
Keepalvied
Keepalived在这里主要用作RealServer的健康状态检查以及LoadBalance主机和BackUP主机之间failover的实现

Click here to open new window CTRL+Mouse wheel to zoom in/out

IP配置信息:

  • LVS-DR-Master          192.168.2.166
  • LVS-DR-BACKUP          192.168.2.167
  • LVS-DR-VIP             192.168.2.170
  • WEB1-Realserver        192.168.2.171
  • WEB2-Realserver        192.168.2.172
  • GateWay                192.168.2.253
  • 浏览器与服务器交互原理以及用java模拟浏览器操作

    * 1,在HTTP的WEB应用中, 应用客户端和服务器之间的状态是通过Session来维持的, 而Session的本质就是Cookie,
    * 简单的讲,当浏览器向服务器发送Http请求的时候, HTTP服务器会产生一个SessionID,这个SessionID就唯一的标识了一个客户端到服务器的请求会话过程.
    * 就如同一次会议开始时,主办方给每位到场的嘉宾一个临时的编号胸牌一样, 可以通过这个编号记录每个嘉宾(客户端)的活动(请求状态).
    * 为了保持这个状态, 当服务端向客户端回应的时候,会附带Cookie信息,当然,Cookie里面就包含了SessionID
    * 客户端在执行一系列操作时向服务端发送请求时,也会带上这个SessionID, 一般来说,Session也是一个URL QueryParameter ,就是说,session可以以Key-Value的形式通过URL传递
    * 比如,http://www.51etest.com/dede/login.php?PHPSESSIONID=7dg3dsf19SDf73wqc32fdsf
    * 一般而言,浏览器会自动把此Session信息放入Header报文体中进行传递.
    * 如果浏览器不支持Cookie,那么,浏览器会自动把SessionID附加到URL中去.
    *
    * 2,在这个例子中,以登陆这个功能点进行讲解.
    * 首先,我们登陆的页面是http://www.51etest.com/dede, 我们第一次访问这个页面后,可以从服务器过来的Http Response报文中的Header中找出服务器与浏览器向关联的数据 — Cookie,
    * 而且Session的值也在Cookie中. 于是,我们可以通过分析Set-Cookie这个Header中的参数的值,找到Seesion的Key-Value段.
    * 然后,我们再向服务器发送请求,请求URL为:post@@http://www.51etest.com/dede/login.php@@userid=admin&pwd=tidus2005&gotopage=/dede/&dopost=login
    * 服务器验证登陆成功了, 并且在此次会话变量中增加了我们登陆成功的标识.
    *
    * 3,增加一个广告定义
    * 增加一个广告定义其实就是一个添加数据的过程,无非是我们把我们要添加的数据通过参数的形式告诉指定url页面,页面获取后添加到数据库去而已.
    * 此url地址为:
    * post@@http://www.51etest.com/dede/ad_add.php@@dopost=save&tagname=test&typeid=0&adname=test&starttime=2008-05-29
    * 因为这个页面会先判断我是否登陆
    * 而判断的依据,前面讲了,就是根据我请求时的SessionID找到指定的Session数据区中是否存在我的登陆信息,
    * 所以我当然要把访问登陆页面时获取的SessionID原封不动的再发回去
    * 相当于对服务器说,这是我刚刚来时,你发我的临时身份证,我现在可以形势我的权利。
    *
    * 这就是整个Java后台登陆网站,然后添加数据的过程。

     
    /** 
     *  
     */ 
    package sky.dong.test; 
     
    import java.io.BufferedReader; 
    import java.io.InputStreamReader; 
     
    import org.apache.commons.httpclient.Cookie; 
    import org.apache.commons.httpclient.Header; 
    import org.apache.commons.httpclient.HttpClient; 
    import org.apache.commons.httpclient.NameValuePair; 
    import org.apache.commons.httpclient.cookie.CookiePolicy; 
    import org.apache.commons.httpclient.methods.PostMethod; 
    import org.apache.commons.httpclient.params.HttpMethodParams; 
     
    /** 
     * @author 核弹头 
     * Email:[email protected] 版权所有 盗版必究 
     * @since 2009-8-11 
     * @version 1.0 
     */ 
    public class HttpLoginTest { 
     
        public static void main(String[] args) { 
            String url = "http://discuzdemo.c88.53dns.com/logging.php?action=login&loginsubmit=yes&floatlogin=yes";//论坛的登陆页面 
            String url2="http://discuzdemo.c88.53dns.com/post.php?infloat=yes&action=newthread&fid=2&extra=&topicsubmit=yes&inajax=1";//论坛的发贴页面 
            HttpClient httpClient = new HttpClient(); 
            //httpClient.getHostConfiguration().setProxy("222.247.62.195", 8080); 
            httpClient.getParams().setCookiePolicy( 
                    CookiePolicy.BROWSER_COMPATIBILITY); 
            PostMethod postMethod = new PostMethod(url); 
            PostMethod postMethod2 = new PostMethod(url2); 
            NameValuePair[] data = { 
                    new NameValuePair("username", "123"), 
                    new NameValuePair("referer", 
                            "http://discuzdemo.c88.53dns.com/index.php"), 
                    new NameValuePair("password", "123"), 
                    new NameValuePair("loginfield", "username"), 
                    new NameValuePair("questionid", "0"), 
                    new NameValuePair("formhash", "fc922ca7") }; 
            postMethod.setRequestHeader("Referer", 
                    "http://discuzdemo.c88.53dns.com/index.php"); 
            postMethod.setRequestHeader("Host", "discuzdemo.c88.53dns.com"); 
            // postMethod.setRequestHeader("Connection", "keep-alive"); 
            // postMethod.setRequestHeader("Cookie", "jbu_oldtopics=D123D; 
            // jbu_fid2=1249912623; smile=1D1; jbu_onlineusernum=2; 
            // jbu_sid=amveZM"); 
            postMethod 
                    .setRequestHeader( 
                            "User-Agent", 
                            "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"); 
            postMethod 
                    .setRequestHeader("Accept", 
                            "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 
            // postMethod.setRequestHeader("Accept-Encoding", "gzip,deflate"); 
            // postMethod.setRequestHeader("Accept-Language", "zh-cn"); 
            // postMethod.setRequestHeader("Accept-Charset", 
            // "GB2312,utf-8;q=0.7,*;q=0.7"); 
            postMethod.setRequestBody(data); 
            try { 
                httpClient.executeMethod(postMethod); 
                StringBuffer response = new StringBuffer(); 
                BufferedReader reader = new BufferedReader(new InputStreamReader( 
                        postMethod.getResponseBodyAsStream(), "gb2312"));//以gb2312编码方式打印从服务器端返回的请求 
                String line; 
                while ((line = reader.readLine()) != null) { 
                    response.append(line).append( 
                            System.getProperty("line.separator")); 
                } 
                reader.close(); 
                Header header = postMethod.getResponseHeader("Set-Cookie"); 
                Cookie[] cookies=httpClient.getState().getCookies();//取出登陆成功后,服务器返回的cookies信息,里面保存了服务器端给的“临时证” 
                String tmpcookies=""; 
                for(Cookie c:cookies){ 
                    tmpcookies=tmpcookies+c.toString()+";"; 
                    System.out.println(c); 
                } 
                System.out.println(tmpcookies); 
    //            System.out.println(header.getValue()); 
                System.out.println(response); 
                NameValuePair[] data2 = { 
                        new NameValuePair("subject", "测试自动发贴"), 
                        new NameValuePair("message", 
                                "能否发贴成功呢?测试一下就知道了"), 
                        new NameValuePair("updateswfattach", "0"), 
                        new NameValuePair("wysiwyg", "0"), 
                        new NameValuePair("checkbox", "0"), 
                        new NameValuePair("handlekey", "newthread"), 
                        new NameValuePair("formhash", "885493ec") }; 
                postMethod2.setRequestHeader("cookie",tmpcookies);//将“临时证明”放入下一次的发贴请求操作中 
                postMethod2.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "gbk");//因为发贴时候有中文,设置一下请求编码 
                postMethod2.setRequestHeader("Referer", 
                        "http://discuzdemo.c88.53dns.com/forumdisplay.php?fid=4"); 
                postMethod2.setRequestHeader("Host", "discuzdemo.c88.53dns.com"); 
                // postMethod.setRequestHeader("Connection", "keep-alive"); 
                // postMethod.setRequestHeader("Cookie", "jbu_oldtopics=D123D; 
                // jbu_fid2=1249912623; smile=1D1; jbu_onlineusernum=2; 
                // jbu_sid=amveZM"); 
                postMethod2 
                        .setRequestHeader( 
                                "User-Agent", 
                                "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"); 
                postMethod2 
                        .setRequestHeader("Accept", 
                                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");//以上操作是模拟浏览器的操作,使用服务器混淆 
                 
                postMethod2.setRequestBody(data2); 
                httpClient.executeMethod(postMethod2); 
                StringBuffer response1 = new StringBuffer(); 
                BufferedReader reader1 = new BufferedReader(new InputStreamReader( 
                        postMethod2.getResponseBodyAsStream(), "gb2312")); 
                String line1; 
                while ((line1 = reader1.readLine()) != null) { 
                    response1.append(line1).append( 
                            System.getProperty("line.separator")); 
                } 
                reader1.close(); 
                System.out.println(response1); 
            } catch (Exception e) { 
                System.out.println(e.getMessage()); 
                // TODO: handle exception 
            } finally { 
                postMethod.releaseConnection(); 
                postMethod2.releaseConnection(); 
            } 
     
        } 
     
    } 
     
    

    以上代码完成一个登陆论坛后在指定的版块自动发贴的功能

     

    Bash 小技巧:给目录加上书签,快速切换目录

    原文地址:http://www.zhuoqun.net/html/y2011/1635.html

    当我们在命令行下面做开发的时候,很大一部分时间都浪费在了目录切换上面,相信不少人每天敲 “cd” 都敲得想吐。如果目录层次多一点,Tab 键也会饱受摧残。虽然 Bash 有内置的 “cd -”, “pushd” 和 “popd” 命令,但用起来都不是很顺手。

    昨天在 Twitter 上看到了 Huy Nguyen 的一篇文章:Quick Bash Tip : Directory Bookmarks,用几行简单的 Bash 脚本巧妙地给目录加上了书签,这样你就可以给最常用的那几个工作目录加上书签,不需要每次都敲 cd 了。

    昨天 Huy Nguyen 的这篇文章被发布到了 Hacker News 上,然后引来了很多人评论,其中不少评论都是非常有价值的,甚至还有人直接在评论里对 Huy Nguyen 的脚本做了改进。Huy Nguyen 看到评论之后也修改了自己最初写的脚本,并放到了 github 上(https://github.com/huyng/bashmarks),你可以用 git clone 命令把那个脚本下载下来,或者直接把源码复制到你的 ~/.bashrc 中。

    这个脚本只有三个命令:

    s – 给当前目录加上书签,书签名为 bookmark_name
    g – 跳到名为 bookmark_name 的书签
    l – 列出所有的书签

    如果想要删除已经保存的书签,请直接编辑 $HOME/.sdirs 文件删除相应的行。

    评论中也有人推荐了另外一个功能更为强大的名为 z 的脚本,这个脚本也在 github 上(https://github.com/rupa/z),有兴趣的可以试用一下。

    BTW, 经常在国外很多技术文章下面看到很多精彩评论,有些甚至比文章本身更加精彩,所以我很多时候都把每个评论仔细看完。评论里没有人说“沙发”,没有人说“傻 逼,这都不懂”,没有人说“菜鸟,早就有人写出同样的东西了!连z都没听说过,我只用它!”,大家都很礼貌,即使是有反对意见也都是逻辑清晰地列出自己的 理由。这让我非常惊诧和羡慕。

    作者发布一篇文章,读者提供反馈,然后作者改进原文,文章的改动历史和评论都成为文章不可分割的一部分,作者和读者都可以不断思考和获益。反过来 说,也正是因为这样的氛围才使得很多人敢于分享自己的看法,敢于写出自己的观点,敢于否认自己最初的看法并不断修正。真希望国内在别人文章下面评论的人也 可以有那样的耐心和礼貌,以及与作者对话的逻辑和才能。至少,要把别人的文章看完再发言。