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
/**
Given two sorted arrays, merge them into one big sorted array
Ex:
merge([1,3,5],[2,4,6])
returns [1,2,3,4,5,6]
You cannot use array.sort().
Try to solve this in O(n+m) runtime.
Where n is the length of the first array
and m is the length of the second array.
@johntran
johntran / prettier.js
Last active April 22, 2019 19:09
prettier everything
./node_modules/.bin/prettier --single-quote --trailing-comma all --write "{,!(node_modules)/**/}*.js"
function foo(a) {
return a()
}
function bar(a) {
return 1
}
// I am passing bar in to foo. bar is a callback function to foo
function woof() {
function map(arr, func) {
return arr.map(func);
}
// IF you are super particular about ordering
function parseCSV(csv) {
var peopleArray = csv.split('\n');
var peopleArrayWithSplitNameElements = map(peopleArray, function(str){
return str.split(',');
})
class Form extends React.Component {
state = {
addressLineOne: '',
};
addressLineOneOnChange = addressLineOne => this.setState({ addressLineOne });
addressLineOneOnBlur = () => console.log('on blur');
render() {
const { addressLineOne } = this.state;
return (
<TextValidator
@johntran
johntran / .bash_profile
Last active September 10, 2018 18:37
John bash 2018 09 10
alias bashdir='cd ~'
alias prof='code ~/.bash_profile'
alias cassandra='cd ~/Documents/apache-cassandra-3.11.3/bin && ./cassandra'
alias ms='cd ~/ONEHOPEWINE/microservice'
alias hc='cd ~/ONEHOPEWINE/hopecommerce'
alias devWatch='hc && npm run relayWatch'
alias devApp='hc && npm run dev-a'
alias devGQL='hc && npm run dev-g'
alias msDev='ms && npm run dev'
/**
* Can you explain splice for me? I know what it is,
* but there aren't many example to use it so I don't understand
* everything that goes inside the parentheses
*/
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
* Array.splice(x,y)
import { commitMutation, graphql } from 'react-relay';
import { ConnectionHandler } from 'relay-runtime';
const mutation = graphql`
mutation ProductReviewAddMutation($input: CreateProductReviewInput!) {
productReviewAdd(input: $input) {
user {
id
role
productReviews {
import Relay from 'react-relay/classic';
export default class ProductReviewAddMutation extends Relay.Mutation {
static fragments = {
user: () => Relay.QL`
fragment on User {
id,
role,
}
`,
/*
Given a graph of nodes, find the shortest path.
The nodes can potentially be circular.
*/
const visitedNodeBefore = (visitedList, currentNode) =>
visitedList.find(visitedNode => visitedNode.value === currentNode.value);
const getDestinationNode = (currentNode, nodeDestination) =>
currentNode.nextNodes.find(({ node }) => node === nodeDestination);