Skip to content

Instantly share code, notes, and snippets.

James Buczkowski jslnriot

View GitHub Profile
View super-props.js
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
example: 'test'
};
}
View web-scraper_package.json
{
"name": "amazon-web-scaper",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon -r esm index.js"
},
"keywords": [],
View web-scraper_scrape.js
import axios from 'axios';
import cherrio from 'cheerio';
async function getHTML(productURL) {
const { data: html } = await axios.get(productURL, {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'
}
})
.catch(function (error) {
View web-scraper-index.js
import { getHTML, getAmazonPrice } from './scrape';
const productURL = `https://www.amazon.ca/Vitamix-Explorian-Professional-Grade-Low-Profile-Refurbished/dp/B07CXVSMZ4/ref=sr_1_5?keywords=vitamix&qid=1555870204&s=gateway&sr=8-5&th=1`;
async function scrapePage() {
const html = await getHTML(productURL);
const amazonPrice = await getAmazonPrice(html);
console.log(`The price is ${amazonPrice}`);
}
View node-passport-example.js
const express = require('express');
// Passport
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const keys = require('./config/keys');
const app = express();
View redux-observer-class.js
class MessageInput extends React.Component {
state = {
value: '',
}
onChange = (e) => {
this.setState({
value: e.target.value,
})
};
View redux-createStore-clone.js
function createStore(reducer, initialState) {
let state = initialState;
// Setup listners to keep track of when the state is changed
// to triger rerenders (observer pattern)
const listeners = [];
const subscribe = (listener) => (
listeners.push(listener)
);
View bootstrapping-a-react-project.json
{
"name": "SpinMyVinylServer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha ./**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
View node-add-agruments.js
const argumentList = process.argv;
const addThese = argumentList.slice(2,argumentList.length);
let sum = 0;
let solution = addThese.forEach((value) => {
// convert to a number
sum += Number(value);
return sum;
});
View sass-mixin-with-default.scss
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
$Color1: navy; // named color value
$Color2: #333333; // hex color value
$StringVar: " with Sass"; // string variable
$FontSize: 18px; // numeric value
$border: 1px solid $Color2; // multi-value variable
You can’t perform that action at this time.