Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@christianroman
christianroman / beautiful_strings.py
Created January 26, 2013 02:59
Facebook Hacker Cup. Beautiful Strings
lines = [line.strip() for line in open('beautiful_stringstxt.txt')]
m = lines[0]
out = ''
for x in xrange(1, int(m)+1):
l = lines[x].lower()
dic = {}
line = ''
for i in l:
if i not in dic:
@christianroman
christianroman / gist:4339581
Created December 19, 2012 19:13
Convert UIImage's alpha channel to mask
- (CGImageRef)createMaskWithImageAlpha:(CGContextRef)originalImageContext
{
UInt8 *data = (UInt8 *)CGBitmapContextGetData(originalImageContext);
float width = CGBitmapContextGetBytesPerRow(originalImageContext) / 4;
float height = CGBitmapContextGetHeight(originalImageContext);
int strideLength = ROUND_UP(width * 1, 4);
unsigned char * alphaData = (unsigned char * )calloc(strideLength * height, 1);
CGContextRef alphaOnlyContext = CGBitmapContextCreate(alphaData,
@christianroman
christianroman / gist:3445232
Created August 24, 2012 03:48
Floating Point digits
/*
* File: main.cpp
* Author: christian
*
* Created on 21 de noviembre de 2011, 14:00
*/
#include <cstdlib>
#include <math.h>
#include <stdio.h>
@christianroman
christianroman / gist:3445224
Created August 24, 2012 03:45
Floating point
/*
* File: main.cpp
* Author: christian
*
* Created on 9 de junio de 2012, 9:07
*/
#include <cstdlib>
#include <math.h>
#include <stdio.h>
@christianroman
christianroman / gist:3407636
Created August 20, 2012 20:35
Get Property Type from an Object
static char *getPropertyType(objc_property_t property) {
const char *attributes = property_getAttributes(property);
const char *start;
int len = strlen(attributes);
if (len >= 3 && attributes[0] == 'T' && attributes[1] == '@' && attributes[2] == '"') {
start = attributes + 3;
char *end = strchr(start, '"');
@christianroman
christianroman / gist:3297430
Created August 8, 2012 18:43
Google Basketball Doodle Hack
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class GoogleDoodle {
static {
try {
Robot r = new Robot();
Thread.sleep(2000);
int b[]={1,5,4,4,1,3,2};
@christianroman
christianroman / gist:3297420
Created August 8, 2012 18:42
Google Basketball Doodle Hack
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class GoogleDoodle {
static {
try {
Robot r = new Robot();
Thread.sleep(2000);
int b[]={1,5,4,4,1,3,2};
@christianroman
christianroman / gist:3248993
Created August 3, 2012 16:03
Check if UITextFields are empty using Objective-C
- (BOOL)emptyTextFields:(id)toCompare, ...
{
va_list args;
va_start(args, toCompare);
id value = nil;
BOOL match = NO;
while ((value = va_arg(args,id)))
if([toCompare isKindOfClass:[NSString class]] && [value isKindOfClass:[UITextField class]])
if([[(UITextField *)value text] isEqualToString:toCompare])
@christianroman
christianroman / gist:3242465
Created August 3, 2012 00:16
Switch Object in Objective-C
BOOL switchObject(id anObject, ...)
{
va_list args;
va_start(args, anObject);
id value = nil;
BOOL matchFound = NO;
while ( (value = va_arg(args,id)) )
{
@christianroman
christianroman / gist:3191095
Created July 27, 2012 23:46
UITableViewCell gradient using Quartz 2D
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 1,
0.95, 0.95, 0.95, 1 };
rgbColorspace = CGColorSpaceCreateDeviceRGB();