Skip to content

Instantly share code, notes, and snippets.

View esbanarango's full-sized avatar
👨‍🚀
Desayunando

Esteban esbanarango

👨‍🚀
Desayunando
View GitHub Profile
require 'roo'
require 'axlsx'
require 'fileutils'
class XlsScript
attr_accessor :file_path
def initialize(file_path)
@file_path = file_path
/*Geo map for COLOMBIA WITH COORDS https://developers.google.com/chart/interactive/docs/gallery/geomap*/
function drawVisualization() {
var dataTable = new google.visualization.DataTable();
dataTable.addRows(3);
dataTable.addColumn('number', 'LATITUDE', 'Latitude');
dataTable.addColumn('number', 'LONGITUDE', 'Longitude');
dataTable.addColumn('number', 'Votantes', 'Value'); // Won't use this column, but still must define it.
@esbanarango
esbanarango / AR_calculations_plus_sql.md
Created December 29, 2013 18:01
ActiveRecord::Calculations can receive SQL functions.

ActiveRecord::Calculations can receive SQL functions.

sum("CAST(total AS float)")
average("CAST(total AS float)")

total dataType is String.

select.form-control + .chosen-container{
display: block;
width: 100% !important;
}
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
{
"check_for_rvm": true,
"run_rspec_command": "bundle exec /Users/esbanarango/.rbenv/shims/rspec {relative_path} -f d"
}
@esbanarango
esbanarango / gist:7311201
Created November 4, 2013 23:31
Salsamentaria 'El Sebiche'

Pedidos Salsamentaria 'El Sebiche'

Producto Cantidad Valor Descripción / Comentario
Apple Magic Mouse 1 $35 De segunda
Mackbook Decal 3 $10.39 Calcomanías pal mac (Link 1, Link 2)
Hard case cover 3 $59.97 Protectores pal mac (1 air, 1 macpro, 1 macpro retina)
iPhone 5 - Green Carbon Fiber 1 $21.21 Protector pal iPhone
@esbanarango
esbanarango / gist:6629748
Last active May 8, 2018 18:12
HTML <input> required attribute and Rails form with remote true.

<input> with attribute required

This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate.

How to show a spinner only when the required validations pass? (Without using any validation plugin, only the required attribute).

Form with a required input

= form_for @person, remote: true do |f|
 = f.text_field, :first_name, required: true
@esbanarango
esbanarango / explenation.md
Last active December 20, 2015 14:49
Accessing and editing an attribute from has_many :through join model.

Accessing and editing attributes from has_many :through join model.

This a solution for a problem that I recently faced.

Let's say we have these three classes Store, PaymentMethod and StorePaymentMethodSetting. A store may have multiple payment methods and these payment methods are similar between the stores. So here we have a HABTM (has and belongs to many) relationship between the Store and the Payment Method. I didn't use HABTM relationship, instead, I used has_many :through relationship, that's because I needed to use the relationship model (StorePaymentMethodSetting) as an independent entity to set the availability of a payment method in a store. Although I would always recommend using has_many :through instead of has_and_belongs_to_many, you never know if in the future you'll need the relationship model to have some attributes.

So here comes the problem, I wanted to update the availability of a payment method through the payment method itself. I mean, I didn't wanted to have

@esbanarango
esbanarango / README BDNG.md
Created December 2, 2012 18:40
Descripción para aplicación de búsqueda de BDNG

#BDNG

Biblioteca Digital de Nueva Generación

###Búsquedas

La aplicación de búsquedas de BDNG está compuesta por dos partes, aplicación Front-end (JavaScript) y Back-end (xQuery). Se recomienda tener conocimiento previo de xQuery para poder entender mejor la estructura y funcionamiento del Back-end.

Aquí algunos links que pueden ser de gran utilidad.

@esbanarango
esbanarango / distance_calculation.sql
Created November 16, 2012 10:52
MySQL calculate distance between two latitude/longitude coordinates, assuming radius of 6,371 km
CREATE FUNCTION `lat_lng_distance` (lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT)
RETURNS FLOAT
DETERMINISTIC
BEGIN
RETURN 6371 * 2 * ASIN(SQRT(
POWER(SIN((lat1 - abs(lat2)) * pi()/180 / 2),
2) + COS(lat1 * pi()/180 ) * COS(abs(lat2) *
pi()/180) * POWER(SIN((lng1 - lng2) *
pi()/180 / 2), 2) ));
END