Skip to content

Instantly share code, notes, and snippets.

View andkon's full-sized avatar
🤠

Andrew Konoff andkon

🤠
View GitHub Profile
@andkon
andkon / KeyboardDismissalViewController.h
Last active December 24, 2015 22:29
Dismissing iOS keyboard by pressing return or by pressing the screen
// This should be the viewcontroller that the keyboard commmunicates with.
@interface KeyboardDismissalViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *theTextFieldThatOpensTheKeyboardInTheFirstPlace;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
@end
@andkon
andkon / RandomColor.m
Created October 7, 2013 19:12
Random colour
// Sometimes you just need a random colour! I think I got this from apress's Beginning iOS Development book, kudos to them.
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
@andkon
andkon / AppDelegate.h
Last active December 31, 2015 23:29
Adding serialized permanent data storage to an iOS app
@interface ADKAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) NSMutableDictionary *storageDict;
-(NSString *)filePath;
@end
@andkon
andkon / Custom cell with UITextField
Last active August 24, 2016 15:23
Custom cell with UITextField - for use with storyboards
Storyboard configuration:
1. Make a cell.
2. Give it a custom class of YourCell
3. Drag a label onto the cell, give the label a tag of 100. Configure and arrange as necessary.
4. Drag a text field onto the cell, give the textField a tag of 101. Configure and arrange as necessary.
@andkon
andkon / DjangoDebugging.py
Last active August 29, 2015 14:01
Python-Django debugging with Foreman/gunicorn/celery.
# 1. Use Celery:
# http://celery.readthedocs.org/en/latest/tutorials/debugging.html
from celery import task
from celery.contrib import rdb
@task()
def add(x, y):
result = x + y
rdb.set_trace() # <- set breakpoint
@andkon
andkon / images.py
Last active August 29, 2015 14:02
Using Image from Pillow
from PIL import Image
img = Image.open("imagefilename.png")
print img.size
# 512, 512
print img.format
# PNG
print img.mode
# RGB
@andkon
andkon / UIViewController.m
Created June 16, 2014 23:49
Making a view behind iOS 7 status bar
- (void)viewDidLoad
{
CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, 20);
UIView *statusBarBg = [[UIView alloc] initWithFrame:rect];
[self.view addSubview:statusBarBg];
statusBarBg.backgroundColor = [UIColor purpleColor];
}
@andkon
andkon / BouncyTransition.h
Created June 20, 2014 03:13
Custom Transitions Between VCs
#import <Foundation/Foundation.h>
@interface BouncyTransition : NSObject <UIViewControllerAnimatedTransitioning>
@end
@andkon
andkon / RootVC.h
Created June 20, 2014 19:00
Custom dismissal animation
@interface RootVC : UIViewController <UIViewControllerTransitioningDelegate>
@andkon
andkon / InteractiveTransition.h
Created June 22, 2014 03:19
Interactive Transitions
@interface InteractiveTransition.h : NSObject <UIViewControllerAnimatedTransitioning>
@end