Skip to content

Instantly share code, notes, and snippets.

View jakemmarsh's full-sized avatar

Jake Marsh jakemmarsh

View GitHub Profile
@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) {
@jakemmarsh
jakemmarsh / binarySearchTree.py
Last active September 26, 2022 18:06
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 / directives.js
Created June 26, 2013 14:18
AngularJS directive to create a functional "back" button
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
@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 / 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 / controllers.js
Last active May 20, 2019 10:15
AngularJS Service with Controller for access to Google API with Javascript Client (and RequireJS)
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 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 / 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 / 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')($);