Skip to main content

Posts

Showing posts from 2012

401k 账户 介绍 mitbbs (转)

也许你刚参加工作,公司为你建立了401k账户。你也常常听到周围的人说起401k账户。可你还搞不清401k究竟是什么,对你有什么影响。这篇文章就将向您解释有关401k账户的基本知识及投资策略。 1.       什么是401k 账户? 401k 账户是一种退休投资账户。基本原理就是你年轻的时候往账户里面存钱投资各种基金及股票,退休后取出来用。 许多公司把401k作为一种福利,match你工资收入的一定百分比。比方说,公司的政策是dollar for dollar match up to 5%。也就是说你每存一美元进去,公司也出一美元存进你的账户,直到存满你工资的5%。之后你再存钱进去,   公司就不再match了。所以如果你一年内contribute 5%,  你的账户里实际有了你工资的10%。但须注意有的公司帮你存的钱可能不是fully vested。公司的contribution虽然在你的账户里显示,但还不真正属于你。如果你公司的规定是4年vested而你在第二年便离开公司,你 只获得你自己的contribution加上公司contribution的25%。 2.       应该存多少钱进401k 账户 你应该存至少你的雇主所match的工资的百分比。因为公司给match的那部分钱等于是白送,不拿白不拿。假设你公司match 5%,而你的工资是10万。如果你只contribute 3%,你等于白白丢掉了$2000。 那存满公司match的百分比之后呢?你或许听说过401k有避税功能,是不是存得越多越好呢?现在让我们来看看401k是怎么省税的。 a.       降低tax bracket: 把钱存进401k可以降低当前的taxable income。 如果存得足够多,你可以此降低自己的tax bracket。 b.      延迟交税:存进401k账户里的钱并不是不交税,而是推迟交税,取钱时再交税。这样做的好处有两重:一是投资收益能够不受税率影响地利滚利。假设现有 1000块,平均每年投资回报率是10%,税率是30%。30年后就是1000*1.1^30*70% = 12214。如果没有推迟交税的优惠政策,30年后这1000块只变为1000*1.07^30 = 7612。当然这个例子有些夸大,因为很少

WordNet JWNL hangs / block for some Strings

This may be a bug for JWNL WordNet. When using the following method, MorphologicalProcessor.lookupBaseForm(POS.NOUN, token) if the input token is some long alphanumeric string (e.g. "l0sfool0o0cnews0cinvesting0c20a120c0a50c0a20cplanning0efor" ), The method may run for a long time. Reference: http://stackoverflow.com/questions/10599966/jwnljava-wordnet-library-hangs-while-processing-large-alphanumeric-data

Monitor memory usage in Java

public static void printMemoryUsage() { int MegaBytes = 10241024; long freeMemory = Runtime.getRuntime().freeMemory() / MegaBytes; long totalMemory = Runtime.getRuntime().totalMemory() / MegaBytes; long maxMemory = Runtime.getRuntime().maxMemory() / MegaBytes; logger.warn("JVM freeMemory: " + freeMemory); logger.warn("JVM totalMemory(initial heap size of JVM):" + totalMemory); logger.warn("JVM maxMemory (maximum heap size of JVM): " + maxMemory); }

Reading list for opinion mining or sentiment analysis (keeping update)

The following are papers for opinion mining or sentiment analysis. Recommend a good latest survey paper. (Click to download) A Survey of Opinion Mining and Sentiment Analysis Kluwer Academic Publishers 2012 1. Survey papers    1.   Liu, B.  Sentiment analysis and subjectivity .    In Handbook of Natural Language Processing, Second Edition, N. Indurkhya and F.J. Damerau, Editors. 2010.    2.   Pang, B. and L. Lee.  Opinion mining and sentiment analysis.  Foundations and Trends in Information Retrieval, 2008, 2(1-2): p. 1-135.     2. Sentiment analysis method    1.  Pang, B., L. Lee, and S. Vaithyanathan.  Thumbs up?: sentiment classification using machine learning techniques . In Proceedings of Conference on Empirical Methods in Natural Language Processing (EMNLP-2002), 2002    2.  Ding, X., B. Liu, and P. Yu.  A holistic lexicon-based approach to opinion mining . In Proceedings of the Conference on Web Search and Web Data Mining (WSDM-2008), 2008.    3.  Jin,

MyBatis: Insert multiple rows if doesn’t exist otherwise update the existing rows

