Skip to content

Instantly share code, notes, and snippets.

View eduardopoleo's full-sized avatar

Eduardo Poleo eduardopoleo

View GitHub Profile
$(function() {
//Captures the click event
$('.choice').click(function(e) {
//extracts the value of the radio button that was clicked which
//corresponds to a JSON route.
var url = e.target.defaultValue
//makes the corresponding ajax call
ajax_call(url, update)
});
//Sets plot's dimensions and other relevant values as paddings
//and margins
var w = 1000
var h = 1250
var xPadding = 10
var yPadding = 20
var xMargin = 200
var yMargin = 0
function draw(dataSet) {
//Appends a svg element and sets its dimensions using w and h
svg = d3.select('body')
.append('svg')
.attr("width", w)
.attr("height", h)
.attr("class", "graph")
.append('g')
.attr("transform", "translate(" + xMargin + "," + yMargin + ")")
//Calculates the scales with the initial data set
function update(dataSet) {
//Calculates the scales from the data set
var scales = calculateScales(dataSet)
var xScale = scales[0]
var yScale = scales[1]
var yAxisScale = scales[2]
//Calculates the axes using the previous calculated scales
var axes = calculateAxes(xScale, yAxisScale)
var xAxis = axes[0]
function draw(dataSet) {
//Appends a svg element and sets its dimensions using w and h
svg = d3.select('body')
.append('svg')
.attr("width", w)
.attr("height", h)
.attr("class", "graph")
.append('g')
.attr("transform", "translate(" + xMargin + "," + yMargin + ")")
//Calculates the scales with the initial data set
class City < ActiveRecord::Base
has_many :libraries
end
class Library < ActiveRecord::Base
belongs_to :city
has_many :books
end
class Book < ActiveRecord::Base
create_table "cities", force: :cascade do |t|
t.string "name"
t.integer "population"
t.boolean "is_capital"
t.string "major"
t.integer "area"
t.datetime "date_founded"
end
create_table "libraries", force: :cascade do |t|
class UsersController < ApplicationController
def create
@user = User.new(user_params)
if @user.save
flash[:success] = "Welcome to Monchitos. Hope you enjoy it!"
redirect_to posts_path
else
flash[:error] = "Sorry your registration could not be completed"
render :new
end
class UsersController < ApplicationController
def create
@user = User.new(user_params)
if @user.save
#Sends the invitation email using the regular Rails mailers
AppMailer.welcome_email(@user)
if params[:invitation_token].present?
invitation = Invitation.find_by(token: params[:invitation_token])
class UsersController < ApplicationController
def create
@user = UserSignupManager.perform(user_params, invitation_token)
if @user.errors.blank?
flash[:success] = "Welcome to Raysurfing. Hope you enjoy it!"
redirect_to posts_path
else
flash[:error] = "Sorry there was an error with your regitration"
render :new