Category Archives: Programming

Recently I had to add ordering support to an application using the column names as strings, but the LINQ API accepts only Lambda expressions.
And to worsen my case, I needed it to work with IEnumerable, plus nested properties, so I decided to write this extension to fulfill these needs.

Normally you’d write:

list.OrderBy(p => p.Name);
list.OrderBy(p => p.Member.SubMember).ThenBy(p => p.AnotherMember);

Now, you can write:

list.OrderBy("Name");
list.OrderBy("Member.SubMember").ThenBy("AnotherMember");

It ended up being more friendly, and I hope it makes your life easier as well.

Few months ago I wrote a jQuery plugin for AJAX file uploading. It’s based on the idea used by WebToolkit Ajax file upload.

The code is here.

How to use it?

$(document).ready(function() {
	$('#your_form_id').uploadForm('your_upload_script', {
		'onStart': function() {
			alert('Uploading...');
			return true;
		},
		'onComplete': function(data) {
			alert('Complete: '+data);
		},
		'onError': function(cause) {
			alert('Error: '+cause);
		},
		'timeout': 5000
	});
});

How does it work?

  1. Page loads, and the form’s submit event is hooked;
  2. User selects a file, and clicks in the submit button;
  3. The hook function is triggered by the submit event, creates an iframe, and appends it to the document root;
  4. The onStart callback is called;
  5. The form’s target property is set to the iframe element, avoiding the full page reload.
  6. The submit event is executed normally;
  7. The onComplete callback is called after the iframe reload;

UPDATE 2009.08.20: I’ve almost completed the task of adding the ipfw support, but I’m not having enough free time lately, so I decided to share my patch and the TODO list. It has been published here.

I packaged two parts of the latest MiniUPnP version into distinct MacOSX frameworks, so developers can embed on their .app’s. The first, miniupnpc, is a client implementation of the Internet Gateway Device Protocol, and the second, libnatpmp, is a client implementation of the NAT Port Mapping Protocol (part of the Bonjour Protocol). I know the latest versions are NOT major releases, but it’s mainly to check people interest.

MiniUPnPc.framework is here.
NATPMP.framework is here.

These frameworks are universal, so they run on both PPC and x86.

Regarding to the server implementation (miniupnpd), it supports netfilter (iptables), packet filter (pf), ipfilter (ipf) and pfSense, but not ipfirewall (ipfw), so it needs considerable work to add this support preserving the API compatibilty. I would be doing that if my day had 72 hours… Anyway, I’ve already contacted the author about my interest.

#define SYS_BASE		0x10
#define SYS_MAC			SYS_BASE+1
#define SYS_LINUX		SYS_BASE+2
#define SYS_FREEBSD		SYS_BASE+3
#define SYS_NETBSD		SYS_BASE+4
#define SYS_OPENBSD		SYS_BASE+5
#define SYS_MINT		SYS_BASE+6
#define SYS_BSD_BASED		SYS_BASE+7
#define SYS_SOLARIS		SYS_BASE+8
#define SYS_HPUX		SYS_BASE+9
#define SYS_RISC_OS		SYS_BASE+10
#define SYS_OS2			SYS_BASE+11
#define SYS_IRIX		SYS_BASE+12
#define SYS_AIX			SYS_BASE+13
#define SYS_BEOS		SYS_BASE+14
#define SYS_CYGWIN		SYS_BASE+15
#define SYS_OPENVMS		SYS_BASE+16
#define SYS_OSF			SYS_BASE+17
#define SYS_QNXNTO		SYS_BASE+18
#define SYS_WINDOWS		SYS_BASE+19
#define SYS_DREAMCAST		SYS_BASE+20

#if defined(__APPLE__) || defined(MAC_OS_CLASSIC) \
	|| defined(MAC_OS_X) || defined(macintosh)
#	define SYSTEM		SYS_MAC
#elif defined(linux) || defined(__linux) || defined(__linux__)
#	define SYSTEM		SYS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#	define SYSTEM		SYS_FREEBSD
#elif defined(__NetBSD__)
#	define SYSTEM		SYS_NETBSD
#elif defined(__OpenBSD__)
#	define SYSTEM		SYS_OPENBSD
#elif defined(__MINT__)
#	define SYSTEM		SYS_MINT
#elif defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
#	define SYSTEM		SYS_BSD_BASED
#elif defined(sun) || defined(__SVR4)
#	define SYSTEM		SYS_SOLARIS
#elif defined(hpux) || defined(__hpux) || defined(__hpux__)
#	define SYSTEM		SYS_HPUX
#elif defined(riscos) || defined(__riscos) || defined(__riscos__)
#	define SYSTEM		SYS_RISC_OS
#elif defined(__OS2__) || defined(__EMX__)
#	define SYSTEM		SYS_OS2
#elif defined(osf) || defined(__osf) \
	|| defined(__osf__) || defined(_OSF_SOURCE)
#	define SYSTEM_		SYS_OSF
#elif defined(sgi) || defined(__sgi) \
	|| defined(__sgi__) || defined(_SGI_SOURCE)
#	define SYSTEM		SYS_IRIX
#elif defined(_AIX)
#	define SYSTEM		SYS_AIX
#elif defined(__BEOS__)
#	define SYSTEM		SYS_BEOS
#elif defined(__CYGWIN__)
#	define SYSTEM		SYS_CYGWIN
#elif defined(__VMS)
#	define SYSTEM		SYS_OPENVMS
#elif defined(__osf__)
#	define SYSTEM		SYS_OSF
#elif defined(__QNXNTO__)
#	define SYSTEM		SYS_QNXNTO
#elif defined(_arch_dreamcast)
#	define SYSTEM		SYS_DREAMCAST
#elif defined(WINDOWS) || defined(WIN32) || defined(_WIN32)
#	define SYSTEM		SYS_WINDOWS
#endif
#define DECLARE_SMART_ENUM(_TYPE) \
	inline _TYPE operator&(_TYPE v1, _TYPE v2) \
	{ return _TYPE(int(v1) & int(v2)); } \
	inline _TYPE operator|(_TYPE v1, _TYPE v2) \
	{ return _TYPE(int(v1) | int(v2)); } \
	inline _TYPE operator^(_TYPE v1, _TYPE v2) \
	{ return _TYPE(int(v1) ^ int(v2)); } \
	inline _TYPE operator~(_TYPE v1) \
	{ return _TYPE(~int(v1)); } \
	inline _TYPE& operator|=(_TYPE& v1, _TYPE v2) \
	{ return v1 = v1 | v2; } \
	inline _TYPE& operator&=(_TYPE& v1, _TYPE v2) \
	{ return v1 = v1 & v2; } \
	inline _TYPE& operator^=(_TYPE& v1, _TYPE v2) \
	{ return v1 = v1 ^ v2; } \
	inline _TYPE& operator++(_TYPE& v1) \
	{ return v1 = _TYPE(int(v1) + 1); } \
	inline _TYPE& operator++(_TYPE& v1, int) \
	{ return v1 = _TYPE(int(v1) + 1); } \
	inline _TYPE& operator--(_TYPE& v1) \
	{ return v1 = _TYPE(int(v1) - 1); } \
	inline _TYPE& operator--(_TYPE& v1, int) \
	{ return v1 = _TYPE(int(v1) - 1); }