Two Guys Arguing

C# Meta-Programming And Extension Methods Question

Posted in .net, functional programming, questions by benjaminplee on 12.30.10

First, it should be noted that my ASP.Net MVC-foo is yet great and I know this.  If you know a better way to do this, please take the time to explain how you are superior.  If you don’t, how will we ever know?

Working with ASP.Net MVC 2 client-side form validation this past week, I ran into two unfortunate (IMHO) facts which kept tripping me up:

  1. Html.ClientValidationEnabled() must be called as a scriptlet BEFORE the form is created
  2. Html.ValidateFor or Html.ValidationMessageFor must be called for EACH property of the model you want validated.

*** This StackOverflow answer includes a couple other important & useful things to note

These two issues (and many more) bother me about ASP.Net MVC 2 client-side validation but #2 in particular was really ticking me off.  I like that I can conditionally turn validation on/off on a field by field basis … but why make me enumerate all validation-needed model fields twice in my view!?  Especially in my case where I want validation turned on for ALL model object fields that have DataAnnotation Validations defined for.  Obviously the fields are going to be enumerated in the view once; how else are the text boxes and drop downs going to be created, but why make me list out each field AGAIN just to turn on validation?

All of this amounts to one WET solution. Am I missing something?

The best solution I have seen, and the one I am about to start implementing, is this one by Rick Anderson over at MSDN found via this related forum post.  The idea is to create additional Html helper extension methods which will combine the creation of the HTML form element with turning on and configuring validation.  This solution has the benefit of making me enumerate the model fields being used only ONCE in my view code and reads cleaner.

The only problem is that I have to walk through our application, find anywhere that is using a built in HtmlHelper extension method to build an HTML form element (e.g. input tag), build a new validating wrapper extension method that matches the signature of the original, and then replace the original code with the new extension method.  This can be done, but is time consuming and error prone.  And I am lazy.

The real issue …

I want to … create additional HtmlHelper extension methods based on all existing ones that produce form elements and take in a Linq expression to find the model property that first pass that expression to helper.ValidateFor() and then return the original extension method’s valued.

Is there any meta-programming feature or technique in C# that will allow me to concisely do that?


Since Html.TextBoxFor(user => user.FirstName) is used in our app, as it stands I will am going to create a custom extension method similar to:

public static class ValidatingFormElementsExtension
  public static MvcHtmlString ValidatedTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression)
    return helper.TextBoxFor(expression);

  // and so on for EACH one we use


Anyone have any ideas?  Am I completely off base with this? Is there a better way?



A few more quick cracks at ASP.Net MVC  that I need to get off my chest

  • Why are so many things done in scriptlets!?  I feel like I am back in the vanilla JSP days of yesteryear.
  • They are Annotations in Java and Attributes in C# …. so why are the data validation attributes defined in System.ComponentModel.DataAnnotations?
  • I get that HTML checkbox form input fields have TRUE/FALSE values passed back when the form is submitted, and that doesn’t map perfectly to how other fields are handled by the Required attribute …. but why was NOTHING included to do this?  Having to use a RegularExpression validator for [Tt]rue is clumsy no?


Matrix Puzzle From Hell or: How I Learned to Stop Worrying and Love the Patterns

Posted in challenge, math by benjaminplee on 12.30.10
The Stage

About a year ago, Mr. King (@Adkron) posed a math puzzle on our team’s whiteboard first thing one morning.  The problem seemed at the same time very complex and strangely simple.  Amos said that he had found it surfing the web the night before and that it was from some company’s interview or resume-submitting questions.

After several passionate whiteboarding sessions including members of our team, and any poor souls who walked by (I believe Mr. Young falls into this group), no one had a solution.  Eventually the whiteboard was clearred for more “important” work but the puzzle lingered with me.  On several occasions over the past year I have redrawn the matrix on a pad of paper and spent and hour or two trying to decipher the patterns and make sense of the answer tickling at edge of my brain.

This past week, while drifting off to sleep, the puzzle popped back into my head.  After a few moments a number of ideas I had had months before fell together in just the right way for me to FINALLY figure out a solution.  Eureka! (I mentally shouted) and got out of bed to find a piece of paper to work through some more examples and prove myself right.

