Skip to content

Instantly share code, notes, and snippets.

Avatar

Jake Marsh jakemmarsh

View GitHub Profile
@jakemmarsh
jakemmarsh / binarySearchTree.py
Last active Oct 3, 2021
a simple implementation of a Binary Search Tree in Python
View binarySearchTree.py
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 / nginx.config
Last active Sep 13, 2021
Modify nginx proxy settings in Elastic Beanstalk options
View nginx.config
files:
"/tmp/proxy.conf":
mode: "000644"
owner: root
group: root
content: |
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
@jakemmarsh
jakemmarsh / directives.js
Created Jun 26, 2013
AngularJS directive to create a functional "back" button
View directives.js
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
@jakemmarsh
jakemmarsh / file.js
Created Sep 8, 2013
Express endpoint to retrieve file from MongoDB GridFS
View file.js
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 / controllers.js
Last active May 20, 2019
AngularJS Service with Controller for access to Google API with Javascript Client (and RequireJS)
View controllers.js
define(['angular', 'services'], function (angular) {
'use strict';
return angular.module('myApp.controllers', ['myApp.services'])
.controller('IndexCtrl', ['$scope', 'googleService', function ($scope, googleService) {
$scope.login = function () {
googleService.login().then(function (data) {
// do something with returned data
console.log(data.email);
@jakemmarsh
jakemmarsh / check_deps.js
Created Feb 21, 2018
Node script to find any JS files that are not imported anywhere else.
View check_deps.js
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 / filters.js
Created Jul 16, 2013
AngularJS filter to create links out of URLs
View filters.js
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) {
@jakemmarsh
jakemmarsh / parseBuild.py
Created Jan 9, 2014
Interview coding exercise to parse and build strings based on the number of occurrences of characters.
View parseBuild.py
# 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 Jan 2, 2016
a basic implementation of the common "elevator" interview question.
View elevators.py
import time
class Elevator:
def __init__(self):
self.state = "stand"
self.doors = "open"
self.currentFloor = 1
self.requests = []
def requestFloor(self, floorNum):
@jakemmarsh
jakemmarsh / TagInput.js
Created Feb 19, 2015
bootstrap-tokenfield
View TagInput.js
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react/addons');
var _ = require('lodash');
var $ = require('jquery');
var tokenfield = require('bootstrap-tokenfield')($);