Skip to content

Instantly share code, notes, and snippets.

View christianroman's full-sized avatar

Christian Roman christianroman

  • Mexico
View GitHub Profile
@christianroman
christianroman / Alumno.java
Created April 23, 2012 05:47
Hibernate Many-To-Many with Extra Columns
package org.cobaem.domain;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
@christianroman
christianroman / AES-RSA.java
Created May 11, 2012 03:48
Generate AES secret key
public static void main(String[] args) {
String plainText = "Very secret data";
AES aesClient = new AES("client");
SecretKey AESKey = aesClient.getEncodedSecret();
RSA rsaClient = new RSA();
byte[] RSAcipher = rsaClient.EncryptSecretKey(AESKey);
String cipherData = aesClient.encryptAndSerialize(plainText);
// Assume that client sends the cipherData and RSAcipher to the server...
@christianroman
christianroman / OCR.java
Created May 15, 2012 01:59
Captcha OCR + Tesseract
public class OCR {
private static final String INPUT = "C:/captcha/ex.png";
private static final String OUTPUT = "C:/captcha/captcha-out.png";
private static final String TESSERACT_BIN = "C:/Program Files/Tesseract-OCR/tesseract.exe";
private static final String TESSERACT_OUTPUT = "C:/captcha/out.txt";
private static final int WHITE = 0x00FFFFFF, BLACK = 0x00000000;
public static void main(String... args) throws Exception {
BufferedImage image = ImageIO.read(new FileInputStream(INPUT));
int average = 0;
@christianroman
christianroman / OCR.java
Created May 15, 2012 02:53
Captcha OCR + Tessaract Complex
public class OCR {
private static final String INPUT = "C:/captcha/ex.png";
private static final String OUTPUT = "C:/captcha/captcha-out.png";
private static final String TESSERACT_BIN = "C:/Program Files/Tesseract-OCR/tesseract.exe";
private static final String TESSERACT_OUTPUT = "C:/captcha/out.txt";
private static final int WHITE = 0x00FFFFFF, BLACK = 0x00000000;
public static void main(String... args) throws Exception {
BufferedImage image = ImageIO.read(new FileInputStream(INPUT));
int average = 0;
@christianroman
christianroman / OCR.java
Created May 15, 2012 02:53
Captcha OCR + Tessaract Complex
public class OCR {
private static final String INPUT = "C:/captcha/ex.png";
private static final String OUTPUT = "C:/captcha/captcha-out.png";
private static final String TESSERACT_BIN = "C:/Program Files/Tesseract-OCR/tesseract.exe";
private static final String TESSERACT_OUTPUT = "C:/captcha/out.txt";
private static final int WHITE = 0x00FFFFFF, BLACK = 0x00000000;
public static void main(String... args) throws Exception {
BufferedImage image = ImageIO.read(new FileInputStream(INPUT));
int average = 0;
@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();
@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: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: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: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};