Objective-C Append NSData to another NSData using NSMutableData

    NSData *d1;
    char c1[] = { 0x02, 0x03 };
    char c2[] = { 0x04, 0x05 };
    d1 = [NSData dataWithBytes:(char*)c1 length:2];
    NSMutableData *nd = [[NSMutableData alloc] initWithData:d1];
    NSLog(@"Before append: %@", d1);
    d1 = [NSData dataWithBytes:c2 length:2];
    [nd appendData:d1];
    NSLog(@"After append: %@", nd);
Posted in Uncategorized | Comments Off on Objective-C Append NSData to another NSData using NSMutableData

Python timeout example.

import signal, os, subprocess

class Alarm(Exception):
    pass

def alarm_handler(signum, frame):
    raise Alarm

# start timer, currently set to go off in 3 seconds
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(3)  # 3 seconds
try:
    print time.strfmt("%H:%M:%S")
    # perform some tasks here, for this example I use a sleep of 20 seconds which will get interrupted.
    time.sleep(20) 		# wait 20 seconds, note this time must be larger than the value of start timer.
    signal.alarm(0)  # reset the alarm
except Alarm:
    print "Oops, taking too long!"
print time.strfmt("%H:%M:%S")
Posted in Uncategorized | Comments Off on Python timeout example.

Python display environment vars

import os
import sys
import platform

e = os.environ["PATH"].split(':')
for i in e:
	print i
print dir(platform)
print platform.uname()
Posted in Uncategorized | Comments Off on Python display environment vars

Software

This site is dedicated to open source software.

Posted in Uncategorized | Leave a comment