Skip to content

Instantly share code, notes, and snippets.

Avatar
🧐

Hersha Venkatesh greathmaster

🧐
  • San Francisco, Bay Area
View GitHub Profile
@greathmaster
greathmaster / quicksort.js
Created Jul 22, 2020
Variations on a theme by Quicksort
View quicksort.js
//Recursive Quicksort using Lomuto's partitioning method
function lomutosPartition(array, start, end) {
let i = start;
let pivot = array[end]
for(let j = start; j < end; j++) {
if(pivot > array[j]) {
[array[j], array[i]] = [array[i], array[j]];
i++;
}
View binary-search-variations-1.js
/*
Given an array of 1's and 0's in the following format:
[1, 1, 1, 0, 0]
Use binary search to determine how many 1's are in the array.
You can assume the 1's will always appear together and at the
beginning of the array.
*/
function bs(array) {
View .block
license: gpl-3.0
@greathmaster
greathmaster / System Design.md
Created Mar 24, 2020 — forked from vasanthk/System Design.md
System Design Cheatsheet
View System Design.md

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@greathmaster
greathmaster / launch.json
Created Mar 24, 2020
VSCode debugger settings for Mocha testing suite
View launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha All",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
@greathmaster
greathmaster / js-bind-with-bind-and-call-args-example.js
Created Feb 16, 2020
JS binding, passing arguments at bind time and call time example
View js-bind-with-bind-and-call-args-example.js
function Dog(name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.sayHello = function(sound1, sound2) {
console.log(`The dog ${this.name}, a ${this.breed}, says Hello! And makes sounds ${sound1} and ${sound2}`)
}
function Cat(name, breed) {
@greathmaster
greathmaster / js-curry-example-sortof.js
Last active Feb 16, 2020
Unlocking a secret using curry principles.
View js-curry-example-sortof.js
//Example 1:
Function.prototype.secretCurry = function() {
let secret = "password"
let that = this;
return function inner(guess) {
if(guess == secret) {
that();
}
return inner;
}
@greathmaster
greathmaster / js-closure-example.js
Created Feb 6, 2020
Javascript example of closure
View js-closure-example.js
Array.prototype.myEach = function(callback) {
for (let i = 0; i < this.length; i++) {
callback(this[i]);
}
}
Array.prototype.myMap = function(callback) {
let newArray = []
const collect = function(el) {
newArray.push(callback(el))
@greathmaster
greathmaster / rails_g.rb
Created Jan 27, 2020 — forked from awkale/rails_g.rb
rails generators #rails #cheatsheet
View rails_g.rb
# Controller Plural
rails g controller Users index show
# Helper Plural
rails g helper Users
# Mailer Singular
rails g mailer UserMailer
# Migration Plural
View ruby-string-assignments-references-example.rb
#Ruby string references clarification
#Mutation of a string
x = "Hello"
y = x
x << " WORLD" #changing the underlying item in memory
puts x #Hello WORLD
puts y #Hello WORLD
a = "Hello"
b = a
You can’t perform that action at this time.