Skip to content

Instantly share code, notes, and snippets.

View jakemmarsh's full-sized avatar

Jake Marsh jakemmarsh

View GitHub Profile
@jakemmarsh
jakemmarsh / check_deps.js
Created February 21, 2018 21:57
Node script to find any JS files that are not imported anywhere else.
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const directoryToSearch = process.argv[2];
function getAllFilesInDirectory(dirOrFile) {
if (fs.statSync(dirOrFile).isDirectory()) {
return Array.prototype.concat(...fs.readdirSync(dirOrFile).map((f) => getAllFilesInDirectory(path.join(dirOrFile, f))));
} else if (dirOrFile.indexOf('.js') !== -1) {
@jakemmarsh
jakemmarsh / nginx.config
Last active September 13, 2021 11:06
Modify nginx proxy settings in Elastic Beanstalk options
files:
"/tmp/proxy.conf":
mode: "000644"
owner: root
group: root
content: |
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
@jakemmarsh
jakemmarsh / TagInput.js
Created February 19, 2015 21:31
bootstrap-tokenfield
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react/addons');
var _ = require('lodash');
var $ = require('jquery');
var tokenfield = require('bootstrap-tokenfield')($);
@jakemmarsh
jakemmarsh / header-switcher.js
Created February 12, 2014 22:15
AngularJS Directive for looping through and displaying multiple headers
directives.directive('headerSwitcher', function() {
return {
restrict: 'A',
scope: {
elementType: '='
},
link: function(scope, element, attrs) {
var headers = $(element).children(scope.elementType),
headerIndex = -1;
@jakemmarsh
jakemmarsh / timeKeystore.py
Last active August 29, 2015 13:56
a simple keystore system in Python. Multiple values can be stored in a single key, and are retrieved based on time of creation.
import time
class keyStore:
def __init__(self):
self.storage = {}
def put(self, key, value):
# create array if it doesn't exist
if key not in self.storage:
self.storage[key] = []
@jakemmarsh
jakemmarsh / parseBuild.py
Created January 9, 2014 19:22
Interview coding exercise to parse and build strings based on the number of occurrences of characters.
# Take a string as input, such as "a3c4b2", and output a new string of the letters
# repeated the specified number of times i.e. "aaabbcccc"
def parse(string):
newString = ""
for i in range(0, len(string)):
if(string[i].isalpha()):
currentChar = string[i]
elif(string[i].isdigit()):
for j in range(0, int(string[i])):
newString += currentChar
@jakemmarsh
jakemmarsh / elevators.py
Last active January 2, 2016 12:39
a basic implementation of the common "elevator" interview question.
import time
class Elevator:
def __init__(self):
self.state = "stand"
self.doors = "open"
self.currentFloor = 1
self.requests = []
def requestFloor(self, floorNum):
@jakemmarsh
jakemmarsh / binarySearchTree.py
Last active June 1, 2024 13:57
a simple implementation of a Binary Search Tree in Python
class Node:
def __init__(self, val):
self.val = val
self.leftChild = None
self.rightChild = None
def get(self):
return self.val
def set(self, val):
@jakemmarsh
jakemmarsh / file.js
Created September 8, 2013 00:24
Express endpoint to retrieve file from MongoDB GridFS
exports.get = function(req, res) {
var db = new mongo.Db('downloadr', new mongo.Server("127.0.0.1", 27017, {}), {safe: false, strict: false});
db.open(function (err) {
if (err) return handleError(err);
var gfs = Grid(db, mongo);
gfs
// create a read stream from gfs...
.createReadStream({ _id: req.param('fileId') })
@jakemmarsh
jakemmarsh / filters.js
Created July 16, 2013 14:03
AngularJS filter to create links out of URLs
app.filter('parseUrl', function() {
var //URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim,
//Change email addresses to mailto:: links.
replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
return function(text, target, otherProp) {
angular.forEach(text.match(replacePattern1), function(url) {