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
// takes a large array of items, chunks them, performs an async task on that item | |
import { chunk } from "lodash"; | |
function wait(time: number) { // in ms | |
return new Promise(resolve => setTimeout(resolve, time)); | |
} | |
export async function batch( | |
arr: any, |
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
def ProductFiltersDataHelper.furniture_types | |
[ | |
{name: "all", types: "all"},{name: "sofas and loveseats", types: "!table sofa couch sectional loveseat settee"}, | |
{name: "wardrobes", types: "wardrobe armoire chifforobe"},{name: "buffets", types: "buffet sideboard credenza"}, | |
{name: "chairs and stools", types: "chair armchair recliner stool rocker"},{name: "tables", types: "table sidetable"}, | |
{name: "beds", types: "!table bed"},{name: "desks", types: "desk"}, | |
{name: "bookcases and shelves", types: "!desk bookcase shelves"},{name: "cabinets", types: "cabinet"}, | |
{name: "mirrors", types: "mirror"} | |
] | |
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
//uses jquery to send request to rails 5 built api-only backend | |
$('.sales-filters input').on('click', function() { | |
var params = {}; | |
var filters = $('.sales-filters input:checked'); //get array of all checked radio buttons | |
for (i = 0; i < filters.length; i++) { | |
params[filters[i].name] = filters[i].value //dynamically create params for GET request based on name and value attributes | |
} | |
var url = window.location.origin + '.....' | |
fetchAndPaginate(url,params) |
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
#utilize a background job - using sidekiq with redis queue | |
class ApisSalesFinders::BestbuySalesFinderWorker < ApisSalesFinders::SalesFinders | |
include Sidekiq::Worker | |
require './app/models/scrape_constants/collections' #ebay product categories | |
def perform | |
current_items = Product.where(retailer: "best buy") | |
discount = 10 | |
minimum_price = 75 #used to filter out some accessory products |
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
//find max value in array of objects with key as argument | |
function findMax(key) { | |
return function maxx(prev,curr) { | |
return Math.max(prev, curr[key]); | |
} | |
} | |
//then pass function to reduce with key as argument | |
//eg get max price from an array of objects | |
var maxPrice = array.reduce(findMax("price"),0); |
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
#Accepts all image files and pdfs. If the upload is a pdf, it is converted to a jpg | |
#Paperclip incorporates ImageMagick. If a multipage page PDF, only the first page is converted | |
#Model | |
#here the original style needs to be given source_file_options. It's critical that the original file is not passed geometry | |
#or the resolution won't really improve | |
has_attached_file :avatar, | |
styles: lambda { |attachment| | |
styles = {} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="css/styles.css"> |