Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@christianroman
christianroman / HomeViewController.m
Created February 6, 2014 16:18
Facebook Paper clone using Auto Layout and UIScrollView (First attempt)
//
// HomeViewController.m
// Stories
//
// Created by Christian Roman on 05/02/14.
// Copyright (c) 2014 Christian Roman. All rights reserved.
//
#import "HomeViewController.h"
#import "StoryView.h"
@christianroman
christianroman / ScrollViewController.m
Last active April 7, 2016 07:39
UIScrollView + Auto Layout, no frames no contentSize
UIScrollView *scrollView = [UIScrollView new];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:scrollView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|"
options:0
metrics:nil
views:@{@"scrollView" : scrollView}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|"
@christianroman
christianroman / MyController.h
Last active January 1, 2016 08:19
Objective-C trivia
typedef void (^AboutBlock)();
@interface MyController : UIViewController {
AboutBlock aboutBlock;
}
@end
@christianroman
christianroman / CRClient+Requests.h
Last active January 1, 2016 02:19
AFNetworking 2.0, Mantle, NSURLSession API design
//
// CRClient+Requests.h
// CRClient
//
// Created by Christian Roman on 20/12/13.
// Copyright (c) 2013 Christian Roman. All rights reserved.
//
#import "CRClient.h"
#import "CRCompletionBlocks.h"
@christianroman
christianroman / labelmaker.py
Created December 9, 2013 06:29
Facebook Hacker Cup Round 1: Labelmaker
ls, out = [line.strip() for line in open('input')], ''
for t in xrange(1, int(ls[0]) + 1):
st, n = ls[t].split(' ')
n, k, l, p, r = int(n), len(st), 0, 1, ''
while n >= p:
n -= p
p *= k
l += 1
for i in range(l):
r += st[n % k]
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
@christianroman
christianroman / basketball_game.py
Last active December 29, 2015 07:29
Facebook Hacker Cup: Basketball Game
lines, w, out, l, c = [line.strip() for line in open('basketball_game.txt')], ' ', '', 1, 0
while l < lines.__len__():
s = lines[l].split(w)
tp, rt, ts = int(s[0]), int(s[1]), int(s[2])
tmp = lines[slice(l + 1, l + tp + 1)]
pl = [{'name': i.split(w)[0], 'shot': i.split(w)[1], 'height': i.split(w)[2]} for i in tmp]
srtd = sorted(pl, key=lambda k: (k['shot'], k['height']), reverse=True)
t1, t2 = srtd[0:][::2], srtd[1:][::2]
nt1 = t1[-rt % len(t1):] + t1[:-rt % len(t1)]
nt2 = t2[-rt % len(t2):] + t2[:-rt % len(t2)]
@christianroman
christianroman / macros.h
Last active December 27, 2015 00:39
Personal use debugging macros
#ifdef DEBUG
#define DLog(...) NSLog(__VA_ARGS__)
#else
#define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
#ifdef DEBUG
#define DLog(format, ...) NSLog((@"%s [Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@christianroman
christianroman / NSLog.m
Created October 30, 2013 19:26
Enhanced NSLog function
#ifdef VERBOSE_DEBUG_LOGGING
# define NSLog(fmt, ...) NSLog((@"%s(%d) " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define NSLog(...)
#endif
- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
if (blur < 0.f || blur > 1.f) {
blur = 0.5f;
}
int boxSize = (int)(blur * 100);
boxSize = boxSize - (boxSize % 2) + 1;
CGImageRef img = image.CGImage;
vImage_Buffer inBuffer, outBuffer;