Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@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;
@christianroman
christianroman / blendoverlay.m
Created October 26, 2013 07:11
Blend overlay
- (UIImage *)blendOverlay:(UIImage *)topImage withBaseImage:(UIImage *)baseImage toSize:(CGFloat)imageSize
{
UIGraphicsBeginImageContext(CGSizeMake(imageSize, imageSize));
[baseImage drawInRect:CGRectMake(0.0, 0.0, imageSize, imageSize)];
[topImage drawInRect:CGRectMake(0.0, 0.0, imageSize, imageSize) blendMode:kCGBlendModeNormal alpha:0.5];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@christianroman
christianroman / coloration.m
Created October 26, 2013 07:00
Icon coloration at runtime
-(UIImage *) negativeImage
{
UIGraphicsBeginImageContext(self.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.size.width, self.size.height));
UIImage *negativeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@christianroman
christianroman / blur.rb
Created October 11, 2013 18:33
Blurring images in Rails with Paperclip custom processor
module Paperclip
class Blur < Processor
def initialize file, options = {}, attachment = nil
super
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
end
@christianroman
christianroman / DatePickerDialogWithMinRange.java
Last active December 25, 2015 02:59
Custom DatePickerDialog class with min date (API Level < 11)
package com.chroman.test;
import android.app.DatePickerDialog;
import android.content.Context;
import android.widget.DatePicker;
/**
* Created by chroman on 09/10/13.
*/