Friday, November 09, 2012

MS Server tools

http://www.cjwdev.co.uk/Software.html

MS Server tools and supporting software

Friday, August 19, 2011

Get pixel data

NSString * path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"jpg"];

UIImage * img = [[UIImage alloc]initWithContentsOfFile:path];

CGImageRef image = [img CGImage];

CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image));

const unsigned char * buffer = CFDataGetBytePtr(data);

Sunday, July 24, 2011

Save in NSUserDefaults

Saving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];

// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];

// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];

// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];

// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];

Loading
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];

// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];

// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];

Saturday, July 23, 2011

iOS SDK tips and tricks

Check if string null

if([myStr isEqual: [NSNull null]])
NSLog(@"null");
else
NSLog(@"not null");

=============================================
Crop Image

UIImageView *tempImageview;
CGRect newRect = CGRectMake(0, 0, newWidth, tempImageview.frame.size.height);
CGImageRef tmp = CGImageCreateWithImageInRect([tempImageview.image CGImage], newRect);
newRect = CGRectMake(tempImageview.frame.origin.x, tempImageview.frame.origin.y, newWidth, tempImageview.frame.size.height);

=============================================
Color with RGB

UIColor *myColor = [UIColor colorWithRed:32/255.0 green:93/255.0 blue:137/255.0 alpha:1.0];
tempImageview.frame = newRect;
tempImageview.image = [UIImage imageWithCGImage:tmp];

=============================================
Bring View to the top:
[self.view bringSubviewToFront:myImageView];

Or:
– bringSubviewToFront:
– sendSubviewToBack:
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:

=============================================

add Image Border

#import

[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];

=============================================

Rate this app

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=374892313&onlyLatestVersion=false&type=Purple+Software"]];

Replace id with the application ID from itunesconnect.

=============================================

Show/Hide Keyboard:

Keyboard Show:
[searchBar becomeFirstResponder];

Keyboard hide:
[searchBar resignFirstResponder];
=============================================

auto-lock disable

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
=============================================

Convert string to number

NSString *intString =@"1";
int value = [intString intValue]; //1

floatValue -> 1.00
doubleValue ->1.0000000
=============================================

Random

int lastNumber;
int rNumber;
while(rNumber == lastNumber)
rNumber = arc4random()%10;
lastNumber = rNumber;
=============================================

Save and Read Data

Save data:
NSString *testValue = [[NSUserDefaults standartUserDefaults] stringForKey:@”stringKey”];
if(testValue == nil)
{
//set default value
[[NSUserDefaults standartUserDefaults] setInteger:42 forKey:@”intKey”];
[[NSUserDefaults standartUserDefaults] setObject:@”data” forKey:@”stringKey”];
[[NSUserDefaults standartUserDefaults] setDouble:3.1415 forKey:@”doubleKey”];
[[NSUserDefaults standartUserDefaults] setFloat:1.23 forKey:@”floatKey”];

[[NSUserDefaults standartUserDefaults] synchronize];
}

Read data:
NSString *defaultString = [[NSUserDefaults standartUserDefaults] stringForKey:@”stringKey”];
int defaultInt = [[NSUserDefaults standartUserDefaults] integerForKey:@”intKey”];
//or NSInteger *defaultInt
int defaultFloat = [[NSUserDefaults standartUserDefaults] floatForKey:@”floatKey”];

=============================================

Absolute Value

float floatValue = -123.45678;
NSLog(@"%f", fabsf(floatValue)); //output: 123.45678
=============================================

=============================================

=============================================

=============================================

Delete User Default Data

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"dataName"];

Get iPhone Device Name, Unique Device Identifier (UDID), OS and Model

NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(@"name: %@", [[UIDevice currentDevice] name]);
NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
NSLog(@"model: %@", [[UIDevice currentDevice] model]);
NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);

iOS version:
NSLog(@"%@", [[UIDevice currentDevice] systemVersion]);

Round Number

#import "math.h"

float numberToRound;
int result;

numberToRound = 4.51;

result = (int)roundf(numberToRound);
NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(4.510000) = 5

result = (int)ceilf(numberToRound);
NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(4.510000) = 5

result = (int)floorf(numberToRound);
NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(4.510000) = 4

Download file

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http"//webite/"]]

Trimming whitespace from ends of a string

NSString *ook = @"\n \t\t hello there \t\n \n\n";
NSString *trimmed =
[ook stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSLog(@"trimmed: '%@'", trimmed);

Deserializing/Serializing with JSON

Deserializing with TouchJSON
#import "CJSONDeserializer.h"

NSData *jsonData = [NSData dataWithContentsOfFile: path]; // or from network, or whatever
NSError *error;
NSArray *playlists =
[[CJSONDeserializer deserializer] deserializeAsArray: jsonData error: &error];

Serializing with TouchJSON
#import "CJSONSerializer.h"

NSArray *allSongs = [self allSongs];
NSString *jsonString = [[CJSONSerializer serializer] serializeObject: allSongs];
NSData *data = [jsonString dataUsingEncoding: NSUTF8StringEncoding];
// write |data| to a file, send over the network, etc

Delete A Substring In Objective C, Iphone , Mac

/** initialize two strings **/
NSString *string = @"This is heaven";
NSString *part = @"heaven";

/** Get the range of the substring in the original string **/
NSRange range = [string rangeOfString:part];

/** Delete the substring from the original string **/
[string deleteCharactersInRange:range];

Distance between 2 points

CGPoint first= CGPointMake(50,50);
CGPoint second= CGPointMake(200,200);
float maxDistance= ccpDistance(first, second);

Detect Single/Double/Triple Taps In IPhone

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *urtouch = [touches anyObject];

NSUInteger urtapCount = [urtouch tapCount];

switch (urtapCount) {
case 1:
NSLog(@"Single Tap Detected!");
break;

case 2:
NSLog(@"Double Tap Detected!");
break;

case 3:
NSLog(@"Triple Tap Detected!");
break;

default :
break;
}
}

