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:5835899
Created June 22, 2013 04:41
Install PostgreSQL 9.2 + PostGIS on CentOS 6
rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
yum install postgresql92 postgresql92-server postgresql92-contrib postgis2_92 postgis2_92-utils
chkconfig postgresql-9.2 on
service postgresql-9.2 initdb
service postgresql-9.2 start
@christianroman
christianroman / NSString+Concatenation.h
Last active January 29, 2018 14:08
NSString+Concatenation
#import <Foundation/Foundation.h>
@interface NSString (Concatenation)
- (NSString *):(NSString *)a;
- (NSString *):(NSString *)a :(NSString *)b;
- (NSString *):(NSString *)a :(NSString *)b :(NSString *)c;
- (NSString *):(NSString *)a :(NSString *)b :(NSString *)c :(NSString *)d;
- (NSString *)concat:(NSString *)strings, ...;
@christianroman
christianroman / implementation.mm
Created June 10, 2013 05:28
Mixing C, C++, Objective-C
#if defined _cplusplus
extern "C" {
#endif
void your_c_function()
{
...
}
#if defined _cplusplus
}
#endif
@christianroman
christianroman / training.sh
Last active November 22, 2024 21:52
Tesseract OCR training new font
#! /bin/bash
# build the environment
mkdir tessenv; cd tessenv
TROOT=`pwd`
mkdir $TROOT/stockfonts; mkdir $TROOT/build; mkdir $TROOT/build/eng
echo "Environment built"
# Get the stock english fonts from Google (old, but they work)
cd $TROOT/stockfonts
GET http://tesseract-ocr.googlecode.com/files/boxtiff-2.01.eng.tar.gz > boxtiff-2.01.eng.tar.gz
@christianroman
christianroman / _flash.html.erb
Last active December 18, 2015 02:09 — forked from potomak/_flash.html.erb
Rails flash messages using Twitter bootstrap 2
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert <%= flash_class(level) %>">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<span><%= flash[level] %></span>
</div>
<% end %>
<% end %>
@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()
@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 / 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: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 / 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