The Puzzle

Given a 2D matrix such that each cell’s value is defined as follows:

>> The smallest non-negative integer not already present to the “left” or “above” <<

Determine an constant time function ( O(1) ) which given X and Y indices will return the value of the matrix cell at (X,Y).

For the visual people in the crowd, the top left corner or said matrix looks something like this:

First 8x8 cells of matrix puzzle

First 8x8 cells of matrix puzzle

The picture only shows the top 8×8 of the defined matrix as an example.  We can see that whatever f(x,y) you come up with needs to equal the following example values

f(0,0) = 0
f(1,0) = 1
f(2,0) = 2
f(3,0) = 3
f(3,1) = 2
f(3,2) = 1

The real key here is that the solution needs to function in constant time: O(1).  This means that computing the matrix value at (6,3) should be the same cost computationally as computing the matrix value at (10000000,4500005).

Anyone can write a program to compute the whole matrix out to your point (in theory) but can you come up with a better solution? In less than a year?

The Solution

Not just yet.  I will post my thought process and eventual solution soon in a separate post.

** I didn’t think of this puzzle, nor guarantee that I am remembering it correctly **
** If you know who did or have any corrections, please leave a comment  below **

Tagged with: ,

NaNoBloMo Recap Part Deux

Posted in challenge by benjaminplee on 11.30.10

Sum up the last month of blogging in 120 characters or less (gotta leave space for a URL on the end)?

15 posts in 30 days; one neglected prego wife.  Finishing what your start; priceless.

Best skill you developed by writing 15 blog posts in 30 day?

How to think of, research, and write a blog post without waking up the wife.

Really, I started thinking more about how I can contribute back to open source projects I use every day.  I have to credit the QUnit team for accepting my changes and providing great support and feedback.  Also, contributing to a project that has real users other than myself has made me consider how other developers look at my code and what they need help with.

** Adding funny pics to my posts **

Favorite post of the last 30 days?

Single post? Popping a Register from a Stack: QuickPiet Macros  Ever since the April Lambda Lounge meeting I keep coming back to Piet and love trying to hack higher level features into a stack based language.  It took a lot of failed attempts to figure out how to implement registers but it was a lot of fun.

Series?  QUnit w/ Rhino posts.  At every step of the way I thought “Oh this should be simple and clever” and winded up being “God that took longer than I thought, but at least it was clever”.  Given the traffic over the past couple weeks, it looks like there is a decent amount of interest in running QUnit w/ Rhino … hopefully these have been helpful.  I want to finish QUnit-CLI with some good examples and working on NodeJS.

Idea? Nate’s Clojure posts.  I have not had time to delve into Clojure like I would like but need to give credit to Nate.  I didn’t understand a lot of his posts but they were always interesting.  And beat me hands down in traffic.

Im in ur blogs writin ur posts

Would you do this again next year?

Not sure.  I want to keep posting and working on getting my ideas out and helping others but it is really hard to commit to an every-other day post regiment.  I think a much better frequency would be 1 every week or so.

Which posts did you half-ass?

Pro Tips: IE Caching Can ByteNotes to self: Keep SVN in sync w/ Git The Poor Man’s Way, and Programming Anti-Patterns: Releasing Cthulhu.  Honestly, these were cop-out posts.  I know I will go back at reference them at some point, but I am not sure anyone else will.  See the previous question.

** Oh, and this post; kinda **

Any last words before spending the coming months trying to forget that you ever did this?

Peace Out!






Tagged with:

NaNoBloMo Recap

Posted in Uncategorized by youngnh on 11.29.10

Sum up the last month of blogging in 120 characters or less (gotta leave space for a URL on the end):

Clojure solves programs naturally, elegantly and — holy crap! it’s 10 o’clock at night and none of my ideas panned out.

Best skill you developed by writing 15 blog posts in 30 days:

