Skip to content

Instantly share code, notes, and snippets.

View johntran's full-sized avatar
🌈
Make it last forever, FRIENDSHIP NEVER ENDS

johntran

🌈
Make it last forever, FRIENDSHIP NEVER ENDS
View GitHub Profile
@johntran
johntran / trees.md
Last active October 1, 2018 04:13
LA Big-O Problem Set: 2017 Sep 25

Trees 2018 Sep 26

christmas tree

Problem Set

Check if a tree is a BST

  • Given a binary tree, check if its a BST. A valid BST doesn't have to be complete or balanced. Duplicate elements are not allowed in a BST.
  • Solution runtime: O(N) time where N is the number of nodes in the tree.
describe('Guest User Can Make Order Receipt', () => {
it('can visit app', () => {
return cy.visit('https://www.onehopewine.com/shop/wine/wine');
});
it('can add item', () => {
return cy
.get('#ProductScroll')
.find('.AddToCartButton')
.first()
.click()
@johntran
johntran / exponentialLaws.js
Created June 27, 2018 04:44
Programs are just generalized polynomials
// Exponential Laws
// B^(x+y) = B^x * B^y
// B^(x*2)
function addTimeOrTemp(x, isTime) {
if (isTime) {
this.time += x;
return this.time;
} else {
@johntran
johntran / Refactoring.js
Created June 27, 2018 04:35
Programs are just generalized polynomials.
// AC + AD + BC + BD = (A+B)(C+D)
// Currently AC + AD + BC + BD
function intersect([low1, hi1], [low2, hi2]) {
if (low1 > low2) {
if (hi1 < hi2) {
return [low1, hi1];
} else {
return [low1, hi2];
}
@johntran
johntran / EditPaymentDialog.js
Last active May 24, 2018 03:55
Feature Flags: React 16 Context + TypeScript
import * as React from 'react';
import {withFeatureFlags} from './FeatureFlag'
@withFeatureFlags(['TEMP_20180523_123_DELETE_PAYMENTS'])
class EditPaymentDialog extends React.Component<{}, {}> {
render() {
const { featureFlags } = this.props;
const { TEMP_20180523_123_DELETE_PAYMENTS } = featureFlags;
if (TEMP_20180523_123_DELETE_PAYMENTS) return <div />;
return null;
function getBillingAddress({
firstName,
lastName,
street,
addressLineTwo,
city,
state,
zip,
} ) {
return {
const foobar = factors =>
factors.map(factor =>
factors.map(secondFactor =>
factor * secondFactor
)
);
var foobar = function(factors) {
return factors.map(function(factor) {
return factors.map(function (secondFactor) {
{
"scripts": {
"lint": "eslint server",
"lint:fix": "npm run lint -- --fix",
"prettier":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.js\"",
"prettierTS":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.ts\"",
"prettierTSX":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.tsx\"",
/**
https://lodash.com/docs/4.17.4#flattenDeep
Recursively flattens array.
_.flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]
Even if I nest an element 100 levels deep, it should still flatten it.
*/
/**
https://lodash.com/docs/4.17.4#memoize
Create a function that saves previous results of past calls.
Example:
function add(x,y) {
return x + y
}
const memoizedAdd = memoize(add);