opening winmail.dat attachments in osx
Monday, September 09, 2013
Microsoft. Outlook. It sends attachments in its own weird an wonderful format as a single file called winmail.dat, for those of us fortunate enough not to have Outlook as our email client to unpack them.
There's an opensource project, TNEF which provides a tool that unpacks these well
- Download the tnef tar
- Untar it (tar -xf .., or just double click)
- Follow the README steps (note the make install needs to be run with sudo)
writing JAXB extension plugins
Thursday, November 01, 2012
JAXB extension plugins (1) give the user more power than simple binding alterations, plus can encourage clean schemas by keeping the code extensions out of the xsd's. But finding up-to-date documentation on this can be a pain, most predates maven.
In hindsight, the process is actually quite simple and there are some good references, but it still takes collation of quite a few sites to make it work. Here I hope to capture them all for a cohesive approach.
Note that 'plugin' is a ubiquitous term and here can mean many things. For disambiguation I've added a postscript number to each use of the term. See footnotes at the bottom for meanings.
JAXB runtime
This post assumes you're using maven. And if so, the JAXB plugin (2) to use is maven-jaxb2-plugin. Add the latest version to your pom http://mvnrepository.com/artifact/org.jvnet.jaxb2.maven2/maven-jaxb2-plugin. Then get your schema generation working OK as documented plenty of places elsewhere on the web. If you're looking at this page then you're probably well past that step anyway.Plugin project skeleton
Create a new maven project to hold your plugin (1). For this example we'll call it my-jaxb-plugin.In the pom add a dependency on jaxb xjc, eg:
<groupid>com.sun.xml.bind</groupid>
<artifactid>jaxb-xjc</artifactid>
<version>2.2.6</version>
</dependency>
Create a new class, call it MyPlugin1 in package com.eg, extending from com.sun.tools.xjc.Plugin. For now just implement the required methods returning "XmyJaxb" from getOptionName(), and implement run() as System.out.println("***working!"); (or similar :).
Now create new folders META-INF/services on the classpath (eg src/main/resources). Add a text file in there called com.sun.tools.xjc.Plugin.In this file is a list of all the plugins that this project provides, one per line. So for now add your new plugin class:
Run a maven install on the project to make it available (not needed later if you use workspace resolution with eclipse maven plugin (3))
Employ the plugin (1)
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-debug</arg>
<arg>-XmyJaxb</arg>
</args>
<plugins>
<plugin>
<groupId>nz.govt.police</groupId>
<artifactId>esbschema-jaxb-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
The -debug arg can be removed later as needed. You may also find it useful to use -X after your mvn install command to get verbose output from the maven build.
More
For taking your plugin (1) further, read the key post from 2005, resources incl javadoc for jaxb-xjc, and the sun codemodel javadocs which you'll be using to modify the code generation.Footnotes
mongodb script types
Monday, April 23, 2012
There's the obvious choice of client drivers in your language of choice for application-based mongodb connections, but for server-side admin and scripting, js is best. But from the shell and cron, often they get wrapped in shell scripts. This table-esque post outlines some of the decision points to use when approaching this, plus some guidance as to how to write them.
Interactive shell
Syntax:mongo
About:
--eval
Syntax: mongo dbname --eval "db.coll..."
About:
- see printjson
js file
Syntax: mongo dbname filename.js
About:
eval + js file
Syntax: mongo dbname --eval "param1=val1;param2=val2" filename.js
About:
All within one sh script
Syntax:
js here
js here
eof
- Cannot be run inside an --eval
- From mapreduce docs { inline : 1} - With this option, no collection will be created, and the whole map-reduce operation will happen in RAM. Also, the results of the map-reduce will be returned within the result object. Note that this option is possible only when the result set fits within the 16MB limit of a single document. In v2.0, this is your only available option on a replica set secondary.
- Queries (such as count(), sort()) cannot be run on inline results (as of mongodb 2.1+ new aggregation features may allow this). For versions <2.1, seeing as cannot run these queries on inline results, and can't have temp collections on secondary servers, have to run these on primary server so can save to a temp collection and run queries against that.
TurnKey Linux
Saturday, February 18, 2012
TurnKey is yet another Linux distro, but it's come a long way since I last checked it out. Initially providing images for LAMP and 2x CMS stacks only, it now boasts nearly 50 different appliances, with an impending launch of up to 150. There are now commercial options for managed cloud deployments as well. Nice offerring
simple svn project repository migration steps
Tuesday, March 29, 2011
Migrate repositories using the eclipse subclipse plugin.
Note this method will not bring revision history into the new repository, so assumes you will still have ongoing access to the old respository. This technique is useful if the history isn't that rich, and you want a quick switch over, or if you don't directly manage the repositories, so svnadmin commands aren't available (like our case, we use a hosted JIRA solution).
Steps:
- Create the new project top-level folder in the new repository. Eg: /NEWREPO/projectA/trunk. Using 'new remote folder' in SVN repositories view is the easiest.
- Open the existing project in eclipse
- Choose team> switch to another branch/tag/revision.
- Choose intended top-level project folder (eg /NEWREPO/projectA/trunk). Note this folder name doesn't have to become the eclipse project name
- team> revert the project to remove local changes
- team> merge (Install into eclipse the fantastic CollabNet Merge client, if haven't already)
- Untick best-practices check and choose 'Merge range of revisions', then Next
- Select, then under Root, browse to the exisiting project folder (original repo) (eg /OLDREPO/projectA/trunk)
- Commit the project
Linux swap space - real usage
Wednesday, January 19, 2011
Using top, ps aux, etc etc gives all kinds of memory usage with lots of blog posts and forum questions explaining how difficult they are to understand, and how typically aren't actually that useful.
As of kernel 2.6.14, smaps has been introduced which means each process reports its own memory usage breakdown.
smaps detail for a process can be seen by:
So, use top, find the big memory hoggers first. Then look at the smaps file for the swap usage. You can use, for example:
For more advanced smaps analysis, try the smaps.pl tool. Not sure at this stage, though, whether that tool gives separate swap values.
In Debian at time of this post, the pmap tool has been patched to use smaps, which may then offer swap values in its output.
fitnesse - find disabled tests
Thursday, September 23, 2010
FitNesse suites can grow enormous, so managing them becomes tough. Here's a simple script to find all pages in a given suite that are not marked as either a Test or as a Suite:
#! /bin/bash
if [ $# -eq 0 ]; then
echo "Shows fitnesse tests that aren't enabled as either Test or Suite"
echo 'Usage: ./find_disabled_tests.sh {parent_dir}'
echo 'Eg: ./find_disabled_tests.sh /var/local/fitnesse/FitNesseRoot/SitTests/RichTests'
exit 0
fi
cd $1
find -name properties.xml -print | xargs egrep -L '(Test/|
python stdio in osx launchd
Monday, August 16, 2010
Running Python scripts via launchd doesn't seem to flush stdout print statements (ie. using the basic 'print' command). This can be confirmed by importing sys and calling sys.stdout.flush() after the print statements to see them actually output.
The solution? Add the -u flag to tell python not to buffer its stdio.
In an OSX launchd plist file, your solution may include:
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>-u</string>
use old laptop as monitor and terminal
Monday, May 31, 2010
I have just had a new Mac Mini arrive that I want to use for mostly automated and headless tasks. But I also want to use this as a home computer for my wife, but it has no screen and no mic, plus not much room on the bench where it lives to fit a keyboard and mouse. My wife has a decrepit (no battery; no harddrive) laptop she's been using, so hey, why not use that as a terminal?
Laptop is running puppy linux (4.3.1). Great little lightweight distro. It boots off CD and uses a USB key for storage.
- Installed tightvnc-client
Mac is running Snow Leopard
So by setting up the script below as a menu option (add to ~/.jwmrc), all she has to do is click it, and the connection begins, including sending all mic input sound (via dd with /dev/dsp) through an audio cable from laptop's headphone jack to Mac's input jack, registering as input on the Mac (Skype-ho!).
Beauty
[caveat: I cannot be held responsible for damage to hardware caused by plugging hardware into each other. Headphone jacks are pretty low voltage though, as I understand it, and it's worked for me]
#!/bin/sh
echo 'Hi, this is how to connect to the Mac Mini'
echo
echo 'Testing for network connection'
if ping -w 2 192.168.1.1 > /dev/null; then
echo ":) Found the router, we're connected already"
else
echo 'Here comes the Network Wizard to connect to the network. You know what to do...'
echo
echo -n 'Press enter once the network is done...'
net-setup.sh > /dev/null 2>&1
read resp
fi
echo
if ping -w 2 192.168.1.9 > /dev/null; then
echo ":) Mac is on, we're ready to connect"
else
echo 'Check the Mac is on. Look for the little white light on the front'
echo -n "Press enter when happy it's on. If only just turned on then wait a minute before continuing..."
read resp
fi
echo
if ps -ef | grep "[d]d if"; then
echo ':) Sound loopback for mic already running'
else
echo 'Ok, starting the sound loopback so we can send the mic to Mac'
dd if=/dev/dsp | dd of=/dev/dsp &
fi
echo
echo 'Right, about to start the connection'
echo "Enter '***' below as the password and you're good to go!"
echo
vncviewer 192.168.1.9:5900 -fullscreen
command line access to hosted JIRA files
Friday, May 28, 2010
Currently I'm on a project that uses an Atlassian-hosted JIRA Studio. We put scripts and config files as wiki page (confluence) attachments, then needed to access them from remote machines via the command line, even as part of a script. JIRA has it's own security methods, not simple http auth, which would be a piece of cake. So, another solution was needed.
A page in the JIRA Community Space describes how to do this using wget with cookies. But it didn't work for me. Whether this is because we are using the hosted variant, or due to changes since that page was written, I found we had to access a different url to log in.
So here's a current working solution that firstly interactively prompts for username and password to log in and creates a cookie:
--post-data "os_username=$uname&os_password=$pass&os_cookie=true" -O /tmp/login 'http://OURDOMAIN.jira.com/rest/gadget/1.0/login'; uname=''; pass=''
Replace OURDOMAIN to make the url relevant for your site. This needs to be run only once per machine, at least until the cookie expires. The cookie file will be saved in your home dir.
Next, to retrieve any files, use:
Again replacing OURDOMAIN. Run this for each file, pasting the full url to the file to retrieve when prompted.
From these you should be able to see how to strip out the interactivity to make them scriptable, too.