In last week's tip on
using the NVelocity template formatting engine,
I described what to set to load a template from
an absolute path.
Here's the magic necessary to get NVelocity to load a template from an
embedded resource:
VelocityEngine engine = new VelocityEngine();
ExtendedProperties properties = new ExtendedProperties();
properties.AddProperty("resource.loader", "assembly");
properties.AddProperty("assembly.resource.loader.class",
"NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity");
properties.AddProperty("assembly.resource.loader.assembly", "StencilFormatter");
engine.Init(properties);
We've started using the NVelocity template formatting engine.
We were absolutely stymied for an hour, trying to figure
out how to get it working with an absolute path to the template file,
instead of the relative path shown in the documentation.
The trick is to set file.resource.loader.path.
Here's how to load C:\foo\bar\somefile.vm:
ExtendedProperties props = new ExtendedProperties();
props.AddProperty("file.resource.loader.path", new ArrayList(new string[]{".", "C:\\"}));
velocity.Init(props);
template = velocity.GetTemplate("foo\\bar\\somefile.vm");
In my post about Printf Tricks a couple of years ago,
I mentioned that "%n is dangerous and disabled by default in Visual Studio 2005."
I got email today from someone who was porting a large codebase to VS 2005.
He was getting an assert from %n and he needed a way to get past it.
He intends to fix the uses of %n when he has a chance.
I spent several minutes digging around in MSDN and came up with
set_printf_count_output. Wikipedia's Format string attack page
led me to Exploiting Format String Vulnerabilities, which
describes in detail how %n (and %s) may be exploited.
In short, if you …continue.
I recently learned about string pods and chain pods.
In essence, they are pocket-sized monopods.
You screw a six-foot string into the tripod socket of your camera,
step on the other end of the string,
and pull it taut.
The tension on the string reduces camera shake.
My string pod tutorial shows how I made the string pod,
as well as some before and after shots.
Before now, I used to try to find a handy surface or wall
to brace the camera, when taking photos without flash.
Often there isn't such a surface.
I have a little 3-inch pocket tripod that I carry with me all the time,
but I haven't …continue.
I've been getting into Python lately. One problem that I've encountered
under Windows, is that input redirection doesn't work if you use
the .py file association to run the script; e.g.:
C:\> foo.py < input.txt
There's a well-known input redirection bug. The fix is to explicitly use
python.exe to run the script.
A related problem for me was that stdin was opened as a text file,
not a binary file, so \r bytes were being discarded from binary input
files. The fix is to run python.exe -u (unbuffered binary input and
output).
I didn't want to hardcode the path to python.exe in a batch file,
so I came up with the …continue.
I ran into a problem installing some COM+ components today. The installer
was using Regsvcs.exe
to register each COM+ component. I noticed after a while that the installer
wasn't making any progress and that my dual-proc system was stuck at 50%
CPU utilization. I attached a debugger to the offending process, regsvcs,
and found that it was stuck in the following infinite loop
(disassembly courtesy of Reflector):
internal void System.EnterpriseServices.CatalogSync.Wait()
{
if (this._set)
{
RegistryKey key1
= Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\CLSID");
while (true)
{
int num1 = (int) key1.GetValue("CLBVersion", 0);
…continue.
I spent far too much time on Friday trying to make log4net work in a COM+ application.
Someone else had done part of the work necessary,
by creating an application.config for the COM+ application
and setting a custom Application Root Directory.
This was enough to ensure that most of the managed code in the application
got their configuration settings;
log4net being the exception.
It took some additional work to realize that we needed to add two assembly attributes:
[assembly: log4net.Config.Repository("unique-name")]
[assembly: log4net.Config.XmlConfigurator(ConfigFile="application.config")]
The repository name just needs to be a unique string.
We used the name of the assembly.
Aerobie AeroPress home page
CoffeeGeek thread
Adler's American recipe
LukeSeubert's Smooth Americano recipe
I like my Americano made with 175F water to the top of the "2" oval, with
our standard ten-second stir, and press with no steep time. Then diluted
1:1 after pressing.
Mark likes his brewed with much hotter water, with a 40 second steep time
and he likes to push all of the water through the press, rather than
diluting aftewards. His recipe has much more edge (which I might call
bitterness).
Sweet Maria's instructions
Lots of reviews
Lack of 'soul'
Negative pressure
Neutral pressure
Espresso definition
Crema
"Espresso strength"
I find that the drip-through, even with long steep or long stir times,
isn't …continue.
A few weeks ago, I wrote a C++ routine to parse decimal numbers using the
overflow detection principles of
SafeInt.
I couldn't find anything in the libraries that actually did a good job of checking
for overflow.
Briefly, to see if unsigned values A+B overflow, check
if (A > MAX_UINT - B). Similarly, A*B will overflow
if (A > MAX_UINT / B).
// Convert a string to an unsigned. Returns 'true' iff conversion is legitimate.
bool
StringToUnsigned(
const string& str,
unsigned& rUint)
{
rUint = 0;
if (str.empty())
…continue.
We use FlexWiki at work. It's an
ASP.NET-based wiki,
a low-overhead, organic way of sharing knowledge.
The only built-in means of editing a page in FlexWiki is to
type into an HTML textbox, which is a horrendous user experience.
There's no WYSIWYG feedback showing you whether you've got the wiki markup
right.
Back in December, Emma and I went to the Oregon coast for a week.
We had no Internet access and long dark evenings, so I spent quite a bit of
time on my laptop, working on a couple of projects. One was a new theme
(skin) for DasBlog, which I didn't finish to my satisfaction. I really
ought to …continue.
Previous »
« Next