Skip to content

Instantly share code, notes, and snippets.

View binho's full-sized avatar

Cleber Santos binho

View GitHub Profile
// Create an RBTCentralManager
self.manager = [[RBTCentralManager alloc] init];
// Scan and connect to all the peripherals
RACDisposable *disposable = [[[[[self.manager.stateSignal
takeUntilBlock:^BOOL(NSNumber *state) {
return (state.integerValue == CBCentralManagerStatePoweredOn);
}] then:^RACSignal *{
return [self.manager scanForPeripheralsWithServices:nil options:nil];
}] reduceEach:^(CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {

A number of tech news outlets, including WIRED, GigaOm, and MIT Technology Review, have recently started writing about Multipeer Connectivity ("one weird trick that the NSA hates"). Since the NSHipster article on the subject has been linked to in a lot of this coverage, I wanted to share some additional thoughts on the matter:

Multipeer Connectivity(http://nshipster.com/multipeer-connectivity/) represents a significant shift in the opposite direction of how we conventionally think about mobile applications. Nearly every app on your phone operates in a client-server model, with the device making requests to remote cloud services to send and receive messages, photos, and videos. The [

@mmick66
mmick66 / UICollectionViewFlowLayoutCenterItem.m
Last active August 2, 2022 10:06
UICollectionViewFlowLayout with arbitrary sized Paging
#import "UICollectionViewFlowLayoutCenterItem.h"
@implementation UICollectionViewFlowLayoutCenterItem
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGSize collectionViewSize = self.collectionView.bounds.size;
CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5f;
CGRect proposedRect = self.collectionView.bounds;
@kosta
kosta / inout.java
Created March 26, 2014 06:47
Copy stdin to stdout in Java
import java.io.IOException;
/**
* Class that copies stdin to stdout, as compained about as not being cleanly
* writable in Java on Hacker News.
* In real code, you would just write IOUtils.copy(System.in, System.out),
* which does basically the same thing.
* This does not catch any exceptions as a) this is just an "exercise" and
* b) all we could do with them is pretty-print them. So let the runtime
* print them for you.
@shto
shto / NSManagedObject+Cloner.h
Last active April 20, 2018 04:53
NSManagedObject cloner files
#import <CoreData/CoreData.h>
@interface NSManagedObject (Cloner)
- (NSManagedObject *)clone;
- (NSManagedObject *)cloneInContext:(NSManagedObjectContext *)differentContext;
@end
@kristopherjohnson
kristopherjohnson / fixDelaysContentTouches.m
Created March 8, 2014 17:47
Hack to allow controls in a UITableViewCell to immediately react to touches in iOS 7 (credit: http://stackoverflow.com/questions/19256996/uibutton-not-showing-highlight-on-tap-in-ios7)
- (void)fixDelaysContentTouches:(UITableViewCell *)cell {
// Hack to allow buttons to show highlight state immediately on touch
// See http://stackoverflow.com/questions/19256996/uibutton-not-showing-highlight-on-tap-in-ios7
for (id obj in cell.subviews) {
if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewCellScrollView"]) {
UIScrollView *scroll = (UIScrollView *) obj;
scroll.delaysContentTouches = NO;
break;
}
}
@jverkoey
jverkoey / shouldAutorotate_nonintrusive.m
Last active August 29, 2015 13:57
Implementing UINavigationController/UITabBarController support for shouldAutorotate without subclassing or extending.
// Add this to your app delegate.
// Neither `UINavigationController` nor `UITabBarController` have the slightest decency to ask their
// visible view controller whether IT would like to rotate and just go on and do whatever the hell
// they please. This'll show 'em.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController* topViewController = window.rootViewController;
do {
// Navigate modal controllers.
@dlo
dlo / Auto-layout-keyboard-adjustment.md
Last active February 26, 2021 07:33
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.

This gist outlines how to resize a view when a keyboard appears using Auto Layout (there are a bunch of code samples out there that manually adjust the view's frame, but that's just so 2013). The method I outline below works universally on both iPhone and iPad, portrait and landscape, and is pretty darn simple.

Setting Up

The first thing to do is to define our containing view controller, the view, and the bottom constraint that we'll use to adjust its size.

Here's HeightAdjustingViewController.h. We don't need to expose any public properties, so it's pretty bare.

// --------------------------------------------------------------------------------------
// A More Modern Scale for Web Typography
// Based on this article: http://typecast.com/blog/a-more-modern-scale-for-web-typography
// --------------------------------------------------------------------------------------
$body-font-size: 1em !default;
// Adjusts body typography to be default
// for each browser.
@mixin reset-body-font-size($font-size: 100%, $size-adjustment: 0.5) {
// I wish something like this (with a better name for the keyword):
@missing UILabel *titleLabel {
UILabel *label = [[UILabel alloc] init];
return label;
};
// Could turns into this:
@interface ViewController ()