-
Monkey patching in python
I was just reading an article about Martijn Pieters, who is a python expert, and he mentioned monkey patching I did not know what monkey patching is, so I googled it, and found a great answer on stack overflow Basically, it takes advantage of python’s class access philosophy. Unlike java, which has a strict access…
-
Java anchored regex
I just discovered this today when doing some regex in Java. When I first started doing regex in Java, I was surprised to learn that Java seems to treat all regular expressions as anchored. That is, if you have a string foobar and search for “foo” it will not match. This is different than grep,…
-
Solr DataImportHandler preImportDeleteQuery gotcha
One handy feature of the DataImportHandler in solr is that you can group documents by different entities. In the MKB we have a couple different kinds of entities we import – songs, albums, tvshows, etc. Sometimes we make a change or improvement to the underlying data of one type of entity, and want to test…
-
Pretty printing json
Here is a really simple way to pretty print some unformatted json $ echo ‘{“foo”: “lorem”, “bar”: “ipsum”}’ | python -mjson.tool { “bar”: “ipsum”, “foo”: “lorem” }
-
Using awk to sum rows of numbers
I have a script which takes a tab-delmited file for regression tests, and converts it xml. I want to do a sanity check, to make sure that the number of utterances in my xml files matches the number in the tab-delimited.txt file. I can do this in 2 lines in UNIX robert_felty$ wc -l samples2.txt…