Monday, July 26, 2021

C Align Up Macro

 #define align_up(num, align) (((num) + ((align) - 1)) & ~((align) - 1))

Friday, September 5, 2014

gcc: print all preprocessor defines

gcc -dM -E - < /dev/null

from: http://www.brain-dump.org/blog/entry/107

Thursday, October 6, 2011

Take Screenshot in WebOS Emulator

luna-send luna://com.palm.systemmanager/takeScreenShot '{"file":"screenshot.png"}'

Thursday, September 2, 2010

Linux Network Programming

Get list of network interfaces:
int getifaddrs(struct ifaddrs **ifap);
void freeifaddrs(struct ifaddrs *ifa);

inet_ntoa() and inet_aton() with IPv6 support
int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);

Monday, March 30, 2009

BASH Scripting - Take input from file as STDIN

# Save the STDIN file descriptor
0>&3

# Redirect file as STDIN
0< filename

# Do stuff
...

# Close the file descriptor
exec 0>&-

# Assign STDIN back to 0
3>&0

Tuesday, March 24, 2009

Setting the "Busy" mouse Cursor

GdkCursor *cursor;

cursor = gdk_cursor_new( GDK_WATCH );
gdk_window_set_cursor( widget->window, cursor );

Friday, December 1, 2006

Neat Inverse Square Root Function

Found this nice function in slashdot: http://www.beyond3d.com/articles/fastinvsqrt/

float InvSqrt( float x )
{
    float xhalf = 0.5f * x;
    int i = *(int *)&x;

    i = 0x5f3759df - ( i >> 1 );
    x = *(float *)&i;
    x = x * ( 1.5f - xhalf * x * x );

    return x;
}