Skip to content

Instantly share code, notes, and snippets.

View matthewoestreich's full-sized avatar
♠️
👋

Matt Oestreich matthewoestreich

♠️
👋
View GitHub Profile
function getDistinctObjectsBasedUponPropertyValue(array, distinctProperty) {
var tempArray = []
return array.filter(function (n) {
return tempArray.indexOf(n[distinctProperty]) == -1 && tempArray.push(n[distinctProperty])
})
}
@matthewoestreich
matthewoestreich / enableScroll.js
Last active July 12, 2020 21:34
Get past paywall - for sites that disable scroll - use this to scroll up/down with a/z keys respectively
function KeyPress(e) {
const { keyCode } = window.event ? event : e;
// If "a" is pressed, scroll up
if (keyCode == 65) {
window.scrollBy(0, -100)
}
// If "z" is pressed, scroll down
if (keyCode == 90) {
@matthewoestreich
matthewoestreich / stackoverflow.sql
Last active September 1, 2019 23:52
My most viewed answers (based on question view count)
--https://data.stackexchange.com/stackoverflow/query/new
SELECT Answers.Id as [Post Link], Question.ViewCount
FROM Posts as Answers, Posts as Question
WHERE Answers.PostTypeId = 2
AND Answers.OwnerUserId = ##UserId##
AND Question.Id = Answers.ParentId
ORDER BY Question.ViewCount DESC;
@matthewoestreich
matthewoestreich / create-react-app-bundle-analyzer.js
Created September 9, 2019 12:56
Bundle Analyzer For create-react-app Applications
process.env.NODE_ENV = 'production';
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpackConfigProd = require('react-scripts/config/webpack.config')('production');
// this one is optional, just for better feedback on build
const chalk = require('chalk');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const green = text => {
@matthewoestreich
matthewoestreich / _gzipper.js
Last active September 22, 2019 00:28
gzip a file in node.js
/**
* USE FROM COMMAND LINE:
* node gzipper.js ./path/to/file.txt ./path/to/output/dir
*/
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const SOURCE = path.resolve(__dirname, process.argv[2]);
@matthewoestreich
matthewoestreich / TypeWriter.jsx
Created September 22, 2019 21:49
Typing effect in React
import React, { useState, useEffect } from 'react';
const CONSTANTS = {
TYPING_SPEED: 30,
DELETING_SPEED: 150,
}
export default function TypeWriter({ messages, heading }) {
const [state, setState] = useState({
text: "",
const isUsernameTaken = (username) => {
User.find({username: username})
.exec()
.then((err, doc) => {
if(err) throw err;
return doc ? true : false;
});
}
const request = require('request');
let MY_THINGS = [];
function getItems() {
let url = 'https://jsonplaceholder.typicode.com/todos/';
return new Promise((resolve, reject) => {
request.get(url, (err, res, body) => {
if(err) reject(err);
if(res.statusCode !== 200) reject(res.statusCode);
@matthewoestreich
matthewoestreich / jenkinsUpdater.sh
Last active October 7, 2019 23:47
Updates Jenkins based upon URL. You will need to change the paths below to fit your deployment.
#!/bin/bash
# USE LIKE:
# bash jenkinsUpdater.sh "updates.jenkins-ci.org/download/war/2.190.1/jenkins.war"
# Change these locations to suit your needs
BACKUP_ROOT_PATH=/usr/share/jenkins/backups
JENKINS_WAR_PATH=/usr/share/jenkins
DOWNLOAD_ROOT_PATH=~/downloads
@matthewoestreich
matthewoestreich / clean.build.js
Created October 11, 2019 13:38
Cleans React Build
const fs = require('fs');
function deleteFolderRecursive(path) {
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);