Skip to content

Instantly share code, notes, and snippets.

View seemaullal's full-sized avatar

Seema Ullal seemaullal

  • United States
  • 06:28 (UTC -07:00)
View GitHub Profile
@seemaullal
seemaullal / gist:86ea817cc84e913fd4e9
Last active March 8, 2021 18:55
Minimum Coins for Change Solution

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;
 });
@seemaullal
seemaullal / gist:be776dd3de4a03593ea0
Last active January 2, 2018 21:03
Sorting a Stack Without Additional Data Structures

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
seemaullal / gist:04e7ea028e3c4acab8ad
Created April 27, 2015 20:16
Breadth First Search (for binary trees)
Note: This example is for a binary tree but for graphs, you do a similar thing but need to keep track of which nodes you have visited (until you visit all of them) and also add all children to the queue, not just the left and right child.
Tree:
5
/ \
2 6
/ \ / \
1 3 4 7
Add the root to the BFSArray (the results). Add its children to the queue.
@seemaullal
seemaullal / gist:3f5ef89bd9e62fbafaa5
Last active July 27, 2017 03:03
Async Library Notes

Some Useful Async library methods

async.each

async.each(arr, function(item,callback) {
	
},
function(err) { 
//function code that is to be done after the 2nd 
//argument of async.each is called on each element
@seemaullal
seemaullal / README.md
Last active May 1, 2017 14:43
Airport Distance Calculator Instructions

Airport Distance Calculator

Calculate the distance between two airports.

About

  • 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 https://airport-distances.herokuapp.com/. Alternatively, follow the installation instructions below to run the application locally.

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
	end
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
seemaullal / gist:f347e925c8d2e0026da7
Last active August 29, 2015 14:25
Angular Sample #3
/* 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 http://www.coduels.com */
'use strict';
app.factory('RoomFactory', function($q) {
var factory = {};
// This is a state and the controller that corresponds to the state
'use strict';
angular.module('learndotApp')
.config(function ($stateProvider) {
$stateProvider
.state('calendar', {
url: '/calendar',
controller: 'CalendarCtrl',
@seemaullal
seemaullal / gist:f8d2b47d036ff9b6308a
Last active August 29, 2015 14:25
Angular Sample #1
/*
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: '',