iPhone SDK examples and resources

http://www.iphoneexamples.com/
http://borkware.com/quickies/everything-by-date

screenshot programmatically on iPhone

#import

...

UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Copy Image to clipboard

// copy to clipboard
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:@"public.jpeg"];

Sunday, March 20, 2011

Get files from directory (including all subdirectories)

string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp", SearchOption.AllDirectories);

Sunday, December 19, 2010

export DataTable To Excel

static DataTable GetTable()
{
DataTable table = new DataTable(); // New data table.
table.Columns.Add("Dosage", typeof(int)); // Add five columns.
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));

table.Rows.Add(15, "Abilify", "xxx", DateTime.Now); // Add five data rows.
table.Rows.Add(40, "Accupril", "yyy", DateTime.Now);
table.Rows.Add(40, "Accutane", "zzz", DateTime.Now);
table.Rows.Add(20, "Aciphex", "zyy", DateTime.Now);
table.Rows.Add(45, "Actos", "xxxy", DateTime.Now);

return table; // Return reference.
}


private void exportDataTableToExcel(DataTable dt, string filePath)
{
// Excel file Path
string myFile = filePath;

//System.Data.DataRow dr = default(System.Data.DataRow);

int colIndex = 0;
int rowIndex = 0;

// Open the file and write the headers
StreamWriter fs = new StreamWriter(myFile, false);

fs.WriteLine("<? xml version=\"1.0\"?>");
fs.WriteLine("<?mso-application progid=\"Excel.Sheet\"?>");
fs.WriteLine("<ss:Workbook xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");

// Create the styles for the worksheet
fs.WriteLine(" <ss:Styles>");
// Style for the column headers
fs.WriteLine(" <ss:Style ss:ID=\"1\">");
fs.WriteLine(" <ss:Font ss:Bold=\"1\" ss:Color=\"#FFFFFF\"/>");
fs.WriteLine(" <ss:Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\" " + "ss:WrapText=\"1\"/>");
fs.WriteLine(" <ss:Interior ss:Color=\"#254117\" ss:Pattern=\"Solid\"/>");
fs.WriteLine(" </ss:Style>");
// Style for the column information
fs.WriteLine(" <ss:Style ss:ID=\"2\">");
fs.WriteLine(" <ss:Alignment ss:Vertical=\"Center\" ss:WrapText=\"1\"/>");
fs.WriteLine(" </ss:Style>");
// Style for the column headers
fs.WriteLine(" <ss:Style ss:ID=\"3\">");
fs.WriteLine(" <ss:Font ss:Bold=\"1\" ss:Color=\"#FFFFFF\"/>");
fs.WriteLine(" <ss:Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\" " + "ss:WrapText=\"1\"/>");
fs.WriteLine(" <ss:Interior ss:Color=\"#736AFF\" ss:Pattern=\"Solid\"/>");
fs.WriteLine(" </ss:Style>");
fs.WriteLine(" </ss:Styles>");

// Write the worksheet contents
fs.WriteLine("<ss:Worksheet ss:Name=\"Sheet1\">");
fs.WriteLine(" <ss:Table>");

fs.WriteLine(" <ss:Row>");
foreach (DataColumn dc in dt.Columns)
{
fs.WriteLine(string.Format(" <ss:Cell ss:StyleID=\"1\">" + "<ss:Data ss:Type=\"String\">{0}</ss:Data></ss:Cell>", dc.ColumnName ));
}

fs.WriteLine(" </ss:Row>");

object cellText = null;

// Write contents for each cell
foreach (DataRow dr in dt.Rows)
{
rowIndex = rowIndex + 1;
colIndex = 0;
fs.WriteLine(" <ss:Row>");
foreach (DataColumn dc in dt.Columns)
{
cellText = dr[dc];
// Check for null cell and change it to empty to avoid error
if (cellText == null ) cellText = "";
fs.WriteLine(string.Format(" <ss:Cell ss:StyleID=\"2\">" +
"<ss:Data ss:Type=\"String\">{0}</ss:Data></ss:Cell>", cellText));
colIndex = colIndex + 1;
}
fs.WriteLine(" </ss:Row>");
}

fs.WriteLine(" <ss:Row>");
fs.WriteLine(" </ss:Row>");

// Close up the document
fs.WriteLine(" </ss:Table>");
fs.WriteLine("</ss:Worksheet>");
fs.WriteLine("</ss:Workbook>");
fs.Close();
}

Example:
exportDataTableToExcel (GetTable(),"C:\\PatientDetails.xls");
will write the content of data table with Formatting Styles.

Wednesday, December 08, 2010

AJAX Database Example

JavaScript:
function showCustomer(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getcustomer.asp?q="+str,true);
xmlhttp.send();
}


======================
ASP:
<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
rs.Open sql,conn

response.write("<table>")
do until rs.EOF
  for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
  next
  rs.MoveNext
loop
response.write("</table>")
%>

http://stackoverflow.com

http://stackoverflow.com