Skip to content

Instantly share code, notes, and snippets.

View itzsaga's full-sized avatar
🍕

Seth itzsaga

🍕
View GitHub Profile
// 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})
$('.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']} -
$('.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'])
let itemsValues
$(() => {
$.getJSON('/items.json', function (data) {
itemsValues = $.map(data, function (e) {
return e.id
})
})
})
// 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>`
)
})
@itzsaga
itzsaga / sidekiq2.rb
Last active June 7, 2017 04:34
Examples for my "100 Days of Flatiron School Bootcamp" blog post
# app/controllers/customers_controller.rb
class CustomersController < ApplicationController
def index
@customers = Customer.all
end
def upload
LeadsWorker.perform_async(params[:leads].path)
@itzsaga
itzsaga / sidekiq1.rb
Last active June 7, 2017 04:34
Examples for my "100 Days of Flatiron School Bootcamp" blog post
# 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
Point.prototype.toString = function () {
return `(${this.x}, ${this.y})`
}
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)
let obj = {a:1, b:2, c:3}
let {a, b, c} = obj