Skip to content

Instantly share code, notes, and snippets.

View sergiosvieira's full-sized avatar

Sérgio Vieira sergiosvieira

  • Fortaleza
View GitHub Profile
for (NSUInteger i = 0; i < [info.allKeys count]; i++)
{
NSString *field = info.allKeys[i];
SEL setField = NSSelectorFromString([NSString stringWithFormat:@"set%@", field]);
if ([newUser respondsToSelector:setField])
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
@sergiosvieira
sergiosvieira / gist:5657210
Created May 27, 2013 13:59
design patterns
public interface XMPPActions
{
public abstract void sendMessageWithBody(String text, String jid);
}
public class XMPPNormalActions implements XMPPActions
{
- void sendMessageWithBody(String text, String jid)
{
/** código relacionado ao envio de mensagem usando chat normal **/
@sergiosvieira
sergiosvieira / snippet.m
Created June 7, 2013 15:51
sorting array of keys of nsdictionary based on value of nsdictionary
NSDictionary *original = @{
@"Campo de Teste" : @{@"order" : @"1"},
@"Alguma coisa" : @{@"order" : @"4"},
@"outro teste" : @{@"order" : @"2"},
@"fala cara" : @{@"order" : @"3"},
};
NSArray *sortedArray;
sortedArray = [original.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *a, NSString *b) {
@sergiosvieira
sergiosvieira / snippet.m
Last active December 18, 2015 05:09
notification center keyboard observer
- (void)enableKeyboardNotifications
{
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
Try to reduce the size of images
If you cannot reduce the size for any reasons, try the below code (operationQueue is an ivar of the instance of NSOperationQueue)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
[operationQueue addOperationWithBlock:^{
@sergiosvieira
sergiosvieira / gist:5852472
Created June 24, 2013 18:52
drop shadow in tableview
self.tableView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
self.tableView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
self.tableView.layer.shadowOpacity = 0.4;
self.tableView.layer.shadowRadius = 5.0f;
self.tableView.clipsToBounds = NO;
self.tableView.layer.masksToBounds = NO;
@sergiosvieira
sergiosvieira / gist:5867157
Created June 26, 2013 12:55
Git Userful Commands
*** initializing submodules ***
$ git submodule init
$ git submodule update
@sergiosvieira
sergiosvieira / gist:5884547
Created June 28, 2013 13:10
Diff between NSDates in seconds
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [dateFormatter dateFromString:@"2013-06-28 00:00:00"];
@sergiosvieira
sergiosvieira / gist:5968029
Last active December 19, 2015 14:18
Multiples of 5, 7 and 35
#import <Foundation/Foundation.h>
/**
Author: Sérgio Vieira - sergiosvieira@gmail.com - 2013
**/
int main(int argc, char *argv[]) {
@autoreleasepool {
NSUInteger max = 100;
@sergiosvieira
sergiosvieira / banco-sergiosvieira.cc
Created July 11, 2013 02:50
OBI2012, Fase 2, Nível 2
#include <iostream>
#include <cstdio>
#include <queue>
/**
Author: Sérgio Vieira - sergiosvieira@gmail.com - 2013
Usage: banco < entrada.txt
**/
using namespace std;