Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<title>My awesome app</title>
</head>
<body>
<h2>beta builds</h2>
<a href="itms-services://?action=download-manifest&amp;url=http://dl.dropbox.com/u/1001/manifest.plist">Awesome App v 0.0.16</a></body>
<h2>alpha builds</h2>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
@2ndmouse
2ndmouse / gist:257087afa433029bcaff
Created January 9, 2015 08:24
Keep y position while adding row at top of UICollectionView or UITableView
- (void) loadHistory {
CGFloat oldOffsetReversed = self.collectionView.contentSize.height - self.collectionView.contentOffset.y;
NSUInteger pageSize = [self fetchNextPage]; //reloadData is called inside
[self.view layoutIfNeeded];
CGFloat offset = self.collectionView.contentSize.height - oldOffsetReversed;
self.collectionView.contentOffset = CGPointMake(self.collectionView.contentOffset.x, offset);
}
@2ndmouse
2ndmouse / gist:185e348cbeda56b2f69a
Last active August 29, 2015 14:12
Store a function in a block
// MyBlockClass.h
@interface MyBlockClass : NSObject
- (id)initView:(UIScrollView *)scrollView withDataHandler:(void (^) (int pageNumber))handler;
@end
// MyBlockClass.m
@interface MyBlockClass ()
@property (nonatomic, copy) void (^getDataOnPage)(int pageNumber);
@end
@2ndmouse
2ndmouse / gist:27be93bff81c58e44aef
Created December 30, 2014 23:33
Fixed the problem of "UITableview and tabbar overlapping"
- (void)loadView{
// cannot set the height here because the data has not been loaded into the tableview yet
// so I just set it to zero
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero
style:UITableViewStylePlain];
}
// set the custom height here
- (void)viewWillLayoutSubviews{
self.tableView.frame = CGRectMake(0, 0, [self widthForView], [self heightForView]);
@2ndmouse
2ndmouse / gist:23e8de8e344e2faddd07
Created December 14, 2014 23:56
Add pull to refresh using apple default
// add this in viewDidLoad
// Configure Refresh Control
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
// create an envent
#pragma mark Events
- (void) refresh:(id)sender {
[self loadData]; // create your own function to load the data, and at the end call [self.collecitonView reloadData]
@2ndmouse
2ndmouse / gist:c9b3e5cd7c0784966624
Last active August 29, 2015 14:09
50-US-states
states = @{
@"AL": @"Alabama",
@"AK": @"Alaska",
@"AZ": @"Arizona",
@"AR": @"Arkansas",
@"CA": @"California",
@"CO": @"Colorado",
@"CT": @"Connecticut",
@"DE": @"Delaware",
@"FL": @"Florida",
@2ndmouse
2ndmouse / gist:dc08441373174db1a1e5
Last active August 29, 2015 14:08
Tab + navigation setup in AppDelegation
// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@end
// AppDelegate.m
@implementation AppDelegate
@2ndmouse
2ndmouse / gist:9885489
Created March 31, 2014 04:49
Django save uploaded file to disk
from django.core.files.temp import NamedTemporaryFile
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
# if you actually need the file
class MyMixin(object):
def pre_save(self, obj):
default_storage.save('/Users/2ndmouse/code/media/a.jpg', ContentFile(self.request.FILES['image'].read()))
# download online file and save it to image field
@2ndmouse
2ndmouse / gist:9560557
Created March 15, 2014 01:34
Get relative time in Django view and template
# in view
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2014, 3, 14, 20, 26, 33, 431064)
>>> a = datetime.datetime.now()
>>> from django.contrib.humanize.templatetags.humanize import naturalday, naturaltime
>>> naturalday(a)
u'today'
>>> naturalday(a)
u'today'