Skip to content

Instantly share code, notes, and snippets.

View hpneo's full-sized avatar

Gustavo Leon hpneo

View GitHub Profile
@hpneo
hpneo / GMaps.js
Created October 8, 2011 00:55
GMaps.js
GMaps = function(options){
this.div = $(options.div)[0];
this.markers = [];
this.polygon = null;
this.infoWindow = null;
this.map = new google.maps.Map(this.div, {
zoom: 15,
center: new google.maps.LatLng(options.lat, options.lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
@hpneo
hpneo / gmaps_random_polygon.js
Created October 22, 2011 04:15
Generar un polígono con puntos, aleatoriamente.
map = new GMaps({
div: '#map',
lat: -12.043333,
lng: -77.028333,
tilesloaded: function(){
var path = [];
var bounds = map.map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
for(var i=1;i<=4;i++){
@hpneo
hpneo / gist:1440782
Created December 7, 2011 00:26
Evitar perder sesiones al realizar requests vía AJAX
$.ajax({
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
data1: value1,
data2: value2,
data3: value3
});
<?php
include('vpos_plugin.php');
$array_send = array();
$array_get = array();
$array_send['acquirerId'] = 117;
$array_send['commerceId'] = 5654;
$array_send['purchaseAmount'] = 100;
$array_send['purchaseCurrencyCode'] = 604;
@hpneo
hpneo / gist:2886225
Created June 7, 2012 02:43
Get list of attributes and methods
var map = new GMaps();
for(i in map){
if(typeof(map[i])=='object' && map[i]){
console.log(i+': '+map[i].constructor.name);
}
else{
console.log(i+': '+typeof(map[i]));
}
}
after_filter :store_location
def store_location
session[:previous_urls] ||= []
session[:previous_urls].unshift request.fullpath if session[:previous_urls].first != request.fullpath
session[:previous_urls].pop if session[:previous_urls].count > 2
end
def after_sign_in_path_for(resource)
session[:previous_urls].last || root_path
@hpneo
hpneo / gist:3978079
Created October 30, 2012 03:04
XMLParser
require 'xml'
require 'active_support/inflector'
class XMLParser
attr_accessor :xml_string, :xml, :root
def initialize(xml_string)
self.xml_string = xml_string
end
@hpneo
hpneo / gist:4057064
Created November 12, 2012 01:34
Regla de ejemplo (CLIPS)
(assert (estadoAnimo depresivo))
(assert (nivelInteres bajo))
(assert (consumoDrogas no))
(defrule episodioDepresivoMayor
(or (estadoAnimo depresivo) (estadoAnimo irritable))
(nivelInteres bajo)
(perdidaPeso si)
(perdidaApetito si)
(capacidadConcentracion bajo)
@hpneo
hpneo / gist:4057094
Created November 12, 2012 01:50
Reglas para transtornos del estado de ánimo
(defrule episodioDepresivoMayor
(or (estadoAnimo depresivo) (estadoAnimo irritable))
(nivelInteres bajo)
(perdidaPeso si)
(perdidaApetito si)
(capacidadConcentracion bajo)
(provocaMalestarLaboral si)
(provocaMalestarSocial si)
(consumoDrogas no)
(tieneTranstornosDeMetabolismo no)
@hpneo
hpneo / gist:4343241
Created December 20, 2012 06:01
ActiveRecord-like methods for arrays of objects (usage)
collection = [{
title : 'Product #1',
price : 10.00,
created_at : '2012-12-20'
}, {
title : 'Product #2',
price : 15.00,
created_at : '2012-12-10'
}, {
title : 'Product #3',