Skip to content

Instantly share code, notes, and snippets.

View MugunthKumar's full-sized avatar

Mugunth Kumar MugunthKumar

View GitHub Profile
//
// Created by Mugunth Kumar, Copyright © 2019 MK. All rights reserved.
//
import Foundation
import UIKit
import ImageIO
public extension UIImageView {
@MugunthKumar
MugunthKumar / measure.swift
Last active February 22, 2016 23:34
Measures Time Taken for a closure to run
func measure(prefix: String = "Time Taken", closure:()->()) {
let a = CFAbsoluteTimeGetCurrent()
closure()
let b = CFAbsoluteTimeGetCurrent()
let m = ((b-a) * 1000.0)
print("\(prefix): \(m) ms")
}
@MugunthKumar
MugunthKumar / NSURLRequest+cURL
Created May 5, 2015 04:05
NSURLRequest cURL description
- (NSString *)description {
__block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -v -X %@", self.HTTPMethod];
[displayString appendFormat:@" \'%@\'", self.URL.absoluteString];
[self.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) {
[displayString appendFormat:@" -H \'%@: %@\'", key, val];
}];
@MugunthKumar
MugunthKumar / gist:3fcb7b5f63a309fc5b60
Created September 12, 2014 04:25
Apple Store Down
#!/bin/bash
function check {
status=`curl -Is http://store.apple.com/sg/ | grep "HTTP/1.1"`
echo ${status:9:3}
if [ "${status:9:3}" == "200" ]; then
while true; do
say "Its here... Its here... Its here"
echo -en "\007"
done
fi
@MugunthKumar
MugunthKumar / gist:5044533
Created February 27, 2013 02:41
UIAppearance for nav bar customization.
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setBackgroundImage:[[UIImage imageNamed:@"NavButton"] stretchableImageWithLeftCapWidth:10 topCapHeight:0]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setBackButtonBackgroundImage:[[UIImage imageNamed:@"BackButton"] stretchableImageWithLeftCapWidth:15 topCapHeight:0]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor rmRedColor]];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBarBG"]
@MugunthKumar
MugunthKumar / Base Init
Created January 20, 2013 03:55
Initializing a custom control.
-(void) baseInit_ {
<#Your code here#>
}
-(id) initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
@MugunthKumar
MugunthKumar / ARCError.m
Created August 17, 2012 03:22
ARC error
#if ! __has_feature(objc_arc)
#error This file/class is targeted for the ARC compiler. Either turn on ARC for your project or use -fobjc-arc flag
#endif
@MugunthKumar
MugunthKumar / gist:2036521
Created March 14, 2012 13:35
UIView Shadow within PNG
self.myView.layer.masksToBounds = NO;
self.myView.layer.shadowColor = [UIColor blackColor].CGColor;
self.myView.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
self.myView.layer.shadowOpacity = 0.7f;
self.myView.layer.shadowRadius = 3.0f;
@MugunthKumar
MugunthKumar / gist:1576556
Created January 8, 2012 00:11
MKNetworkEngine and UIImageView
[AppDelegate.imageFetcher imageAtURL:self.profile.avatarURL
onCompletion:^(UIImage *image, NSURL *url, BOOL isInCache)
{
// this "if" is to prevent images flashing repeatedly when cells are reused.
if ([[self.profile.avatarURL absoluteString] isEqualToString:[url absoluteString]]) {
self.avatarImageView.image = resizedImage;
}
}];
@MugunthKumar
MugunthKumar / initgit.sh
Created January 19, 2011 02:13
Initialize a git repository and copy a git ignore file from your home directory
# Copy this file to /usr/local/bin/ on your Mac
# type chmod +x initgit.sh
# From now on, on any folder, you can just type initgit.sh and a new git repo with a default .gitignore file will be created for you.
#! /bin/sh
git init
cp ~/.gitignore .
rm -r build/
git add .gitignore