Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@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: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: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: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 / 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 / JSONRequest.h
Last active December 11, 2015 19:08
AFNetworking delegate pattern used in JSON requests
#import <Foundation/Foundation.h>
@class JSONRequest;
@protocol JSONRequest <NSObject>
- (void)didReceiveJSONResponse:(id)objectResponse;
- (void)didNotReceiveJSONResponse:(NSError *)error;
@end
@christianroman
christianroman / gist:4653469
Created January 28, 2013 06:29
Find n coordinates around given latitude and longitude
private static ArrayList<Point> findAroundCoordinates(Double lat, Double lon, Double range){
// Number of points
int numberOfPoints = 32;
Double degreesPerPoint = 360.0 / numberOfPoints;
int currentAngle = 0;
Double x2;
Double y2;
@christianroman
christianroman / gist:4772868
Last active December 12, 2015 12:38
SGCODE 12 Febrero
lines, out = [line.strip() for line in open('data.in')], ''
for x in xrange(1, int(lines[0])+1):
l = lines[x].upper()
import re
for w in l.split(' '):
m = re.search('^h.+o|^p.*r$', w, re.IGNORECASE)
l = l.replace(w, "#" * w.__len__()) if m and m.groups() > 0 else l
out += l + "\n"
with open ('data.out', 'w') as f: f.write (out)
@christianroman
christianroman / gist:5665218
Last active December 17, 2015 20:09
Restore tmux session after reboot
#!/bin/zsh
SESSIONNAME="script"
tmux has-session -t $SESSIONNAME &> /dev/null
if [ $? != 0 ]
then
tmux new-session -s $SESSIONNAME -n script -d
tmux send-keys -t $SESSIONNAME "~/bin/script" C-m
fi
@christianroman
christianroman / test.py
Created May 30, 2013 16:02
Bypass Captcha using 10 lines of code with Python, OpenCV & Tesseract OCR engine
import cv2.cv as cv
import tesseract
gray = cv.LoadImage('captcha.jpeg', cv.CV_LOAD_IMAGE_GRAYSCALE)
cv.Threshold(gray, gray, 231, 255, cv.CV_THRESH_BINARY)
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
api.SetPageSegMode(tesseract.PSM_SINGLE_WORD)
tesseract.SetCvImage(gray,api)
print api.GetUTF8Text()