Monday, October 21, 2013

SQL SERVER – Query to Find First and Last Day of Current Month

 Following query will run respective to today’s date. It will return Last Day of Previous Month, First Day of Current Month, Today, Last Day of Previous Month and First Day of Next Month respective to current month.



DECLARE @mydate DATETIME
SELECT @mydate GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,'Last Day of Previous Month'UNION
SELECT 
CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101AS Date_Value,'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101AS Date_Value'Today' ASDate_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,'First Day of Next Month'
GO

Friday, October 11, 2013

Get debug console log in iOS

- (NSString *)getConsoleLogFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return nil;
}
return [documentsDirectory stringByAppendingPathComponent:fileName];
}


NSString *fileName = @"xx.log";
NSString *logFilePath = [self getConsoleLogFilePath];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);




Tuesday, September 10, 2013

Print "Hello World" Without Using Semicolon


Source Code :
 #include <stdio.h>  
 int main() {  
 if(printf("Hello World")) {  
 /*  
 * It prints Hello world and returns the  
 * value 11 i.e Length of the String  
 */  
 }  
 }  



Monday, June 10, 2013

Execute HTTP GET in Android

Sample Code :

try {
       HttpClient client = new DefaultHttpClient();
       String targetUrl = "http://www.example.com";
       HttpGet httpGet = new HttpGet(targetUrl);
       HttpResponse response = null;       
       response = client.execute(httpGet);
       HttpEntity entity = response.getEntity();
       if(entity!=null){
             Log.v("GET RESPONSE", EntityUtils.toString(entity));
       }
}
catch(Exception e){
       e.printStackTrace();
}

Thursday, June 06, 2013

Get the frame of a view inside another view

Converts a rectangle from the coordinate system of another view to that of the receiver.
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view
Sample :
CGRect frame = [imageView convertRect:button.frame toView:self.view];


Tuesday, April 30, 2013

Atomic vs nonatomic properties


@property(nonatomic, retain)( NSString *userName;

@property(atomic, retain) NSString *userName;

@property(retain) NSString *userName;


The last two are identical; "atomic" is the default behavior (note that it is not actually a keyword; it is specified only by the absence of nonatomic -- atomic was added as a keyword in recent versions of llvm/clang).


Assuming that you are @synthesizing the method implementations, atomic vs. non-atomic changes the generated code. If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory. (Note: @synthesize is now the default behavior in recent versions of LLVM. There is also no need to declare instance variables; they will be synthesized automatically, too, and will have an _ prepended to their name to prevent accidental direct access).


With "atomic", the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.
In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".


What "atomic" does not do is make any guarantees about thread safety. If thread A is calling the getter simultaneously with thread B and C calling the setter with different values, thread A may get any one of the three values returned -- the one prior to any setters being called or either of the values passed into the setters in B and C. Likewise, the object may end up with the value from B or C, no way to tell.

Ensuring data integrity -- one of the primary challenges of multi-threaded programming -- is achieved by other means.

Monday, April 29, 2013

How to get the available font from iOS Device ?

NSString *familyName;
NSString *fontName;
   
for(familyName in [UIFont familyNames])
    {
        NSLog(@"\nName of the Family: %@", familyName);
       
       
for(fontName in [UIFont fontNamesForFamilyName:familyName])
            NSLog(@"\tName of the Font: %@\n", fontName);
    }

Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...