Skip to content

Instantly share code, notes, and snippets.

View nax3t's full-sized avatar

Ian Schoonover nax3t

View GitHub Profile
@nax3t
nax3t / guessing-game-original.js
Created August 1, 2021 20:19
Guessing Game Refactor
let maximum = parseInt(prompt("Enter the maximum number!"));
while (!maximum) {
maximum = parseInt(prompt("Enter a valid number!"));
}
const targetNum = Math.floor(Math.random() * maximum) + 1;
let guess = parseInt(prompt("Enter your first guess!"));
let attempts = 1;
@nax3t
nax3t / stock-and-crypto-scraper.js
Created February 3, 2021 22:27
Web scraper program for getting current stock or crypto prices (e.g., GME, AMC, BTC-USD)
const axios = require('axios')
const cheerio = require('cheerio')
async function getPrice(symbol) {
try {
let { data } = await axios.get(`https://finance.yahoo.com/quote/${symbol}?p=${symbol}&.tsrc=fin-srch`)
let $ = cheerio.load(data)
// use this one for bitcoin
// console.log(`The current price of ${symbol} is:`, '$' + $('span[data-reactid="33"]').eq(1).text())
// use this one for aftermarket hours
@nax3t
nax3t / app.js
Last active November 11, 2019 19:30
Reading, Deleting, and Renaming Files with Node JS File System (fs) Module
// FS docs: https://nodejs.org/api/fs.html
const fs = require('fs');
fs.readdir('.', (err, files) => {
if(err) console.log(err);
let counter = 0;
files.forEach(file => {
// // match and delete thumbnails
// if(file.match(/\d\dx\d\d/)
// || file.match(/\d\d\dx\d\d\d/)
@nax3t
nax3t / wifikeepalive.js
Created May 10, 2019 18:34
node script to ping wifi every 10 minutes and restart it if it's down
const shell = require('shelljs');
const rp = require('request-promise');
async function testWifi() {
let count = 0;
try {
const result = await rp('http://www.google.com');
if (result) {
console.log('wifi working');
}
} catch(err) {
@nax3t
nax3t / README.md
Last active December 1, 2018 19:31
Add average rating to Post

Add average rating to Post

  • Add avgRating property to PostSchema (/models/post.js)
const PostSchema = new Schema({
	title: String,
	price: String,
	description: String,
	images: [ { url: String, public_id: String } ],
	location: String,
	coordinates: Array,
@nax3t
nax3t / mongoose-paginate-with-express.md
Last active April 23, 2021 23:14
Express JS Pagination with Mongoose

Add Pagination to Posts Index

  • Seed some post data
    • Install faker npm i -S faker
    • Create a seeds.js file in the root directory /surf-shop and open it
    • Require faker const faker = require('faker');
    • Require Post model const Post = require('./models/post');
@nax3t
nax3t / paperscript-sublimetext3-syntax.md
Last active December 28, 2020 16:04
Paperscript JS Syntax Highlighting - Sublime Text 3
  • Download and Install Sublime Text 3.1.1 Build 3176
  • Install Package Control (don't forget to restart Sublime after)
  • Install PackageResourceViewer (restart Sublime)
  • Open the Command Palette (Tools > Command Palette from Sublime task menu)
  • Enter open resource and select PackageResourceViewer: Open Resource
  • Enter html and select HTML
  • Enter sub and select HTML.sublime-syntax
  • Click Find > Find... from the Sublime task menu (or use cmd+f or ctrl +f) and search for (?:java|ecma)
  • Replace (?:java|ecma) on line 38 with (?:java|ecma|paper)
  • Save and close the file
@nax3t
nax3t / postsIndex
Created September 18, 2018 22:43
posts index method (get all posts or filter)
index: async (req, res, next) => {
let posts, filters, query;
// define escapeRegex function for search feature
const escapeRegex = (text) => {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
// check if filters exist
if (req.query.post) filters = Object.values(req.query.post).join('') ? true : false;
// check if request has filter(s)
if (filters) {
DROP DATABASE IF EXISTS ig_clone;
CREATE DATABASE ig_clone;
USE ig_clone;
CREATE TABLE users (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
@nax3t
nax3t / instructions
Last active July 21, 2020 08:16
Code for https://youtu.be/b089GmAvUyQ MongoDB c9.io Install Instructions
killall mongod
sudo apt-get purge -y mongodb-org*
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
rm -rf mongod
echo "mongod --dbpath=data --nojournal" > mongod
chmod a+x mongod