Skip to content

Instantly share code, notes, and snippets.

#!/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 August 29, 2015 14:11
CoreData Simple Fetch
// 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 August 14, 2014 08:57
Round two corners on UIView
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;
}
__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 January 28, 2018 23:38
RestKit - Load data from local json file
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 March 15, 2013 10:54
Helper methods to show and hide Android layouts
// 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 January 21, 2019 18:02
Customizing the segmented control to be dark gray and green when selected. Note: this is not a subclass - just set it in your controller.
// 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 March 28, 2020 00:13
Marks invalid UITextFields red in iOS. If valid, restores original border.
#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;
}