Formulating ideas and writing them down helps me break them down. I always felt like I had the quintessential software skill of “breaking the problem down”, but this excercise really taught me that is a separate skill from making my problems smaller. To belabor the point, one approach leaves you with a lot of problems that you have to solve, and the other is the excercise of ignoring a lot of solutions. I have written posts on ideas I thought were small and elegant, but they scrolled in at 5 or 6 screens of text. I tried not to do that this month, and in the process, felt like I got better at extracting smaller problems from large ones.

Favorite post of the last 30 days:

I really enjoyed writing the HP-15C program. The manual was something that took me some searching to find, so it was with great pleasure that I uploaded it to our site for others to find, and it was a fun challenge to write a program in 400-something bytes when every digit is an instruction.

Would you do this again next year?

I would commit to a less-demanding writing schedule. Considering that last year I stone-cold quit NaNoBloMo after maybe 2 posts, I’m really happy that I stuck it out until the end this year. I’m not terribly interested in being a pundit and even though I’ve got a lot of opinions, what I wanted to do with this month was write about writing software. There are new killer Clojure libraries emerging daily. It’s satisfying to use what someone else wrote to solve a problem. It’s personally instructive to try and fathom their design decisions. It’s enduringly useful to others to have concrete examples of good software available.

Having to post something every 2 days is too strict. The amount of time required to produce a post every 2 days was exactly right, the problem came when I failed to get anything working in the 3-4 hours a night I spent fiddling with stuff. Starting out I had a grand idea planned and outlined how every two days I’d move on to a new topic and use some new Clojure library to address that day’s topic, but I ran into issues after the first post and never got back on track. I think a post every 4 days would be a good amount. Enough time to queue up posts if things go swimmingly, and enough to recover and take a new tack if they don’t.

Which posts did you half-ass?

I started early, my fifth post, Start Tomcat from the REPL was an old text file I had lying around in case I ever had to actually do that again. I cleaned it up for an easy post. My Oracle post was the same way, the only difference is the old text file the Oracle post came from represented weeks of effort and failure and forum posts and hair pulling and lots of swearing. I’ve got a lot more old text files on installing Oracle for semantic technologies. I’m glad I didn’t use them.

Chasing the Sun, was one of my favorite posts since it led to a lot of interesting study for me and pointed towards a solution to a long-standing challenge of Ben’s. It was a half-assed post that I started writing maybe an hour before publishing. I had spent all day working on something else that didn’t turn out. That post contained no code, no real grasp of the astronomical concepts, just me plugging numbers into online calculators.

Copyright 1988 is as half-assed as it comes. I click-clacked that one out after getting home from work on a Friday, minutes before rushing out the door to catch the latest Harry Potter film with friends.

I didn’t half-ass the Konquest post, I just couldn’t get to an elegant, complete solution so I think it came off as half-finished.

Any last words before spending the coming months trying to forget that you ever did this?

I’ll have it known that my co-blogger Ben (if he doesn’t stumble at the finishing line) beat me handily at getting his posts in on time and deserves the TwoGuys NaNoBloMo trophy.

Submitting too close to midnight bit me twice and those posts appeared a day later than they were due. I submitted a post 7 minutes before midnight on November 9th, but unbeknownst to me our blog (at least my profile) was set to Eastern time, so it was published with a November 10th timestamp. I immediately rectified the timezone problem, but 3 minutes before midnight on the Saturday after Thanksgiving it totally slipped my mind that I was in Portland, Oregon. So that post showed up on an even numbered day as well.

Java 6 Scripting is no js.jar

Posted in java, javascript by benjaminplee on 11.28.10


Monkey Riding Dog

QUnit-CLI riding a Dog

Today I wanted to put together a QUnit-CLI example that leveraged Java 6’s included scripting features.  Seeing as the Java 6 JDK includes a recent version of Rhino as its primary JavaScript engine, I thought this would be a piece of cake.  Wrong.


To the javax.script package’s credit, Creating a new scripting engine and evaluating some script code is dead simple.  Example below from Oracle’s own pages

import javax.script.*;

