Skip to content

Instantly share code, notes, and snippets.

View greathmaster's full-sized avatar
🧐

Hersha Venkatesh greathmaster

🧐
  • San Francisco, Bay Area
View GitHub Profile
@greathmaster
greathmaster / System Design.md
Created March 24, 2020 19:11 — forked from vasanthk/System Design.md
System Design Cheatsheet

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 March 24, 2020 18:14
VSCode debugger settings for Mocha testing suite
{
"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 February 16, 2020 07:23
JS binding, passing arguments at bind time and call time example
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 February 16, 2020 03:19
Unlocking a secret using curry principles.
//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 February 6, 2020 03:07
Javascript example of closure
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 January 27, 2020 22:49 — forked from awkale/rails_g.rb
rails generators #rails #cheatsheet
# Controller Plural
rails g controller Users index show
# Helper Plural
rails g helper Users
# Mailer Singular
rails g mailer UserMailer
# Migration Plural
@greathmaster
greathmaster / ruby-string-assignments-references-example.rb
Created December 27, 2019 23:11
Ruby String references example
#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
@greathmaster
greathmaster / ruby-lazy-evaluation-example.rb
Created December 19, 2019 18:10
Ruby Lazy Evaluation Example
#Lazy evaluation in Ruby
@menu || = ["cookies", "bananas", "water"]
#The above is syntatic sugar for
@menu = @menu || ["cookies", "bananas", "water"]
#Similar concept to
x = x + 10 #Both are the same, but different snytax
x += 10
@greathmaster
greathmaster / js-promises-async-await-fetch.js
Created October 30, 2019 05:22
Example of JS promises, fetch, and asnyc/await
//Fetch with Promises and explicit functions
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(function (res) { return res.json()})
.then(function (data) {
//Make use of the data variable here
console.log(data)
})
@greathmaster
greathmaster / fetch-promise-example.js
Created October 25, 2019 18:08
Example of Javascript Fetch and Promise
function func() {
let promise = fetch('https://api.github.com/zen')
return promise.then((successResponse) => {
console.log(successResponse)
return successResponse.text();
})
}
func().then((resp) => {console.log(resp)})