Skip to content

Instantly share code, notes, and snippets.

View sag333ar's full-sized avatar

sagar kothari sag333ar

View GitHub Profile
@sag333ar
sag333ar / zoomOutToWorldView.m
Last active December 29, 2015 08:09
Sometimes, in maps, you might need to display entire-world-view. Example, in case of no location found, zoom out to the world view. Following code-snip would help you to achieve the same.
// this code will help you to zoom out to world-view
// step.1 create co-ordianate-span as follows
MKCoordinateSpan span = {.latitudeDelta = 180, .longitudeDelta = 360};
// step.2 crate region as follows
MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(0.0000f, 0.0000f), span);
// step.3 zoom using region to map as follows
[self.mapView setRegion:region animated:YES];
@sag333ar
sag333ar / createImageWithColorAndSize.m
Last active December 29, 2015 07:38
Create an image using color and size supplied in arguments.
// get image color & size as parameters
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
UIImage *img = nil;
// create rectangle/square of size supplied
CGRect rect = CGRectMake(0, 0, size.width, size.height);
// create context of size supplied
UIGraphicsBeginImageContext(rect.size);
@sag333ar
sag333ar / customLoggerForObjC.m
Last active December 29, 2015 07:29
NSLog without date time stamp, application name, and process id info.
#define NSLog(args...) CustomLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, args)
static inline void CustomLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...)
{
// Type to hold information about variable arguments.
va_list ap;
// Initialize a variable argument list.
va_start (ap, format);
// NSLog only adds a newline to the end of the NSLog format if
// one is not already there.
// Here we are utilizing this feature of NSLog()
@sag333ar
sag333ar / showDesktopIcons.APPLESCRIPT
Last active December 29, 2015 07:29
How to SHOW All Desktop Icons in Mac OS X by command line?
--comment
--step-1 - show icons
defaults write com.apple.finder CreateDesktop -bool true
--step-2 - kill finder & relaunch
killall Finder
@sag333ar
sag333ar / hideDesktopIcons
Last active December 29, 2015 07:29
How to Hide All Desktop Icons in Mac OS X by command line?
--comment
--step-1 - hide icons
defaults write com.apple.finder CreateDesktop -bool false
--step-2 - kill finder & relaunch
killall Finder
@sag333ar
sag333ar / takeScreenshot.m
Last active December 28, 2015 09:59
Take screen-shot of current-application-window.
// a function to take screen-shot of application's screen
- (UIImage*)takeScreenshot
{
// get the key-window references
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
// manipulate boundries of key-window
CGRect rect = [keyWindow bounds];
// create context using size
@sag333ar
sag333ar / generate1xAndAssets.sh
Last active December 28, 2015 09:59
Put all 2x images in proper folder-structure. Open terminal & cd to parent-directory of images folder. Run following script to generate XCAssets. View article - http://sugartin.info/2013/10/18/shell-script-for-genrating-xcassets-for-projects/
#!/bin/bash
createImagesets() {
for d in *; do
if [ -d $d ] ; then
(cd $d; createImagesets)
fi
if [ -f $d ] ; then
a=${d%@2x.*};
dirname=$a".imageset";
@sag333ar
sag333ar / EnableDebugConsole.c
Last active December 28, 2015 09:59
Enable console logs only for Debug mode, while sending release disable Debug_mode to turn off console logs.
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define STLog(x,...) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(x), ##__VA_ARGS__])
#else
#define STLog
#endif
@sag333ar
sag333ar / ALERT_WITH_TAG.m
Last active December 28, 2015 09:59
Show Alertview with one-line of code & also detect alertview with tag. Examples are as follows ALERT_WITH_TAG(100, @"Message", @"send this request", nil, self, @"Yes", @"No",nil); ALERT_WITH_TAG(100, @"Message", @"Data deleted", @"Okay", self, nil);
void ALERT_WITH_TAG(NSUInteger tag,NSString *title, NSString *message,NSString *canceBtnTitle,id delegate,NSString *otherButtonTitles, ... )
{
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:canceBtnTitle
otherButtonTitles:nil
];
va_list args;
@sag333ar
sag333ar / applyColorToImage.m
Last active December 28, 2015 09:59
Apply color to black-masked-image
// pass color & supply masked (masked with black-color) image
+ (UIImage *)applyColor:(UIColor *)color toImage:(UIImage*)toImage{
// create context
UIGraphicsBeginImageContextWithOptions(toImage.size, NO, toImage.scale);
// get context reference
CGContextRef context = UIGraphicsGetCurrentContext();
// Change the origin of the user coordinate system in a context.
CGContextTranslateCTM(context, 0, toImage.size.height);