public class EvalFile {
  public static void main(String[] args) throws Exception {
    // create a script engine manager
    ScriptEngineManager factory = new ScriptEngineManager();

    // create JavaScript engine
    ScriptEngine engine = factory.getEngineByName("JavaScript");

    // evaluate JavaScript code from given file - specified by first argument

The trouble came into play when I ran QUnit-CLI ‘s Rhino based suite.js file.   Ka-blew-ey!

Exception in thread "main" javax.script.ScriptException: 
    ReferenceError: "load" is not defined. (#1) in  at line number 1
  at com.sun.script.javascript.RhinoScriptEngine.eval(
  at javax.script.AbstractScriptEngine.eval(
  at Java6RhinoRunner.load(
  at Java6RhinoRunner.main(

It turns out that scripts running from in a Rhino Shell environment have access to extra functions that are not directly provided when executing embedded from Java.  The top-level “load” function which is used to load additional JavaScript files from the Rhino Shell is not directly available when running from the scripting engine.

It turns out, I am not the only one with this problem.  My solution was to bind an additional object with a Java-based “load” function and add a new top-level “load” function to the JavaScript scope that invokes the Java code.

import javax.script.*;

public class Java6RhinoRunner {
  public static void main(String[] args) throws ScriptException {
    new Java6RhinoRunner().load(args[0]);

  private final ScriptEngine engine;

  public Java6RhinoRunner() throws ScriptException {
    ScriptEngineManager factory = new ScriptEngineManager();
    this.engine = factory.getEngineByName("JavaScript");

    this.engine.put("Java6RhinoRunner", this);
    this.engine.eval("function load(filename) { Java6RhinoRunner.load(filename); }");

  public void load(String filename) throws ScriptException {
    try {
      this.engine.eval(new FileReader(filename));
    catch(FileNotFoundException e) {
      throw new RuntimeException("Error loading javascript file: " + filename, e);

To make matters worse, from the Rhino Shell, the “print” function will output the given text to standard output with a newline character.  As far as I can tell there isn’t a non-newline print command available on the Shell.  Annoyingly, when running from Java both print and println are available and tied to their common java behaviors.  This means that my suite.js code which uses “print” needs to use “println” when running from Java.  My first thought was to override print to execute println from my Java runner, but it looks like these basic top-level functions can’ be redefined from JavaScript.

this.engine.eval("function print(message) { println(message); }");

(no errors at runtime, but didn’t work)

The solution was to use add a level of indirection to my suite.js

var out = (typeof println !== "undefined") ? println : print;
out("FAIL - " + name); // used to be a call to print directly

Now we have suit.js running from Rhino embedded within the Java 6 JDK … but things are perfect.  The current code throws “Inappropriate array length” errors for a few QUnit tests.  I will be looking into these next.

Probability of Konquest

Posted in Uncategorized by youngnh on 11.28.10

I really like the KDE game, Konquest. It reminds me of another game I like, KDice. KDice has a handy table reference to tell what the odds of an attack succeeding are. Calculating the odds of winning a confrontation in Konquest is, undeniably, more complex.

First, a little about the calculation of a winner in Konquest. There are two sides to every confrontation, an attacker and a defender. Each has a number of ships, and each has a “Kill Percentage”, a measure of the probability that they will destroy an enemy ship. The game conducts the battle by having each side “roll” in turn to determine if an opposing ship is destroyed. First the defender rolls to see whether they destroyed a ship or not, then the attacker. When one side is destroyed, the remaining side is the victor.

It’s pretty easy to determine the probability of successfully attacking an undefended planet. Likewise, there’s no battle if no fleet attacks. So we’ll start with a 1 v 1 battle where both sides have a 50% kill percentage. The ways in which the battle could be resolved are:

d kill, a doesn’t roll = d wins 0.5000000
d miss, a kills = a wins 0.2500000
d miss, a miss, d kill = d wins 0.1250000
d miss, a miss, d miss, a kill = a wins 0.0625000
d miss x N, a miss x N, d kill = d wins (1-dkp)^N * (1-akp)^N * dkp
d miss x N+1, a miss x N, a kill = a wins (1-dkp)^N+1 * (1-akp)^N * akp

N doesn’t have to get very large before the probability of those outcomes quickly reaches zero.

Rounding to 4 digits, I found that the odds of a 1v1 matchup going 22 rolls or more is 0%.
Adding together the probabilities of all outcomes, I got 66.6667% chance that the defense would hold against the attacker.

So there’s only a 1 in 3 chance of an attacker winning an otherwise even matchup. First strike is a valuable advantage in Konquest.

If the attacker sends forces with a better kill percentage, say 60% against a defending force of 50%, I calculate the odds of attacker winning at 43.75%.

If the attacker doubles his forces, 2 attackers versus 1 defender, the situation changes a bit. The ways in which the battle could be resolved are:

d kill, a kill = a wins 0.250000
d kill, a miss, d wins the 1v1 = d wins 0.166667
d kill, a miss, a wins 1v1 = a wins 0.083334
d miss, a kill = a wins 0.250000

and for each of the above outcomes, there could be N misses before them:

d miss x N, a miss x N, d kill, a kill = a wins
d miss x N, a miss x N, d kill, a miss, d wins the 1v1 = d wins
d miss x N, a miss x N, d kill, a miss, a wins the 1v1 = a wins
d miss x N, a miss x N, d miss, a kill = a wins

This drops the percentage significantly, but it’s midnight and this post is due, so check back later to see how much.

QUnit-CLI: Running QUnit with Rhino

Posted in git, javascript, software testing by benjaminplee on 11.26.10

Rhino - wikimediaPreviously I talked about wanting to run QUnit outside the browser and about some issues I ran into.  Finally, I have QUnit running from the command line: QUnit-CLI

After a good deal of hacking and a push from jzaefferer, I gotten the example code in QUnit-CLI to run using Rhino and no browser in sight.  This isn’t a complete substitute for in-browser testing, but makes integration with build servers and faster feedback possible.

/projects/qunit-cli/js suite.js
PASS - Adding numbers
FAIL - Subtracting numbers
PASS|OK|subtraction function exists|
FAIL|EQ|Intended bug!!!|Expected: 0, Actual: -2
PASS - module without setup/teardown (default)
PASS - expect in testPASS - expect in test
PASS - module with setup
PASS - module with setup/teardown
PASS - module without setup/teardown
PASS - scope check
PASS - scope check
PASS - modify testEnvironment
PASS - testEnvironment reset for next test
PASS - scope check
PASS - modify testEnvironment
PASS - testEnvironment reset for next test
PASS - makeurl working
PASS - makeurl working with settings from testEnvironment
PASS - each test can extend the module testEnvironment
PASS - jsDump output
PASS - raises
PASS - mod2
PASS - reset runs assertions
PASS - reset runs assertions2
PASS: 22  FAIL: 1  TOTAL: 23
Finished in 0.161 seconds.

The first hurdle was adding guards around all QUnit.js’s references to setTimeout, setInterval, and other browser/document specific objects.  In addition I extended the test.js browser checks to include all of the asynchronous tests and fixture tests.  Finally I cleaned up a bit of the jsDump code to work better with varying object call chains.  My alterations can be found on my fork here.

The second hurdle was getting QUnit-CLI using my modified version of QUnit.js and adjusting how Rhino errors are handled.  Adding a QUnit submodule to the QUnit-CLI git repository easily fixed the first (I previously posted my notes on git submodules and fixed branches).  QUnit.js’s borrowed jsDump code is used to “pretty-print” objects in test messages.  jzaefferer ran into an issue when running QUnit’s own tests through QUnit-CLI resulting in the cryptic error:

js: "../qunit/qunit.js", line 1021: Java class "[B" has no public instance field or method named "setInterval".
at ../qunit/qunit.js:1021
at ../qunit/qunit.js:1002
at ../qunit/qunit.js:1085
at ../qunit/qunit.js:1085
at ../qunit/qunit.js:1085
at ../qunit/qunit.js:110
at ../qunit/qunit.js:712 (process)
at ../qunit/qunit.js:304
at suite.js:84

It turns out that errors objects (e.g. ReferenceError) throw in Rhino include an additional property of rhinoException which points to the underlying Java exception that was actually thrown.  The error we saw is generated when the jsDump code walks the error object tree down to a byte array off of the exception.  Property requests executed against this byte array throw the Java error above, even if they are done part of a typeof check, e.g.

var property_exists = (typeof !== 'undefined');

Once I figured this out, I wrapped the object parser inside QUnit.jsDump to properly pretty-print error objects and delegate to the original code for any other type of object.

var current_object_parser = QUnit.jsDump.parsers.object;
QUnit.jsDump.setParser('object', function(obj) {
  if(typeof obj.rhinoException !== 'undefined') {
    return + " { message: '" + obj.message + "', fileName: '" + obj.fileName + "', lineNumber: " + obj.lineNumber + " }";
  else {
    return current_object_parser(obj);

With these changes we have a decent command line executable test suite runner for QUnit.  With a bit more work QUnit-CLI will hopefully be able to print Ant/JUnit style XML output and/or include stack traces when errors bubble out of test code.

Tagged with: , , , ,

a small stack

Posted in Uncategorized by youngnh on 11.25.10

This Thanksgiving, I’m thankful for modern computer architectures.

Ben’s post on Piet and dealing with it’s stack prompted me to dig up my old HP-15C calculator, a relic my father handed down to me which also operates on a stack architecture. If you’re interested in all of its capablities, you can download the pdf manual, but in a nutshell, the calculator has a fixed size stack and 67 7-byte registers.

The stack’s size is fixed at 4, each position on the stack is a 7-byte register, called the x, y, z and t registers. Push more than 4 numbers onto it and the first items will fall off the end. t is the bottom of the stack, and x is the top. The number shown in the HP-15C’s display is always the x-register. Extra storage is provided by the 67 addressable registers. The registers are divided into data and program registers. The exact allocation of each is changeable, but by default 20 registers are allocated for data, 46 are registered for program instructions and 1 is special, called the index register. The data registers are accessed and written to using the RCL and STO buttons followed by a register address. Register addresses are the numbers 0-9 or .0-.9 (a decimal key followed by a digit key).

What to Write

As an excercise in programming the HP-15C, I decided to tackle Ben’s sunwalker challenge. I dug into the Explanatory Supplement to the Astronomical Almanac which had equations for roughly calculating the position of the sun relative to the earth for any day within two hundred years of the latest epoch, the year 2000.

The equations will give us the Right Ascension and Declination of the Sun which is the first step towards pinpointing where in the sky an observer from Earth would see it.

To do so, we start with the Julian Date of the day in question, JD.
From that, we’d like to calculate where in it’s ecliptic, the Sun is. This measurement is called λ.

λ = L + 1.915 sin G + 0.020 sin 2 G

Where L is the mean longitude corrected for aberration, and G is the mean anomaly.

L = 280.460 + 36000.770 T
G = 357.528 + 35999.050 T

T is the number of centuries since the epoch. Along with T, there’s only one other number we need to calculate, ε, the obliquity of the ecliptic.

T = JD - 2451545.0 / 36525
ε = 23.4393 - 0.01300 T

Having calculated the Sun’s ecliptic longitude, we can then convert it’s position into a position on the Celestial Sphere relative to the center of the Earth, given as right ascension, α, and declination, δ.

tan α = cos ε sin L / cos L
sin δ = sin ε sin L

Get to the Program Already

In pseudo-code, the program looks like this:

RCL .1
* +
STO .3

This is the calculation of G, and it pushes two numbers onto the stack, retrieves T from the .1 register, multiplies and adds and then stores the result for further calculations to use in the .3 register.

Each digit of the numbers, however corresponds to a single-byte instruction. RCL and STO operations consume 2 bytes. Here’s the whole listing in three columns, the machine instruction, the corresponding keyboard input and the pseudo-code equivalent:

001 - 42,21,11     f LBL A     A:         -- start program labeled A
002 -    45  0     RCL 0       RCL 0      -- fetch JD from register 0
003 -        2     2                      -- calculate T
004 -        4     4
005 -        5     5
006 -        1     1
007 -        5     5
008 -        4     4
009 -        5     5           2451545.0
010 -       30     -           -
011 -        3     3
012 -        6     6
013 -        5     5
014 -        2     2
015 -        5     5           36525
016 -       10     /           /
017 -    44 .1     STO .1      STO .1     -- store T in register .1
018 -        2     2                      -- calculate L
019 -        8     8
020 -        0     0
021 -       48     .
022 -        6     6           280.460
023 -       36     ENTER
024 -        3     3
025 -        6     6
026 -        0     0
027 -        0     0
028 -        0     0
029 -       48     .
030 -        7     7
031 -        7     8           36000.770
032 -    45 .1     RCL .1      RCL .1
033 -       20     *           *
034 -       40     +           +
035 -    44 .2     STO .2      STO .2     -- store L in register .2
036 -        3     3                      -- calculate G
037 -        5     5
038 -        7     7
039 -       48     .
040 -        5     5
041 -        2     2
042 -        8     8           357.528
043 -       36     ENTER
044 -        3     3
045 -        5     5
046 -        9     9
047 -        9     9
048 -        9     9
049 -       48     .
050 -        0     0
051 -        5     5           35999.050
052 -    45 .1     RCL .1      RCL .1
053 -       20     *           *
054 -       40     +           +
055 -    44 .3     STO .3      STO .3     -- store G in register .3
056 -    45 .2     RCL .2      RCL .2     -- calculate λ
057 -        1     1
058 -       48     .
059 -        9     9
060 -        1     1
061 -        5     5           1.915
062 -    45 .3     RCL .3      RCL .3
063 -       23     sin         sin
064 -       20     *           *
065 -       40     +           +
066 -       48     .
067 -        0     0
068 -        2     2           0.020
069 -       36     ENTER
070 -        2     2           2
071 -    45 .3     RCL .3      RCL .3
072 -       20     *           *
073 -       23     sin         sin
074 -       20     *           *
075 -       40     +           +
076 -    44 .4     STO .4      STO .4     -- store λ in register .4
077 -        2     2                      -- calculate ε
078 -        3     3
079 -       48     .
080 -        4     4
081 -        3     3
082 -        9     9
083 -        3     3           23.4393
084 -       36     ENTER
085 -       48     .
086 -        0     0
087 -        1     1
088 -        3     3           0.01300
089 -    45 .1     RCL .1      RCL .1
090 -       20     *           *
091 -       40     +           +
092 -    44 .5     STO .5      STO .5     -- store ε in register .5
093 -       24     cos         cos        -- calcuate α
094 -    45 .4     RCL .4      RCL .4
095 -       23     sin         sin
096 -       20     *           *
097 -    45 .4     RCL .4      RCL .4
098 -       24     cos         cos
099 -       10     /           /
100 -   43  25     tan-1       tan-1
101 -    44  1     STO 1       STO 1      -- store α in register 1
102 -    45 .5     RCL .5      RCL .5     -- calculate δ
103 -       23     sin         sin
104 -    45 .4     RCL .4      RCL .4
105 -       23     sin         sin
106 -       20     *           *
107 -   43  23     sin-1       sin-1
108 -    44  2     STO 2       STO 2      -- store δ in register 2

Help! I rooted my evo, now what do I do?

Posted in Uncategorized by benjaminplee on 11.24.10

A few weeks ago I rooted my HTC Evo 4G using the unrevoked 3 tool to flash my phone’s firmware and allow full root access to the internals.  The unrevoked app was one of the best user experiences I have seen in a while (walks you through each step with a nice clean interface).  Everything went great until the end when I was left wondering…

Am I done?  What do I do now?

Mount the file system as root

From the great Droid Incredible rooting tutortial over

  1. Turn the phone off
  2. Reboot the phone by holding down the power button and down-volume button
  3. From the menu, select recovery
  4. After the phone boots into recovery mode, select partitions
  5. Select mount /system
  6. Now, from your machine (with the android sdk tools installed) execute “adb shell”
  7. Now your are connected with root access

Wireless Tether

I had trouble with the Android Wifi-Tether app on the app store so I downloaded the latest code from the Google Code homepage.  Install, enable access control (so that you can approve/deny anyone connecting by MAC) and go!


This post has nothing to do with Clojure or Lisp.  Nada.  Zip.  Zilch.
This post has no opinion of Richard Stallman.  Nada. Zip. Zilch.

Tagged with: , , ,

Installation of the Joseki SPARQL Endpoint in front of Oracle on Ubuntu

Posted in configuration by youngnh on 11.23.10

Here’s one from my archives. It was a bitch to come by, so hopefully this will help some other poor soul tasked with setting up a HTTP interface to Oracle’s semantic store.


First, install Oracle on Ubuntu. That’s a pain, and only partially covered elsewhere. My notes on that subject, however, are enough for an entire months worth of blog posts, so I’m saving them for next November.

Once you’re done with the first step, you’ll want to enable semantic support, install a semantic network, maybe create a model or two, populate them and then make them queryable with a shiny SPARQL web service endpoint.

To enable Oracle’s semantic support (from here):

sqlplus / as SYSDBA

To create a semantic network (from here):

  DATAFILE '/u01/app/oracle/oradata/tseval/rdf_tblspace.dat' SIZE 1024M REUSE


Create a user in Oracle and grant them privileges:

create user rdfuser
identified by rdfuser
default tablespace users
temporary tablespace temp;

grant connect to rdfuser;

SPARQL Endpoint

Install Tomcat 6:

sudo apt-get install tomcat6

Download Joseki 3.4.0 and the latest Jena adaptor for Oracle (from here and here):

mv Joseki-3.4.0 joseki  

mkdir jena_adaptor
cd jena_adaptor
unzip ../

The Joseki web app must be carefully put together using files from each. Copy a directory from joseki as a starting directory to construct the web apps:

cp -R joseki/webapps/joseki joseki.war.d
cp -R joseki/lib joseki.war.d/WEB-INF

And copy away:

cp jena_adaptor/joseki/* joseki.war.d
cp jena_adaptor/web/* joseki.war.d/WEB-INF
cp jena_adaptor/jar/* joseki.war.d/WEB-INF/lib

The sdordfclient.jar in the jena_adaptor has since been superceded and doesn’t work with Tomcat anyway (insert grumblings about WebLogic here). I got my hands on a copy of the latest version thanks to having sweet contacts inside the Oracle mothership, if you do too, you’ll want to put that in there. If you don’t, you should give up now and make something of your life.

The webapp needs Oracle’s sdordf.jar from your installation:

cp $ORACLE_HOME/md/jlib/sdordf.jar joseki.war.d/WEB-INF/lib
cp $ORACLE_HOME/jdbc/lib/ojdbc6.jar joseki.war.d/WEB-INF/lib

And Joseki comes with a replacement for Tomcat’s default servlet-api jar:

rm joseki.war.d/WEB-INF/lib/servlet-api-2.5.jar
mv joseki.war.d/WEB-INF/lib/servlet-api-2.5-6.1.10.jar /usr/share/java
cd /usr/share/tomcat6/lib
rm servlet-api-2.5.jar
ln -s ../../java/servlet-api-2.5-6.1.10.jar servlet-api-2.5.jar

Next, add this file to make an Oracle datasource that Oracle’s Joseki service will look for:

<?xml version="1.0" encoding="UTF-8"?>
  <Resource name="OracleSemDS"
            validationQuery="select 1 from dual"

Also, I’d bump up the number of connections in Joseki’s connection pool

<#oracle> rdf:type oracle:Dataset;
    joseki:poolSize     30 ;         ## Number of concurrent connections allowed to this dataset.
    [ a oracle:OracleConnection ;
    oracle:defaultModel [ oracle:firstModel "M1" ] .

Verify that your directory structure looks like so:






Create the joseki war file:

cd joseki.war.d
jar cvf ../joseki.war .

Deploy it:

mv joseki.war /var/lib/tomcat6/webapps

Goodluck and Godspeed.

Tagged with: , , ,