Skip to content

Instantly share code, notes, and snippets.

View vaidehijoshi's full-sized avatar

Vaidehi Joshi vaidehijoshi

View GitHub Profile
sudo env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1'
# To install plotly: install.packages('plotly')
# To ensure you have plotly: library(plotly)
# Import your dataset. You can use this script to generate a CSV for an entire month's worth of data:
# https://gist.github.com/vaidehijoshi/5bb92c2a3656d8b72fc731bb0d2bf243
# R Studio should recgonize your dataset automatically when you upload it, but if not, you can do something like this:
monthly_endpoint_percentages <- read.table('~/Code/scatter_plot_data.csv', sep=",", header=TRUE)
# If you want to graph the endpoints as compared to their app rpm's, use this command:
@vaidehijoshi
vaidehijoshi / insertion_sort.js
Last active May 29, 2017 16:49
JS insertion sort
function insertionSort(array) {
// Traverse through length of array, starting with the element at index 0.
for (var i = 0; i < array.length; i++) {
// Our current place in the unsorted portion of the array.
// currentUnsortedItem is the item we will be moving into the "sorted" subset of our array.
var currentUnsortedItem = array[i];
console.log('currentUnsortedItem is currently ' + currentUnsortedItem);
// Iterate through sorted items.
// If the current unsorted item is smaller than the item to its left,
@vaidehijoshi
vaidehijoshi / insertion_sort_results.js
Last active May 29, 2017 06:10
Insertion sort results
> var a = [4, -31, 0, 99, 83, 1];
> insertionSort(a);
> currentUnsortedItem is currently 4
> ** inserting 4 at index 0
> array is now: 4,-31,0,99,83,1
> currentUnsortedItem is currently -31
> -31 < 4 is true
> ** inserting 4 at index 1
> ** inserting -31 at index 0
function bubbleSort(array) {
var isSorted = false;
while (!isSorted) {
isSorted = true;
// Iterate until we get to the last element
for (var index = 1; index < array.length; index++) {
console.log("comparing " + array[index] + " and " + array[index - 1]);
// If the element to the left is bigger, then swap the element
> var myArray = [9, 7, 4, 1, 2];
> bubbleSort(myArray);
> comparing 7 and 9
> SWAPPING 7 and 9
> array is now (5) [7, 9, 4, 1, 2]
> comparing 4 and 9
> SWAPPING 4 and 9
> array is now (5) [7, 4, 9, 1, 2]
> comparing 1 and 9
function selectionSort(numbers) {
var length = numbers.length;
// Traverse through all the elements in the number array.
for(var index = 0; index < length; index++) {
// Set the current item to be the smallest/minimum.
var smallestNumIndex = index;
// Find the minimum element in remaining unsorted array.
for(var nextNumIndex = index + 1; nextNumIndex < length; nextNumIndex++) {
console.log('comparing ' + numbers[smallestNumIndex] + ' and ' + numbers[nextNumIndex])
> selectionSort([33,2,52,106,73]);
> comparing 33 and 2
> comparing 2 and 52
> comparing 2 and 106
> comparing 2 and 73
> swapping the number 2 for the number 33
> numbers currently looks like: 2,33,52,106,73
> comparing 33 and 52
> comparing 33 and 106
var s = new Set();
s.add(2);
// Set { 2}
s.add(45);
// Set { 2, 45}
s.add(45);
// Set { 2, 45}
s.add('hello world!');
// Set { 2, 45, 'hello world!' }
function bookHashing(bookTitle, hashTableSize) {
// Remove any spaces from book title.
var strippedBookTitle = bookTitle.replace(/\s/g, '')
// Divide the length of the title by the hash table size.
// Return the remainder.
return strippedBookTitle.length % hashTableSize;
}
bookHashing("The Grapes of Wrath", 12);
// 4