Skip to content

Instantly share code, notes, and snippets.


Template Method

Template method is pretty straight forward: you have a parent class that is pretty bare and more of a skeleton- it will mostly contain "abstract methods" that exist to be overridden by the subclasses that inherit from the parent. This allows you to put shared behavior in the parent class while letting the subclasses customize behavior by overriding methods. Let's take a look at an example:

class HotDrink
	attr_reader :temperature
	def initialize(temperature)
		@temperature = temperature
View aliases
alias log="git log --graph --pretty=format:'%Cred%h%Creset %C(cyan)%an%Creset -%C(blue)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
alias inst='bundle && rake db:migrate && npm install'
alias rs='git reset --hard HEAD'
alias prodc='cap production rails:console'
alias test='zeus rspec'
alias gco='git checkout'
alias ga='git add'
alias gap='git add -p'
alias gcp='git commit -p'
alias gd='git diff'
seemaullal /
Last active May 1, 2017
Airport Distance Calculator Instructions

Airport Distance Calculator

Calculate the distance between two airports.


  • Search for an airport by typing its name, city, or airport code. Airport names will autocomplete as you search
  • The distance between the two airports will be calculated in nautical miles and the airports will also be shown on a Google map.

Live Version

A live version of the application is online at Alternatively, follow the installation instructions below to run the application locally.

View gist:f347e925c8d2e0026da7
/* This is a factory used to manage a firebase reference that held data for each
room of a coding challenge instance. It was part of a web applications where
users could compete in coding challenges against each other in real time
The application can be viewed at */
'use strict';
app.factory('RoomFactory', function($q) {
var factory = {};
View gist:bb9d5080015247863e62
// This is a state and the controller that corresponds to the state
'use strict';
.config(function ($stateProvider) {
.state('calendar', {
url: '/calendar',
controller: 'CalendarCtrl',
View gist:f8d2b47d036ff9b6308a
This is a custom attribute directive I wrote. It was used for form validation to ensure that the name
entered in a form was not already in the database. It is an async custom validator.
'use strict';
app.directive('sandwichnamevalidator', function(SandwichesFactory, $q){
return {
require: 'ngModel',
restrict: '',
seemaullal / gist:c504de50ab42a57b59c1
Last active Aug 29, 2015
Valid Parentheses Combinations
View gist:c504de50ab42a57b59c1

One way of solving this problem is to do so recursively: -you can always pick a left parentheses as long as you haven't used up all of your left parentheses (i.e. if the # of left parentheses is less than n)

  • you can pick a right parentheses if it does not make the combination invalid
    • it will be invalid if there are more right parentheses than left
    • if you keep track of how many left parentheses you currently have added, then you can determine whether or not you can add a right parentheses to the current combination
    • when you have added n left parentheses and n right parentheses, you have a valid result and can add it to your results set

You can use the following recursive calls to mimic this.

First you call a function getCombinations(left,right,curr) with left = n, right =0, and curr='' because you have n left parentheses to add but can't add any right yet (it would make the combination invalid since right parentheses must come after a left) and your initial result is an empty stri

View gist:2d2c3493b5fe3a737264

A dynamic programming approach to this problem is described below. This approach takes O(n*n) time since we are comparing the letters of a string using an n*n matrix (where n is the length of the longer string since empty characters are added to the shorter string).

A dynamic programming approach to this problem is described below. This approach takes O(n*n) time since we are comparing the letters of a string using an n*n matrix (where n is the length of the longer string since empty characters are added to the shorter string).

(click on the image to be taken to the video)

Now that we know how to think about this programming from a dynamic programming perspective, we can write some code to solve the problem. There are a few different approaches to this but generally they all have some things in common:

  • you will have a 2-d array that represents the matrix which compares
seemaullal / gist:be776dd3de4a03593ea0
Last active Jan 2, 2018
Sorting a Stack Without Additional Data Structures
View gist:be776dd3de4a03593ea0

Before you started coding, you should have tried to think about this problem visually. It would probably help to actually make a stack and then an empty helper stack and think about how you can move elements around until one of the stacks contains all the elements in sorted order.

Here is an explanation of how the solution works– this is just an explanation of the algorithm and contains no code (at one point the video says that 8 is smaller than 2 instead of 8 is bigger than 2 but the solution is still correct):

(click on the image to be taken to the video)

The general idea is that you always pop the top element of the stack which you are sorting. You want to add this to the helper stack but first need to make sure that doing so won't make the helper stack unsorted.

When all elements from the original stack are in the helper stack (i.e. the original stack is empty), you n

seemaullal / gist:86ea817cc84e913fd4e9
Last active Mar 8, 2021
Minimum Coins for Change Solution
View gist:86ea817cc84e913fd4e9

The first approach that jumps to mind for most people is using a greedy algoirthm- picking the biggest coin possible and continuing to do this until you have the amount you are looking for.

This looks something like this:

function minCoins(coinArr, amt) {
    var numCoins = 0;
    while (amt !== 0) {
        var eligibleCoins = coinArr.filter(function(coin) {
            return coin <= amt;