Skip to content

Instantly share code, notes, and snippets.

Kyle Clegg kyleclegg

Block or report user

Report or block kyleclegg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TidyJSON.py
#!/usr/bin/python
import fileinput
import json
if name == "main":
jsonStr = ''
for aline in fileinput.input():
jsonStr = jsonStr + ' ' + aline.strip()
jsonObj = json.loads(jsonStr)
@kyleclegg
kyleclegg / gist:ae32ea1fc5b19359bea0
Last active Aug 29, 2015
CoreData Simple Fetch
View gist:ae32ea1fc5b19359bea0
// Substitute [ACHCoreDataHelper sharedHelper].defaultContext for the managedObjectContext
NSEntityDescription *entity = [NSEntityDescription entityForName:@"StickerPack" inManagedObjectContext:[ACHCoreDataHelper sharedHelper].defaultContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [[ACHCoreDataHelper sharedHelper].defaultContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"items: %@", items);
StickerPack *pack = items[0];
NSLog(@"pack: %@", pack);
@kyleclegg
kyleclegg / RoundUIViewCorners
Created Aug 14, 2014
Round two corners on UIView
View RoundUIViewCorners
Easy helper method:
- (void)setMaskTo:(UIView *)view byRoundingCorners:(UIRectCorner)corners
{
CGFloat cornerRadius = 6.0;
UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
View gist:458622a8bd5a1005fb3f
__weak id weakSelf = self;
[[[[[self signalGetNetworkStep1] flattenMap:^RACStream*(id *x) {
// perform your custom business logic
return [weakSelf signalGetNetworkStep2:x];
}] flattenMap:^RACStream*(id *y) {
// perform additional business logic
return [weakSelf signalGetNetworkStep3:y];
}] flattenMap:^RACStream*(id *z) {
// more business logic
return [weakSelf signalGetNetworkStep4:z];
@kyleclegg
kyleclegg / RestKit Local Loading
Last active Jan 28, 2018
RestKit - Load data from local json file
View RestKit Local Loading
NSString *filePath = [[NSBundle mainBundle] pathForResource:JohnSmith ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
if (data) {
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
KCUser *appUser = [[KCUser alloc] init];
NSString* MIMEType = @"application/json";
NSError* error;
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
id parsedData = [RKMIMETypeSerialization objectFromData:data MIMEType:MIMEType error:&error];
@kyleclegg
kyleclegg / ShowHideLayouts
Created Mar 15, 2013
Helper methods to show and hide Android layouts
View ShowHideLayouts
// Helper method to animate the showing of a view
private void showLayout (final LinearLayout theLayout) {
AlphaAnimation fade_in = new AlphaAnimation(0.0f, 1.0f);
fade_in.setDuration(500);
fade_in.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation arg0) {
}
public void onAnimationRepeat(Animation arg0) {
@kyleclegg
kyleclegg / KCSegmentedControl
Last active Jan 21, 2019
Customizing the segmented control to be dark gray and green when selected. Note: this is not a subclass - just set it in your controller.
View KCSegmentedControl
// in viewDidLoad
[self.mySegmentedConrol setTintColor:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1]];
[self.mySegmentedConrol setSegmentedControlStyle:UISegmentedControlStyleBar];
// Update tints on valueChanged
- (IBAction)valueChanged:(UISegmentedControl *)sender {
UIColor *selectedTintColor = [UIColor colorWithRed:80.0f/255.0f green:185.0f/255.0f blue:72.0f/255.0f alpha:1.0];
UIColor *unselectedTintColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1];
@kyleclegg
kyleclegg / InvalidTextFields
Last active Jan 11, 2019
Marks invalid UITextFields red in iOS. If valid, restores original border.
View InvalidTextFields
#import <QuartzCore/QuartzCore.h>
// Form validation. You'll probably place this in your buttonClicked action
if ([textField.text isEqualToString:@""]) // checks if field is empty, add other form validation here
{
textField.layer.cornerRadius = 8.0f;
textField.layer.masksToBounds = YES;
textField.layer.borderColor = [[UIColor redColor] CGColor];
textField.layer.borderWidth = 1.0f;
}
You can’t perform that action at this time.