This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fetch places | |
function fetchPlaces () { | |
return (dispatch) => { | |
dispatch({type: 'FETCH_PLACES'}) | |
return fetch('http://localhost:3001/api/places') | |
.then(response => { | |
dispatch({type: 'RECEIVED_PLACES', payload: response}) | |
}) | |
.catch((err) => { | |
dispatch({type: 'FETCH_PLACES_ERROR', payload: err}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.js-next').on('click', function() { | |
let nextIndex | |
let dataIdIndex = itemsValues.indexOf(parseInt($('.js-next').attr('data-id'))) | |
if (dataIdIndex === itemsValues.length - 1) | |
nextIndex = 0 | |
else | |
nextIndex = dataIdIndex + 1 | |
$.getJSON('/items/' + itemsValues[nextIndex], function(data) { | |
$('#name').html(`${data['name']} - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.js-next').on('click', function() { | |
let nextIndex = itemsValues.indexOf(parseInt($('.js-next').attr('data-id'))) + 1 | |
$.getJSON('/items/' + itemsValues[nextIndex], function(data) { | |
$('#name').html(data['name']) | |
$('#rating').html(data['rating']) | |
$('#notes').html(data['notes']) | |
if (nextIndex === itemsValues.length) | |
$('.js-next').attr('data-id', itemsValues[0]) | |
else | |
$('.js-next').attr('data-id', data['id']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let itemsValues | |
$(() => { | |
$.getJSON('/items.json', function (data) { | |
itemsValues = $.map(data, function (e) { | |
return e.id | |
}) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With ES6 Template Literals | |
data.items.forEach(function (item) { | |
itemList = itemList.add(`<li><strong><a href='/items/${item['id']}'>${item['name']}</a></strong> | |
<ul> | |
<li>Rating: ${item['rating']}</li> | |
<li>Notes: ${item['notes']}</li> | |
</ul>` | |
) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/customers_controller.rb | |
class CustomersController < ApplicationController | |
def index | |
@customers = Customer.all | |
end | |
def upload | |
LeadsWorker.perform_async(params[:leads].path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/workers/leads_worker.rb | |
class LeadsWorker | |
require 'csv' | |
include Sidekiq::Worker | |
def perform(leads_file) | |
CSV.foreach(leads_file, headers: true) do |lead| | |
Customer.create(email: lead[0], first_name: lead[1], last_name: lead[2]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point.prototype.toString = function () { | |
return `(${this.x}, ${this.y})` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Point (x, y) { | |
this.x = x | |
this.y = y | |
} | |
Point.prototype.toString = () => { | |
return `(${this.x}, ${this.y})` | |
} | |
// In the terminal | |
> var p = new Point(2,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = {a:1, b:2, c:3} | |
let {a, b, c} = obj |