Skip to content

Instantly share code, notes, and snippets.

View nax3t's full-sized avatar

Ian Schoonover nax3t

  • Fort Worth, TX
View GitHub Profile
@nax3t
nax3t / admoda-api
Last active August 29, 2015 14:18
Solution for Mike's API request
# My solution, using Typhoeus gem
p "-------Ian\'s Solution---------"
require 'typhoeus'
request = Typhoeus::Request.new("https://api.admoda.com/v1/advertiser/stats/campaigns.csv?date=2015-03-11",
method: :get,
headers: { 'Authorization' => 'Token api_token_here' })
response = request.run
puts response.body
@nax3t
nax3t / ranking.js
Created March 1, 2017 00:14
Reddit Ranking Algorithm in JavaScript
function _confidence(ups, downs) {
var n = ups + downs;
if(n === 0) {
return 0;
}
var z = 1.281551565545;
var p = parseFloat(ups) / n;
var left = p + 1 / (2 * n) * z * z;
@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
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 / 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) {
@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 / 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 / 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 / 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 / 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/)