Archive for May, 2005

Java Executors

I’m surprised I hadn’t come across these classes before, but Java Executors are great. Added in JDK 1.5, Executors provide built in thread management for all kinds of needs. Below are two simple code fragments.

These two pieces of code are about the same amount of code to spawn a new thread, wait and return. However, the Executor code allows easy replacement of the ExecutorService so that you can use a variety of different thread management and scheduling options. The Executor code uses a simple single threaded executor so that you can queue up jobs, but the JDK also has builtin fixed size thread pools, dynamic thread pools, and you can define your own factory method for thread creation. The Executor also can run older Runnable tasks, but the new Callable interface is more flexible because it can return a value of any type and throw exceptions.

It’s good stuff. Plus it makes me think of Starcraft because the Protoss commanders were called Executors.

import java.util.concurrent.*;

public class ExecutorFun {  public static class DoIt implements Callable {    public String call() {      return "Hello World!";    }  }

  public static void main(String []args) {    try {      ExecutorService executor = Executors.newSingleThreadExecutor();      FutureTask task = new FutureTask(new DoIt());      executor.submit(task);      System.out.println(task.get());      executor.shutdown();    } catch ( Exception e ) {}  }}

Compare that with the following older style code

public class ThreadFun {  public static class DoIt implements Runnable {    String result;    public void run() {      result = "Hello World!";    }  }

  public static void main(String []args) {    try {      DoIt task = new DoIt();      Thread t = new Thread(task);      t.start();      t.join();      System.out.println(task.result);    } catch ( Exception e ) {}  }}

Leave a Comment

Ugh spam

Both gmail and proofpoint are having a hard time detecting spam that is bounced back to me. Some asshat is sending a huge number of spams from a bunch of random users @chen.net. This is causing me to get about huge number of bounce messages a day. It’s really pissing me off. I’m getting a total of about 1200 spams a day, but the false negative rate has gone way up. I’m probably getting about 100-200 more spams into my inbox than I was before.

I guess I should see how easy it is to do Domain Keys or Sender Policy Framework but I doubt whether these will help solve my current problems.

Leave a Comment

Happy Birthday to me.

Another year older and another year dumber. Maybe with luck, I’ll get out of work early tonight and have a nice dinner with Tracy. We spent some of Sunday up at Half Moon Bay sitting on the beach. It was a bit windier than expected, so we didn’t sit too long, but we got up and took a walk along the boardwalk.

Leave a Comment

Guild Wars

I’ve finally gotten a chance to play some Guild Wars and I’m very impressed. It lives up to the hype. It has a lot of excellent design features that make it not a grind and it feels like it could be playable for a long time. Here are some of the reasons it is so good.

  • Very good graphics: It’s pretty hard to amaze me these days since I saw HL2 so I rate the graphics just very good, but you gotta have something good.
  • Unique skill system. Most games these days have some sort of profession/class system, but the Guild Wars skill system is very elegant and unique. While each of the 6 profession has a large number of skills(around 75 each I think), each character has a lot of customization available. Every player has a two classes a primary and secondary. On any mission, you can only have 8 skills available. It makes skill choice very important for each mission, but not permanently disastrous.
  • Very good Player vs Environment(PVE) system. The quest system is pretty good and the level advancement isn’t much of a grind. There’s a maximum of 20th level, so it doesn’t take a very long time to hit the max.
  • Very good Player vs Player(PVP) System. It’s tough to build a balanced system for multiplayer combat. I can’t conclude that it’s balanced yet, but it is a fast action game, where tactics and skill selection really counts.
  • Well integrated PvP and PvE. This is a tough thing to do. But NCSoft has done a really good job here of making people useful in both PvP and PvE. You can use one of their high level cookie cutter characters if you just want to try out PvP to see how you like it, but those characters have very limited skills, so for a lot more customization you can use a PvE character to unlock more skills and items. Once unlocked any of your characters(with the correct profession) can use the unlocked things.

Leave a Comment

Poker win rate and position

Two things I’ve been thinking about lately are poker win rates and position.

The standard way of calculating how good a player your are in limit games is to calculate your win rate in terms of big bets per hour you win. Most of the consensus seems to be that a good player can win an average of about 2-3 big bets per hour in a casino. So at a limit $1/2 table, that averages about $4-6/hr, and at a $15/30 table, that’s $90/hr. Especially at the smaller games the rake is going to eat into the win rate significantly. The problem with that calculation is that it’s sort of based on regular physical casinos. Today a lot of players including myself play a lot more online than in real casinos. So it’s better to use the metric that PokerTracker uses, whch is Big Bets won/100 hands. That accounts for the much faster play online which is usually 60-80 hands/hr instead of 40-50 in a real casino.

