Skip to content

Instantly share code, notes, and snippets.

@MonaTem
MonaTem / queue.md
Created September 11, 2018 19:48 — forked from OfTheDelmer/queue.md

Interview Prep

Control Flow And Queue's

A queue just preserves the order in which items arrived into it. This helps model real world problems around waiting in your turn or in line.

Directions: Write a ruby script to do the following with a queue.

Scenario: you have a store and you're writing a script to help calculate a quick receipt. The one problem is that every 3rd and 5th item a customer buys is on sale. Every 3rd item is 10% off and every 5th item is 20% off, but also, an item that is both a 3rd and 5th item is 30% off.

@MonaTem
MonaTem / functional-utils.js
Created August 23, 2018 18:52 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@MonaTem
MonaTem / postgres-cheatsheet.md
Created August 3, 2018 21:24 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@MonaTem
MonaTem / Equity.md
Created July 12, 2018 19:52 — forked from isaacsanders/Equity.md
Joel Spolsky on Equity for Startups

This is a post by Joel Spolsky. The original post is linked at the bottom.

This is such a common question here and elsewhere that I will attempt to write the world's most canonical answer to this question. Hopefully in the future when someone on answers.onstartups asks how to split up the ownership of their new company, you can simply point to this answer.

The most important principle: Fairness, and the perception of fairness, is much more valuable than owning a large stake. Almost everything that can go wrong in a startup will go wrong, and one of the biggest things that can go wrong is huge, angry, shouting matches between the founders as to who worked harder, who owns more, whose idea was it anyway, etc. That is why I would always rather split a new company 50-50 with a friend than insist on owning 60% because "it was my idea," or because "I was more experienced" or anything else. Why? Because if I split the company 60-40, the company is going to fail when we argue ourselves to death. And if you ju

@MonaTem
MonaTem / slim-redux.js
Created July 12, 2018 05:04 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@MonaTem
MonaTem / reduce4.js
Created July 12, 2018 04:01 — forked from maulberto3/reduce4.js
Reduce example #4
const arr = [["dog", 1], ["cat", 2], ["bear", 3]];
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array
const func2 = (obj, prop) => Object.assign(obj, prop); // assigns each object to an accumulator object
const obj3 = arr.map(func1).reduce(func2); // nesting
console.log(JSON.stringify(obj3, null, 2)); // Prints { "dog": 1, "cat": 2, "bear": 3 }
@MonaTem
MonaTem / reduce3.js
Created July 12, 2018 04:01 — forked from maulberto3/reduce3.js
Reduce example #3
const arr = [["dog", 1], ["cat", 2], ["bear", 3]];
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array
const obj2 = arr.map(func1)
console.log(JSON.stringify(obj2, null, 2)); // Prints [ { "dog": 1 }, { "cat": 2 }, { "bear": 3 } ]
@MonaTem
MonaTem / reduce2.js
Created July 12, 2018 04:00 — forked from maulberto3/reduce2.js
Reduce example #2
const reducer = (accum, curr) => accum + curr;
const result = [0, 1, 2, 3, 4].reduce(reducer);
console.log("result is", result); // result is 10
@MonaTem
MonaTem / reduce1.js
Created July 12, 2018 04:00 — forked from maulberto3/reduce1.js
Reduce example #1
const result = [0, 1, 2, 3, 4].reduce( (accum, curr) => accum + curr )
console.log('result is', result) // result is 10
@MonaTem
MonaTem / Eyeballing-This.md
Created July 12, 2018 03:41 — forked from zcaceres/Eyeballing-This.md
Understanding Binding and 'this' in Javascript

How to Eyeball Your ‘This’ Context in Javascript

The early programmer struggles with the Javascript keyword this. But understanding your this context is easier than it seems.

This is all about where a function is invoked. Often, early programmers worry about where the function was declared. Perhaps the function was declared in a specific file or a particular object. Surely this changes it's this!

Nope.

To understand this, we need to see where it is invoked. Nothing else matters, with one exception which we'll cover in a moment.