The following is only content for XML file in MyBatis <insert id="insertOrUpdateMultipleRecords" parameterType="HashMap">     INSERT INTO table1  ( field1, field2, created )     VALUES     <foreach collection="inputList" item="inputListItem" separator=",">        (#{inputListItem.itemfield1}, #{inputListItem.itemfield2} , NOW())     </foreach>     ON DUPLICATE KEY UPDATE field2 = VALUES(field2)   </insert>

Java开发人员知识点 (转)

1.听说过James Gosling,SUN和Oracle公司。知道网上下载Java的地址,在哪讨论Java。练习过Java在Windows下的安装和配置。知道Java应用系统中常见的几种license和JCP。了解bytecode和Java在不同系统下可以轻松移植的原理。 2.懂得基本的Java编程和行命令格式。了解面向对象的编程思路。 几个基本点:Java基本语法和控制结构,命名和代码风格,结构化,对象封装,继承,抽象,多态,接口,异常处理,堆空间,栈空间,垃圾回收器,static,this,synchronized,annotations,JUnit,JDBC,JSP/servlet Java Core APIs: java.lang,java.util,java.io,java.awt,javax.swing,JFrame ,String,java.sql,JUnit 3.了解Java ME,Java SE,和Java EE的基本区别。知道JVM,JRE,Java SDK,JavaContainer的不同。懂得Java SE6,Java 1.5和Java 1.4的不同,特别是1.4到1.5的改进,包括generics,enum,new loop,variable number of arguments。听说过Oracle JRockit。 4.熟悉一种Java IDE比如Eclipse,NetBeans,JDeveloper,IntelliJ,JBuilder,JCreator。最好版本比较新。懂得如何在程序中查错,熟悉常见的几种Java错误。 5.能用SVN/CVS/GIT进行团队开发。可以编写Javadoc文档。懂得一般的版本管理方法。 6.熟悉JDBC和JSP编写基本的Web数据库应用。懂得基本的SQL编程,JDBC,HTML格式, JavaScript编程和CSS语法。 7.懂得进一步的Java编程比如collections,serialization,streams,networking,multi-threading,reflection,event handling,localization,charset conversion Java Core APIs: java.util,java.text,j

Unstandardized Predicted Value and Standardized Predicted Value

The Unstandardized Predicted Value and the Standardized Predicted Value have a perfect correlation  because they are simple linear transformations of one another.  Illustrattively, the standardized predicted value involves the subtraction of a constant (the mean predicted value) from each predicted value, and division by a constant (the standard deviation of the predicted values). The adjusted predicted value is somewhat more complicated.  This is the predicted value for a case when it is excluded from the computation of the regression coefficients. http://spssx-discussion.1045642.n5.nabble.com/regression-predicted-values-td1069695.html

Coding execises

The following are kinds of coding websites. http://codeforces.com/ http://codingbat.com/ http://projecteuler.net/ http://poincare.matf.bg.ac.rs/~jelenagr/ASP/testHeadHunter.pdf anandtechblog.blogspot.com/ http://tianrunhe.wordpress.com/category/questions-from-careercup/ http://codinggeeks.blogspot.com/ interview question summary https://docs.google.com/file/d/0B2I8CDQfM3NKLVdEWkNxNjVkWjA/edit?+usp=sharing

Web development tools

you have deep knowledge in the entire LAMP stack and also: ·       RHEL 5.x or CentOS ·       LDAP ·       Web servers like nGnx, Apache, etc. ·       Tomcat application server, ·       Network security (eg. Firewalls, IDS, etc.) ·       Logical security (eg. PAM, VP, trusted/bastion, ssh, Kerberos, etc.), ·       Software Load Balancers like Zeus ·       Infrastructure monitoring solutions like Zabbix, WebMetrics, Nagios, Cricket, MRTG, etc. ·       Clustering/HA: Memcached, Repcached, Hibernate and Terracotta ·       Automation ·       Bare metal provisioning (eg. Kickstart) ·       Configuration management (eg. Puppet)

Google Adsense 博客能赚钱吗 (转)

个人网站加入Google AdSense赚钱的多少,主要取决于网站访问量、网站内容所在领域(不同领域的广告价格有所差异)、网页设计和AdSense广告代码优化等因素(直接 影响广告点击率),一般说来网站访问量越高,广告展示字数多,在点击率相对稳定的前提下,获得的广告佣金也就越多。 在google AdSense提供的常见问题解答中有这样一个问题:我可以通过此计划获得多少收入(原文附后)?不过,google并没有直接告诉内容发布商将可以从广 告主支付的每次点击费用中获得多大比例的佣金。事实上google AdSense提供给加盟会员(即google所说的内容发布商)的佣金比例也可能并不是固定的。“尽管我们不会详细公布收入分配情况,但我们的目标是保 证发布商获得的收入不会少于他们加入其他广告网所能获得的收入。”这是google对于佣金的惟一解释,从中很难获得google AdSense佣金政策的具体信息。事实上,通过对多家网站联盟佣金的分析发现,google AdSense提供的佣金是比较高的,这就意味着,同样访问量的网站加入google AdSense比其他的网络联盟赚钱要多一些。 另外,由于google有较高的知名度和可信度,你的个人网站加入google AdSense显示google提供的网页内容相关的网络广告,相对于其他网站联盟提供的广告来说,有更高的可信度,对充实网站的相关内容也有一定的价 值。也正因为如此,加入google AdSense获得的综合价值是最高的。 总之,google AdSense制定的会员佣金政策应该比一般电子商务网站提供的固定佣金比例的模式复杂得多,要想准确了解google AdSense的佣金支付方案可能是徒劳的,并且既然google声明不会详细公布这一分配方案,那么我个人认为也没有必要对此做过多的猜测,加盟会员只 要大致了解一下每次点击的平均佣金状况也就差不多了。 根据作者对部分网站佣金情况了解的一些信息,发现一些统计信息,对于推测个人网站赚钱多少可能有一定参考价值:平均每次点击的佣金大概在 0.02-0.25美元左右,或者说每千次广告展示eCPM大约0.5-1.5美元左右。如果从广告点击率来看,由于各网站广告点击率差异较大,从 0.4%-10%之间都属于正常,1%-3%都是比较常见的点击率。这样推算,

Java GzipInputStream GZIP can not read the whole file

GzipInputStream can only read a small portion of gzip file. This is a bug for Java http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4691425 Reason: the gz/zip file is concatenated before. (e.g. you continuously append the gz/zip file) Solutions: Use following class "MultiMemberGZIPInputStream" to replace "GzipInputStream"  import java.io.InputStream; import java.io.PushbackInputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; /** * replace GZIPInputStream to read concatenated gz file FileInputStream fis = new FileInputStream(zipFileName); BufferedReader reader = new BufferedReader(new InputStreamReader( new MultiMemberGZIPInputStream(fis))); */ public class MultiMemberGZIPInputStream extends GZIPInputStream { private MultiMemberGZIPInputStream parent; private MultiMemberGZIPInputStream child; private int size; private boolean eos; public MultiMemberGZIPInputStream(InputStream in, int si

Transform singular and plural forms of words (not WordNet)

import java.util.HashSet; import java.util.LinkedList; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Transforms words to singular, plural, humanized (human readable), underscore, camel case, or ordinal form. This is inspired by * the Inflector class in Ruby on Rails , which is distributed under the Rails license . * @author Randall Hauch * */ public class Inflector { protected static final Inflector INSTANCE = new Inflector(); public static final Inflector getInstance() { return INSTANCE; } protected class Rule { protected final String expression; protected final Pattern expressionPattern; protected final String replacement; protected Rule(String expression, String replacement) { this.expression = expression; this.replacement = replacement != null ? replacement : ""; this.expressionPattern = Pattern.compile(this.expression, Pattern.CASE_INSENSITIVE); }

Web application monitor tool

Ganglia http://ganglia.sourceforge.net/ JConsole http://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html jstack http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html http://www.herongyang.com/Java-Tools/jstack-Detect-Java-Thread-Deadlocks.html jmap http://www.herongyang.com/Java-Tools/jstack-jmap-Generate-Heap-Dump-File.html htop http://htop.sourceforge.net/ visualvm http://visualvm.java.net/

How to avoid concurrentModificationException

Code with exception public static void main(String[] args) { List myList = new ArrayList (); myList.add("1"); myList.add("2"); myList.add("3"); myList.add("4"); myList.add("5"); Iterator it = myList.iterator(); while(it.hasNext()){ String value = it.next(); if(value.equals("3")){ myList.remove("3"); } } System.out.println("List Size:"+myList.size()); } Code without exception using Iterator public static void main(String[] args) { List myList = new ArrayList (); myList.add("1"); myList.add("2"); myList.add("3"); myList.add("4"); myList.add("5"); Iterator it = myList.iterator(); while(it.hasNext()){ String value = it.next();

Pass JSP variable as parameter to Javascript function

Two points which need to pay attention when applying: (1)  Use single quote for parameter in Javascript function e.g.  foo is a Javascript fcuntion; value is a JSP variable. onclick="foo(' <%=value %>');" (2)  Use  following Javascript function to encode String containing  special characters (e.g. ";"  "\r") You have 3 options: escape()  will not encode:  @*/+ encodeURI()  will not encode:  ~!@#$&*()=:/,;?+' encodeURIComponent()  will not encode:  ~!*()' References: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript http://stackoverflow.com/questions/10033555/pass-a-jsp-variable-as-parameter-to-javascript-function http://stackoverflow.com/questions/4803906/jsp-variable-accssing-in-javascript

Is volatile variable thread-safe in Java

Not my writing Access to volatile int in Java will be thread-safe. When I say access I mean the unit operation over it, like volatile_var = 10 or int temp = volatile_var (basically write/read with constant values). Volatile keyword in java ensures two things : 1) When reading you always get the value in main memory. Generally for optimization purposes JVM use registers or in more general terms  local memory  foe storing/access variables. So in multi-threaded environment each thread may see different copy of variable. But making it private makes sure that write to variable is flushed to main memory and read to it also happens from main memory and hence making sure that thread see at right copy of variable. 2) Access to the volatile is automatically synchronized. So JVM ensures an ordering while read/write to the variable. However Jon Skeet mentions rightly that in non atomic operations (volatile_var = volatile + 1) different threads may get unexpected result. Reference:  http:

Generics in Java

"What is the difference between a wildcard bound and a type parameter bound" http://stackoverflow.com/questions/3486689/java-bounded-wildcards-or-bounded-type-parameter http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ203

Protected access modifier in Java

A subclass only access a protected members of its parent class, if it involves implementation of its parent. But in a different package, it cannot access the protected member though parent instance. You can’t use a protected constructor in a class that extends the constructor’s class, other than via an implicit or explicit super() to invoke the protected constructor. http://www.stevideter.com/2008/05/04/understanding-the-protected-access-modifier-and-inheritance-in-java/ http://mindprod.com/jgloss/protectedscope.html

Java serialization in class hierarchy (inheritance)

There are two cases for Java serialization in class hierarchy. Suppose we have two classes : SuperC and SubC. ( It does not matter whether SuperC is abstract class or not ) Case 1: Super class (SuperC) implements interface "Serializable". This case is simple. The sub class does not need to implement interface "Serializable". package serializable; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; abstract class SuperC implements Serializable { int supervalue; public SuperC() { } public SuperC(int supervalue) { this.supervalue = supervalue; } public String toString() { return "supervalue: " + supervalue; } } class SubC extends SuperC { int subvalue; private static final long serialVersionUID = 201111291028L; public SubC(int supervalue, int subvalue) { super(supervalue); this.subvalue = subvalue;

Apache Ant tutorial

https://www6.software.ibm.com/developerworks/education/j-apant/j-apant-ltr.pdf http://ideoplex.com/focus/java#ant TortoiseSVN Ant 实现自动化更新和发布 http://lengjing.iteye.com/blog/1158351 http://www.javapractices.com/topic/TopicAction.do?Id=135 Project dependency http://www.exubero.com/ant/dependencies.html Sample Ant script http://www.javapractices.com/topic/TopicAction.do?Id=135

Software skills

Iterable interface example (not my writing)

import java.util.Iterator; import java.util.NoSuchElementException; // This class supports iteration of the // characters that comprise a string. class IterableString implements Iterable , Iterator { private String str; private int count = 0; public IterableString(String s) { str = s; } // The next three methods implement Iterator. public boolean hasNext() { if (count < str.length()){ return true; } return false; } public Character next() { if (count == str.length()) throw new NoSuchElementException(); count++; return str.charAt(count - 1); } public void remove() { throw new UnsupportedOperationException(); } // This method implements Iterable. public Iterator iterator() { return this; } } public class MainClass { public static void main(String args[]) { IterableString x = new IterableString("This is a test."); for (char ch : x){ System.out.println(ch); } } }

Enum in Java

http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html http://javarevisited.blogspot.com/2011/12/convert-enum-string-java-example.html An enum example private enum Score { MINUS10(-10), MINUS5(-5), ZERO(0), PLUS5(5), PLUS10(10); private final int value; private Score(int value) { this.value = value; } public int getValue() { return value; } static public boolean isValid(int value) { Score[] scores = Score.values(); for (Score aScore : scores) { if (aScore.getValue() == value) { return true; } } return false; } }