The other thing I’ve been considering lately is the value of position, especially when related to pot limit omaha on the flop. In omaha, checking and giving someone an opportunity to see a free card is a huge mistake when you have th e best hand because any single card could improve an opponents hand dramatically. This makes it’s much less common for people to attempt to checkraise on the flop. The relative lack of checkraising on the flop therefore means a position only bet can be made relatively frequently and successfully. This leads to my ultimate conclusion which is that position is significantly more important in pot limit omaha than both pot or no limit hold’em.

Leave a Comment

Poker formats to prevent collusion

More poker stuff. Paul Phillip’s blog has been talking about collusion lately and how to prevent it. I think someone should come up with some tournament formats that discourage collusion, or make it clear where other interests lie. The only tournament format which does that is a full headsup tournament which isn’t really that practical to run for a casino. Maybe a team format would make hidden collusion and soft play less common. Lucky Chances has a doubles tournament every year where 2 people play on a team. Every twenty minutes, you don’t play and your partner sits out then you switch. It’s not that great a format, someone could come up with something better. Any ideas?

Leave a Comment

C preprocessor macros are evil

I just spent a long and frustrating night recovering from someone else’s use of C preprocessor macros. They are the work of the devil. They just make it very easy to screw someone else up in very hard to find ways if you aren’t careful. Here’s an example. Co-worker A defined a macro which happened to be a variable used by a third party library. This wasn’t a problem until I was making some code changes, I reordered some of the includes. This caused compile errors in code I’d never touched. It took me several hours of debugging to find the problem. The hard thing about this is that it’s impossible to debug easily. Only looking at the C code that the preprocessor generated was helpful

Leave a Comment

Java getter/setter replacements(more on java enums)

I’ve never liked the whole Java thing of building getter and setter methods to access instance variables. Here’s a typical example:

public class Story {  private String author;  private String title;  private String text;  public String getAuthor() {    return author;  }  public void setAuthor(String author) {    this.author = author;  }  public String getTitle() {    return title;  }  public void setTitle(String title) {    this.title = title;  }

  public String getText() {    return text;  }  public void setText(String text) {    this.text = text;  }

}

I’m really not a fan of all this code for what is something pretty simple conceptually. It’s a bit error prone and ugly in my opinion because it creates a huge number of methods in an API. But there are a lot of APIs that are built around this sort of thing. I thought about the Java enum stuff I’ve been using and I came up with some other way I’d prefer to do something like this. Consider the following replacement code…

public class Story {  public enum Fields {    AUTHOR,TITLE,TEXT;  }  public EnumMap fieldMap = new EnumMap(Fields.class);}

It’s not an apples to apples comparison, but this second example has some nice features. Most particularly, adding in new fields does not require as much code, and getting all the fields can be done easily and iterated through with something like this:

  for(Map.Entry entry:fieldMap.entrySet()) {    System.out.println("Key: " + entry.getKey() + " Value: " + entry.getValue() );  }

You don’t even have to define a toString() method for the fieldMap. It’s got a very good one builtin. Enums can be used as a poor man’s replacement for reflection, it’s just good enough sometimes.

Leave a Comment

Who do you trust more with your data?

In an ideal world all your web usage and personal data would be completely anonymous and no one would be able to discern any information about you that you didn’t allow them to. However we are rapidly moving in the opposite direction where everyone can buy and sell your data at will. The question is, who would you rather have your data big companies or small companies. I believe your personal data is much safer with a large multinational data-centric company(like Yahoo or Google) than some small random website. Why? Because a large company won’t sell you out individually and they have much better data security policies and procedures. A small company might make a buck off of selling your name and address, and that’s hard for them to pass up especially if they get into financial trouble, but a large company is likely to only sell aggregate data in aggregate so that they can continue to resell it multiple times and they don’t want to dilute the value of their data.

Leave a Comment

Gmail as a spam filter

I just tried out Gmail’s mail forwarding service. Interestingly, they don’t forward spam, so it was easy to use a dummy gmail account just to filter out all the spam that I get and then send it back to me. It catches somewhat different things than my standard filter Proofpoint. But while I’m using both, I think they catch %96-98 of the spam(which still amounts to a 5-10 a day).

Leave a Comment