private static String encrypt(String encryptMe, byte[] cryptKey, SecretKey secretKey, byte[] iv){
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE");
cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));
byte[] raw = encryptMe.toString().getBytes("ASCII");
if(log.isDebugEnabled())log.debug("unencrypted bytes: " + raw.length);
byte[] cipherText = new byte[cipher.getOutputSize(raw.length)];
int ctLength = cipher.update(raw, 0, raw.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
if(log.isDebugEnabled())log.debug("ctLength: " + ctLength);
if(log.isDebugEnabled())log.debug("cipherText Length: " + cipherText.length);
//raw = cipher.doFinal(raw, 0, raw.length);
byte[] copy = new byte[ctLength];
System.arraycopy(cipherText, 0, copy, 0, ctLength);
String encrypted = new String(new Base64().encode(copy), "US-ASCII");
return encrypted;
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
Sunday, April 04, 2010
AES Encryption in Java
Friday, April 02, 2010
what's in your history?
206 hadoop
44
27 ls
23 cd
18 su
17 grep
15 tac
11 pwd
10 exit
8 env
5 less
4 /mnt/hadoop/hbase-0.20.3/bin/hbase
4 man
4 ifconfig
3 telnet
3 start-dfs.sh
3 source
3 mount
3 ant
2 vi
Tuesday, February 23, 2010
Webscale Computing and Hadoop
Hadoop is an incredibly rich software stack consisting of three main pieces:
- The Hadoop Distributed File System (HDFS)
- A Map/Reduce infrastructure consisting of Daemons that layer services on top of HDFS
- A set of APIs allowing a data processing task to be split into simple Map and Reduce phases
If one was to read the description of map/reduce one might conclude that it is pretty much nonsense. In fact, it sounds to trivial to even be called an algorithm. Put things into groups, operate on the groups. Big deal. It sounds pretty much like common sense. Until you work with Hadoop, you really cannot appreciate all of the benefits that the Hadoop stack brings. It's really the collective benefits of the entire stack that make for the game changing experience that programming with Hadoop really is.
With problems of processing huge datasets, the devil is in the details. Hadoop provides a framework that removes all of the annoying complexity associated with big data sets. In essence you write two simple methods and from that point on you don't care much whether you are operating on 1 byte or 1 TB. This is possible in large part because HDFS allows you to think of terrabytes worth of data as a simple URL such as hdfs://namenode/user/geoff/BigDataSet. HDFS takes care of replicating your data, and figuring out where the data blocks actually reside in the cluster. As an added bonus, Hadoop automatically deals with nuances such as the files being zipped. But wait, there's more. From the hadoop command line, you can run commands to cat and grep these URLs, again, acting as if they were simple local files.
For me, one of the most interesting side effects of running a hadoop cluster has been how it changes ones ability to interact with peers on a webscale computing project. You can now shoot your co-worker a URL to a 200GB file, and they can poke and prod at the contents by doing things like "hadoop fs -text hdfs://namenode/user/geoff/BigData".
I'll try to write more about this later, but for now suffice it to say that Hadoop is quite exciting to work with. I think the criticism by Michael Stonebreaker have totally missed the point of what a good implementation of a map/reduce framework can yield, probably because their criticism focused on the map/reduce algorithm, which in and of itself is trivial. And that's really the point. It's really all about the tools and the entire stack that make map/reduce simply a "part of this complete breakfast" when it comes to hadoop. So don't forget the toast, juice, and yummy Cheerios!
Sunday, February 21, 2010
HATEOAS - Hypermedia As The Engine Of Application State
I was certainly confused for a long time about what constitutes a RESTful system. Isn't anything that has a URL RESTful? Definitely not, as the presence of resource identifier is just one of several properties that make a system RESTful. Fielding has recently written this article listing the properties he sees as essential to a RESTful system. After working quite a bit on the RESTful system for NextDB.net, it seems that me that the principle of Hypermedia As The Engine Of Application State (HATEOAS), identified on the original dissertation section 5.1.5, might be the most important principle of all. Incidentally, of all the properties outlines in the recent article, Fielding chose to title the article "REST APIs Must be Hypertext Driven". To my mind, that confirms my hunch that HATEOAS is perhaps the least understood principle of REST, and the principle in need of the most discussion and explanation.
The essence of HATEOAS is that the client needs to understand as little as possible. In essence, this is quite similar to the experience a human requires when he browses a website. In order to move from one page to the next, we must be given links that we can navigate. This is our common experience on web pages. Consider an alternative, and less user friendly, scenario in which the home page simply consisted of a set of instructions (an API, if you will). One instruction might read "To view articles about sports, visit a URL consisting of "http://sitename/topics?name=topic-name" and replace topic-name with 'SPORTS'". You would be forced to manually construct the URL and enter it into the browser. The notion of such a website seems absurd, and yet it describes the scenario common to RPC or "fake REST" APIs in which the client is responsible for constructing the state-transition links rather than being handed a hypermedia document that provides the available state transitions.
Quoting Fielding: "...all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations".
This is an interesting article that shows how non-HTML hypermedia can be used in keeping with HATEOAS. However, I think there are excellent reasons why Plain Old HTML (POH) is the best hypermedia choice for use with RESTful systems:
- HTML was made for hypermedia (it has well known structures for encoding links)
- Your mom knows what HTML is
- By using POH for HATEOAS, your RESTful system's content can be indexed by search engines
- You can easily view and traverse your system states using a web browser
http://nextdb.net/nextdb/rest/geoff/testchars/lines/style/newspaper-a
Monday, February 15, 2010
Spam Bucket
UPDATE: I have the answer: "A LOT"
"Salad Man", I commend you! "get three inches on your dick!" is a noble spam to leave on my blog, but I am dissapointed you did not include a video!!!
Saturday, February 13, 2010
NextDB REST tables
<iframe src='http://www.nextdb.net/nextdb/rest/geoff/vids/sk8;~cols=PK,video_CONTENT_TYPE,video_FID/style/newspaper-a/pgsz/3' />
Friday, February 12, 2010
An update on JTIdy and XSLT
Thursday, January 21, 2010
Character Encoding Hell
On the other hand, Jetty *does* assume the URL is UTF-8 percent encoded (love jetty!!). So without some config tweaks, don't expect servlet containers to *uniformly* deliver properly decoded UTF-8 strings.
My latest installment of UTF-8 Hell comes as I implement some more REST capabilities for Nextdb.net. Here is the content of a message I just posted to Paul Sandoz of Jersey fame (man, that guy must never sleep. he is *on the ball* on the Jersey mailing list). Mad props to Jersey. It is just killer. But I digress:
I got to the bottom of this by trying to unmarshal the string in three different ways. As I already mentioned the first way was just to call FormDataBodyPart.getValue().
Then I tried two other ways, both of which correctly unmarshalled the bytes from the POST. As supporting information, here is the CURL line I was testing with, and an excerpt from the CURL trace, showing the proper bytes being posted.
curl --trace traced -F line=てすと http://localhost:8080/nextdb/
The 9 bytes highlighted below are the three japanese characters.
=> Send data, 148 bytes (0x94)
0000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 63 61 --------------ca
0020: 33 32 31 65 31 30 39 66 36 37 0d 0a 43 6f 6e 74 321e109f67..Cont
0030: 65 6e 74 2d 44 69 73 70 6f 73 69 74 69 6f 6e 3a ent-Disposition:
0040: 20 66 6f 72 6d 2d 64 61 74 61 3b 20 6e 61 6d 65 form-data; name
0050: 3d 22 6c 69 6e 65 22 0d 0a 0d 0a e3 81 a6 e3 81 ="line".........
0060: 99 e3 81 a8 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ......----------
0070: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0080: 2d 2d 2d 2d 63 61 33 32 31 65 31 30 39 66 36 37 ----ca321e109f67
0090: 2d 2d 0d 0a
Both of the following two methods will properly unmarshal the correct String:
method 1: use InputStream to get raw bytes
InputStream is = theFormDataBodyPart.
try {
byte[] bytes = Util.readInputStream(is, 1024 * 1024, 1024 * 1024 * 1024);
log.debug("this many bytes: " + bytes.length);
for(byte b:bytes){
log.debug(Integer.toHexString(
}
String s = new String(bytes, "UTF-8");
log.debug(s);
return s;
} catch (IOException ex) {
throw new RuntimeException(ex.
}
Method 2) use theFormDataBodyPart.
Cheers,
geoff
Monday, January 04, 2010
Well said....
A member of Parliament to Disraeli: "Sir, you will either die on the gallows or of some unspeakable disease." "That depends, Sir," said Disraeli, "whether I embrace your policies or your mistress."
"He had delusions of adequacy." - Walter Kerr
"He has all the virtues I dislike and none of the vices I admire." - Winston Churchill
"I have never killed a man, but I have read many obituaries with great pleasure." Clarence Darrow
"He has never been known to use a word that might send a reader to the dictionary." - William Faulkner (about Ernest Hemingway).
"Thank you for sending me a copy of your book; I'll waste no time reading it." - Moses Hadas
"I didn't attend the funeral, but I sent a nice letter saying I approved of it." - Mark Twain
"He has no enemies, but is intensely disliked by his friends." - Oscar Wilde
"I am enclosing two tickets to the first night of my new play; bring a friend.... if you have one." - George Bernard Shaw to Winston Churchill
"Cannot possibly attend first night, will attend second... if there is one." - Winston Churchill, in response.
"I feel so miserable without you; it's almost like having you here." - Stephen Bishop
"He is a self-made man and worships his creator." - John Bright
"I've just learned about his illness. Let's hope it's nothing trivial." - Irvin S. Cobb
"He is not only dull himself; he is the cause of dullness in others." - Samuel Johnson
"He is simply a shiver looking for a spine to run up." - Paul Keating
"In order to avoid being called a flirt, she always yielded easily." - Charles, Count Talleyrand
"He loves nature in spite of what it did to him." - Forrest Tucker
"Why do you sit there looking like an envelope without any address on it?" - Mark Twain
"His mother should have thrown him away and kept the stork." - Mae West
"Some cause happiness wherever they go; others, whenever they go." - Oscar Wilde
"He uses statistics as a drunken man uses lamp-posts... for support rather than illumination." - Andrew Lang (1844-1912)
"He has Van Gogh's ear for music." - Billy Wilder
"I've had a perfectly wonderful evening. But this wasn't it." - Groucho Marx
Wednesday, December 16, 2009
JavaOneRadio interview 2009
Sunday, December 13, 2009
Saturday, December 12, 2009
a==1 or 1==a
After going on the exact same bug hunt myself, many years ago, I kicked myself for not following his advice. I've coded all my Boolean expressions in the "literal on the left" style ever since, and the compiler has saved me many a bug hunt.
To that paradigm I now have a small addition to make. I've started coding my string equals comparisons in literal-left style as follows: "something".equals(a)
This has the nice effect warding off null pointer exceptions when a is null. I think this literal left style is better than (a+"").equals("something") which is another trick for warding off null values of a.
Friday, December 11, 2009
Keep the hot air flowing
Saturday, December 05, 2009
Keep it on the DL
Thursday, December 03, 2009
JTidy and handling HTML embedded in database strings
The problem is that if the user enters invalid XHTML, like they just throw <blort&rt; into their document, then the XSLT will crash. The problem is made gnarlier by the fact that the documents themselves are likely to be fragments (and in fact they have to be fragments so that when they appear in the context of the default HTML presentation that they get treated as a valid portion of the overall document). In other words, if the user puts tags around their document, you have to strip those body tags off, so that the default HTML presentation doesn't have a nested body.
Enter JTidy. The JTidy library is all about handling crapped-up HTML, and fixing it on the fly. The journey to getting JTidy working was longer than I expected due to an unpleasant interaction with Maven. So, despite the fact that I had the most recent version of JTidy on my Netbeans's project's classpath, when I used Maven to startup Jetty using the mvn Jetty plugin, I would get runtime errors complaining that the method I was trying to call (tidy.setPrintBodyOnly(true);) didn't exist. So, like any good bughunt, the fub began. I knew that Tidy.class was somehow sneaking into my runtime classpath. The first place I looked was my local .m2 repository -- no joy. Finally occured to me that this must be an internal inclusion of an old Tidy jar by maven. When I ran 'grep -r Tidy.class' on my maven directory, I found that maven's 'uber jar' (maven-core-2.0.7-uber.jar) did in fact contain the older version of JTidy. Turns out if you look at the internal dependencies for Maven, you find that it depends on an old version of JTidy. So I unzipped the uber-jar, replaced all the JTidy classes with the latest and greatest, rezipped the jar, and ...badabing badaboom...problem solved. Bing bang boom, very good have a drink.
The actual coding took less than 2 minutes. Argghh talk about an 80/20 rule. Anyhow, JTidy does exactly what I want. Fix any crufted HTML that the user might enter, and then extract only the content of the body element (and even better, if the user doesn't include a body, JTidy fixes that first). So it all boils down to this (just to print the tidied content):
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setPrintBodyOnly(true);
tidy.parse(new ByteArrayInputStream((val+"").toString().getBytes()), System.out);
Epilogue: maybe blogger.com should start using Jquery. Ironically, this rich text editor threw up on some tags I typed into this post, and I had to spend a few minutes cleaning up the mess!!!
Thursday, November 26, 2009
Good news on C02 Emissions
Obama's announcement, combined with China's recent pledge, is the first good news I've heard on climate change -- ever! Happy Thanksgiving!
Wednesday, November 25, 2009
Viterbi Maximum Liklihood Decoding
"In the last decade, coding emphasis has been in the area of convolutional codes since in almost every application, convolutional codes outperform block codes for the same implementation complexity of the encoded-decoder. For satellite communications channels, forward error correction techniques can easily reduce the required SNR for specified error performance by 5 to 6dB. This coding gain can translated directly into an equivalent reduction in required satellite effective radiated power (EIRP), which consequently reduced satellite weight and cost."
After reviewing the Viterbi algorithm, I was curious about who this Viterbi guy was, anway. I'd also seen a chart in the Sklar book, attributed to the "Linkabit" corporation. Turns out Viterbi founded Linkabit, then later Qualcomm, an eventually donated $50 million to USC where the Viterbi school of engineering bears his name. Interesting story.
Oh, and it turns out the Viterbi algorithm does have applications to spell checking.
Sunday, November 22, 2009
Order-invariant Path Parameters with JSR-311 JAX-RS and Jersey
.../person/firstname/geoff/lastname/hendrey
.../person/lastname/hendrey/firstname/geoff
I've found that the best way to do this is to creat a single resource class, in this case Person, and to define subresource locator methods for "firstname/{firstname}" and "lastname/{lastname}". The trick is to return "this" in your subresource locator method, which affectively turns the subresource locators into a means to setting instance fields on the Person instance.
So when we look in the "PersonResource" class, our subresource locator method for 'firstname' is:
@Path("/person")
public class PersonResource{
private String firstname;
private String lastname;
@Path("firstname/{firstname}") //subresource
public Person getSubResource(@PathParam("firstname") String fname){
this.firstname=fname; //set instance field on this resource
return this;
}
@Path("lastname/{lastname}") //subresource
public Person getSubResource(@PathParam("lastname") String lname){
this.lastname=lname; //set instance field on this resource
return this;
}
}
The locator method for lastname follows the same patter. And that's all there is to it! I have not found this pattern covered or described in any of the docs for Jersey, but I have found it indespensible.
Creating "alias" URLs for Jersey JAX-RS JSR-311 resources
http://nextdb.net/nextdb/rest/home/{account}/db/{db}/tbl/{tbl}
for example: http://nextdb.net/nextdb/rest/home/geoff/db/testchars/tbl/lines
The "shortcut" URL would be: http://nextdb.net/nextdb/rest/{account}/{db}/{tbl}
for example http://nextdb.net/nextdb/rest/geoff/testchars/lines
There's a simple "trick" you can apply using JSR-311 to make your resource appear at two different URLs. First, start with your "fully qualified resource". For example, here is snippet:
@Path("/home/{account}/db/{db}/tbl/{tbl}")
public class TableResource extends AbstractSelectableResource{
@PathParam("account") protected String account;
@PathParam("db") protected String db;
@PathParam("tbl") protected String table;
...
Now, to make an "alias" or "shortcut" URL, just define a dummy class that extends the resource you want to make a shortcut to. The purpose of this class is simply to "mount" the resource on an additional URL. Be sure to include all the path parameters and their names must be identical.
@Path("/{account}/{db}/{tbl}")
public class ShortcutToTableResource extends TableResource{
//this class is intentionally empty
}
Now your resource will be available on both URLs!
Wednesday, November 11, 2009
Jamwiki
http://www.nextdb.net/wiki/en/REST
I wasted a lot of time on XWiki, which basically was bloated, didn't work well, and basically produces a constant stream of stack traces. JamWiki works really well, it's nice and clean.
Sunday, November 08, 2009
New ideas for REST in NextDB.net
peek:
support for relationships in REST URLs (calling them 'links')
...account/db/link/FRIENDSHIP/from/uname/john/to/uname/tom
The path parameters "from" and "to" describe the tail and the head of
the relationship, respectively. In other words, we can draw a
relationship as an arrow from one table to another table. This makes
'from' and 'to' the natural path parameters.
The REST URL above is equivalent to:
NAME=FIND_FRIEND;
ROW f1 FROM FRIEND;
ROW f2 FROM FRIEND;
f1 RELATED f2 VIA FRIENDSHIP;
WHERE(){
f1.uname='john' AND f2.uname='tom'
side of the relationship. The following URL would retrieve *all* of
john's friends.
..account/db/link/FRIENDSHIP/from/uname/john
is equivalent to:
NAME=FIND_FRIEND;
ROW f1 FROM FRIEND;
ROW f2 FROM FRIEND;
f1 RELATED f2 VIA FRIENDSHIP;
WHERE(TEXT name1){
f1.uname=${name1}
.../account/db/query/FIND_FRIEND/name1/john
So it all will play nicely with existing queries you have already
defined, and new ones you may define in the future.
I also intend to support cookies. So let's say you wanted to log a
user in via https, and then securely transmit his password with each
subsequent REST URL using regular HTTP (not https). First the user
logs in via a secure (httpS) rest access to a query you named LOGIN.
So the password below would not be in the clear, since the form on the
HTML page would GET to an HTTPS url. The URL is constructed
dynamically by the form on submission:
https://nextdb.net/...db/query/LOGIN/uname/geoff/pwd/xxxxxxx;set-cookie
the 'set-cookie' matrix parameter tells nextdb to return a set-cookie
HTTP header with a value equal to cypher('xxxxxxxx'). I.e., nextdb
will encrypt the value that was sent in your request's REST URL,
wherever it finds ;set-cookie, and tell the browser to pass a cookie
named 'pwd' (in this example) with a value that is the encrypted
version of whatever is in the REST URL for the password in the pwd/
{password} path parameter. The set-cookie matrix parameter can occur
at any path segment in the URL, and would be applied to whatever path
parameter is described by the path segment.
from that point on you can use regular rest URLs and nextdb will
substitute into your URL the encrypted cookie value. So you can use
URL's like this in your application, for later actions that require a
user's password:
.../db/link/ACCOUNT_DETAILS/from/pwd/;get-cookie
The get-cookie matrix parameter int the URL allows an HTML page to be
designed with static URLs, into which nextdb will dynamically
substitute the URL path parameters with values sent by the browser as
cookies. It's a bit of a mind bender but this allows a site be
designed with static URLs. The only dynamic URL ever generated by the
app is the single login query that sets the pwd/{password} path
parameter.
so when nextdb receives the static URL above, it will first see that
the URL incudes a get-cookie matric paramter. NextDB will then look
for a cookie named 'pwd' sent by the browser (or other http client),
decrypt the cookie value, and place the value into the URL where it
finds the get-cookie matrix parameter:
.../db/link/ACCOUNT_DETAILS/from/pwd/xxxxxxxx/
The URL above is then equivalent to this NextQuery expression:
NAME=ACCOUNT_DETAILS;
ROW r1 FROM USER;
ROW r2 FROM ACCOUNT;
r1 RELATED r2 VIA MY_ACCOUNT;
WHERE(){
r1.pwd='xxxxxxxx'
The net effect of this new style of REST url for queries and relationship traversal is to vastly reduce the amount of code an applicaiton has to write, and hopefully to make nextdb accessible to HTML/front-end developers.
Native REST support in NextDB.net
Beeing down with a bad cold the last few days, ironically this has given me
some time to work with Jen from Dartmouth Design on using the REST features
to build some features for Project Have Hope. She has graciously offered to
share the preliminary results. So far we've used nextdb for creating
profiles of children to sponsor. The entire page, including the paging
links, profile data, and paypal buttons, is created by applying an XSLT
transformation to the table served up by nextdb. The result is sourced in an
iframe and loaded into a Joomla module. This appears to be a very nice way
to integrate nextdb content with Joomla. I'm also very stoked to see NextDB
used on such a worthy project.

You can read about the XSLT approach here:
http://www.nextdb.net/wiki/en/REST#XSLT_(reformatting_your_data%27s_presentation
This is the XSLT that is being used by Project Have Hope.
http://nextdb.net/nextdb/rest/dd/phh/config_files/row/1/xslt.xslt
I've just learned XSLT so I think there are many things that can be done
smarter, and there is also a bit of cruft template in the XSLT that is never
used (for example the 'append-pad' template is never used) and needs to be
cleaned up. But that aside, it's an amazingly small amount of XSLT
considering this XSLT is the *only* code required to bring together this
dynamic page.
Monday, August 03, 2009
Three Views of REST resources
@Provider
@Produces(MediaType.TEXT_HTML)
public class UsersProvider implements MessageBodyWriter{
@Override
public void writeTo(Users users, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMapparams, OutputStream os) throws IOException, WebApplicationException {
try {
JAXBContext jc = new JSONJAXBContext(JSONConfiguration.natural().build(), new Class[]{users.getClass()});//JAXBContext.newInstance(users.getClass());
DOMResult xml = new DOMResult();
jc.createMarshaller().marshal(users, xml);
StreamSource styleSheet = new StreamSource(getClass().getResourceAsStream("/stylesheet/Users.xsl"));
Transformer transformer = TransformerFactory.newInstance().newTransformer(styleSheet);
transformer.transform(new DOMSource(xml.getNode()), new StreamResult(os));
}catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
@Override
public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return (Users.class.isAssignableFrom(type) && mediaType.isCompatible(MediaType.TEXT_HTML_TYPE));
}
@Override
public long getSize(Users arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
return -1;
}
}
In the end it's actually quite easy, but what threw me off was that JAX-RS has built-in support for the serialization of List<t> where T is a JAXB annotated class. The problem is that my custom provider, which applies a stylesheet to the XSL necessarily bypasses the built-in support for collections of JAXB annotated classes. Therefore, the method in my resource can't return a List
<users>
<user>...</user>
<user>...</user>
<!-- etc -->
</users>
versus naming the accessor method in the plural produces (note redundant plural users):
<users>
<user&sgt;...</users>
<users>...</users>
<!-- etc -->
</users>
so here is the JAXB annotated "wrapper" class for use instead of returning a raw List
@XmlRootElement(name = "users")
public class Users {
private List
/**
* @return the users
*/
@XmlElement
public List
return users;
}
/**
* @param users the users to set
*/
public void setUsers(List
this.users = users;
}
}
then the Resource method just looks like this (note that it returns the Users wrapper class):
@GET
@Produces({MediaType.TEXT_HTML})
@Path("/users/{user}")
public Users getUsersHTML(@PathParam("user") String username) throws Exception {
Users users = new Users();
if(username.equalsIgnoreCase("*")){
users.setUsers(net.nextdb.SysAdminSearchAccounts.getUsers("%"));
}else{
users.setUsers(net.nextdb.SysAdminSearchAccounts.getUsers(username));
}
return users;
}
JAX-RS and Jersey
I'll probably wind up implementing my own providers for generating simple HTML pages and JSONP-HTML.
Tuesday, July 21, 2009
JSON, in retrospect
From: Geoff Hendrey
Sent: Wednesday, May 24, 2006 10:31 AM
To: Brent Hamby
Subject: Json questions
Hey dude,
I went to the json "see for yourself" page: http://www.json.org/example.html to compare the Json equivalent of XML.
I copied each of the examples into notepad and wrote down the size-on disk:
json size (bytes) XML size (bytes) (json size)/(XML size)
===================================================
604 630 95%
252 221 114%
630 656 96%
3554 10708 33%
898 1150 78%
AVG (json size)/(XML size)
=====================
83.2%
Based on an average size compaction to 83.2% of the XML size. Also, if you look at the 4th example they give (line 4 of the table above), they did a Json version of web.xml. Now web.xml is a notoriously bad XML design. It basically doesn't use ANY attributes, so you get pretty nasty tag bloat. So if we drop the 4th comparison, as being kinda silly, we get an average compaction to 95.4% of the original size. Is saving 4.5% really a big advantage?
I also saw several statements on the json web page that I would put in the "wacky" bin. This may just be personal preference, but I found the XML documents much easier to read than their json equivalents. The Json looks, to me, like "code", kinda like a snippet of PERL or something.
Anyway, it seems clear that being able to easily marshal an object representation of your data makes it much easier to develop software in any programming language. But it seems to me that json is munging this idea up with the wire format, which to me are orthogonal concerns.
Saturday, June 20, 2009
JavaScript downloaded function executor
- required YUI script and link tags, that are needed by YUI, are defined on my page richEditor.html. I need to be move said tags from head to body, because jQuery.load function only loads the body of the HTML page.
- said script and link tags *begin* downloading from yahoo when jQuery calls your load callback function. That's becuase richEditor.html itself has been downloaded by jQuery, but the said script and link tags referenced ON richEditor.html have only just begun asynchronously downloading. So if you need to access a function in one of the script tags that is downloading, you have no way to be sure the function has completed downloading.
Here is the Object:
function DownloadedFunctionCaller(funcToInvoke, waitMS, maxTries, _failHandler){
var funcToInvoke = funcToInvoke;
var waitMS = waitMS;
var maxTries = maxTries;
var failHandler = function(){
alert("Unable to access the network. Please reload the page or try again.");
}
if(null != _failHandler){
failHandler = _failHandler;
}
var that = this;
var tries = 0;
this.invoke = function(){
try{
funcToInvoke();
}catch(err){
if(++tries >= maxTries){
failHandler();
return;
}
setTimeout(that.invoke, waitMS);
}
}
}
and here is an example of using it to invoke a function named setEditor that is defined
in an external file, richEditor.html. The setEditor function will only work if all the YUI scripts are downloaded, hence the need to use the DonwloadedFunctionCaller
var div = $("<div></div>");
div.addClass("yui-skin-sam");
div.load("richEditor.html", null, function(content){
var invokeMe = function(){
setEditor("Script loaded and executed.");
}
new DownloadedFunctionCaller(invokeMe, 500,10,function(){
alert("failed to download rich text editor")
}).invoke();
});
If you click on this screengrab, to get a bette look at it, you will see that the text "script loaded and executed" has been set into the YUI editor's text area by the successful invocation of the setEditor method.
Saturday, May 23, 2009
random lines of poetry
I woke up early this morning around 6:30 thanks to Claritin-induced sleep deprivation. I started hacking on server code for automatically building "tables of contents" for very large database tables. I'm using a bunch of Yeats poems, and The Iliad as sample rows in the database. It makes debugging a lot more fun when the data is interesting. It's also a great way to read random lines of poetry. Here is a great stanza from the Iliad:
Generations of men are like the leaves.
In winter, winds blow them down to earth,
but then, when spring season comes again,
budding wood grows more. And so with men--
one generation grows, another dies away. (Iliad 6.181-5)
Did you know the phrase "another one bites the dust" is lifted from the Iliad?
"Grant that my sword may pierce the shirt of Hector about his heart, and that full many of his comrades may bite the dust as they fall dying round him."
Saturday, April 11, 2009
Tesla rocks...
http://www.techcrunch.com/2009/04/10/teslas-elon-musk-grows-a-pair-good-for-him/
It would be criminal if Tesla didn't receive the funding they need. To see a loser like GM sloshing in bailout funds is a sickening contrast.
Tuesday, March 31, 2009
Sunday, March 22, 2009
Back in one piece...
Actually, I just checked the DOT report for I-80:
"Enter Highway Number(s)
You can also call 1-800.427.7623 for current highway conditions. Mobile
This highway information is the latest reported as of Sunday, March 22, 2009 at 21:50 .
I 80
[IN NORTHERN CALIFORNIA & THE SIERRA NEVADA]
WESTBOUND TRAFFIC IS BEING HELD AT CISCO GROVE (PLACER CO) - DUE TO AN
ACCIDENT - MOTORISTS ARE ADVISED TO USE AN ALTERNATE ROUTE
CHAINS ARE REQUIRED ON ALL VEHICLES EXCEPT 4-WHEEL-DRIVE VEHICLES WITH SNOW
TIRES ON ALL 4 WHEELS FROM 1 MI EAST OF BAXTER (PLACERCO) TO THE
DONNER LAKE INTERCHANGE (NEVADA CO) "
Wednesday, March 18, 2009
Tuesday, March 17, 2009
Monday, March 16, 2009
Photos From Scotland
One of the most fascinating aspects of Edinburgh and Glascow was there role in the Arts and Crafts and Art Nuveau movements. Phoebe Anna Traquair (P.A.T) was one of the female artists who figured prominently in this movement. If you ever have a chance to visit the Mansfield Traquair church, do not miss it.
You can get a better look, here: http://www.mansfieldtraquair.org.uk/nav/cag02.html
If that doesn't blow your hair back, get a look at this amazing painting by P.A.T.. Oh, wait, take a second look, it isn't a painting! It's SILK EMPROIDERY!!

It's almost incomprehensible that a few years ago, the Mansfield Traquair church was being used as a brick storage facility. Thankfully, it was recently rescued an restored. For the life of me I cannot understand why P.A.T. and John Duncan are not better known. Please read this blog to see some more breathtaking work by P.A.T.
I am so awestruck by John Duncan's St. Bride that I recently aquired a canvas reproduction of it from an obscure source on the web. Here is a shot of it gracing my living room.
Scotland has lots of badass wildcats, which came to America as stowaways, and became the big Main Coon cats.
Sunday, March 15, 2009
Another Gem from William Morris
The wind's on the wold
And the night is a-cold,
And Thames runs chill
'Twixt mead and hill.
But kind and dear
Is the old house here
And my heart is warm
'Midst winter's harm.
Rest then and rest,
And think of the best
'Twixt summer and spring,
When all birds sing
In the town of the tree,
And ye in me
And scarce dare move,
Lest earth and its love
Should fade away
Ere the full of the day.
I am old and have seen
Many things that have been;
Both grief and peace
And wane and increase
No tale I tell
Of ill or well,
But this I say:
Night treadeth on day,
And for worst or best
Right good is rest.
ProPublica: Jouranlism in the public interest
Basically, none of the major news outlets can be trusted. This is just a fact. Remember before we went into Iraq how the New York Times ran breathless stories on Sadam's vast underground bunker complex. It was all just a load of shit.
So now I'm going try getting my news from ProPublica, because their mission is to reinvigorate investigative journalism.
Friday, March 13, 2009
Developers are starting to catch on!
http://blog.solutionset.com/wpmu/2009/03/11/nextdb-a-front-end-database-solution/
It's a great post, and I think it illustrates how easy nextdb is to learn, and use. Nextb is getting preety close to exiting alpha and entering Beta. During the Beta we will have our "subscribe" buttons up on the site. We are targeting price points that are basically below the noise for even a personal account, so affording nextdb should not be a problem for anyone.
Brent is busy developing and refining a new set of utilities for adding forms to your AJAX apps. The forms will automatically configure themselves based on the content of your table or query, and will be CSS friendly.
I'm working on a notification system that will allow you to receive email when data is inserted into a table. You'll be able to request digests, as well as create email templates that receive data from the inserted row in order to create a personalized, pretty email.
Sunday, January 25, 2009
ulimit -n .... the saga continues
Argghhh. Will this issue never end?
I've added "ulimit -n 100000" to my .bash_profile, and now I have confirmed that after logging into a new session, that the new ulimit of 100000 files is in effect.
I'm not happy with putting this in my .bash_profile, but the alternatives looked too dangerous and or flakey.



