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
{
"name": "watsonFrontendV2",
"version": "1.0.0",
"description": "Change app/views/layouts/application.html.erb before deploying. Or bad things will happen.",
"main": "index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --require ./frontend/test/test_helper.js 'frontend/test/' --recursive",
"dev": "webpack-dev-server --config webpack.dev.js --hot --progress --inline --colors",
"devNoTools": "webpack-dev-server --config webpack.devNoTools.js --hot --progress --inline --colors",
"prod": "./node_modules/.bin/webpack -p --config webpack.prod.js",
@johntran
johntran / usersTable.js
Last active February 12, 2016 21:09
For ShipHawk Medium Article
const usersTable = (props) => {
const shrug = '¯\_(ツ)_/¯'
if (props.users) {
/**
* Returns
* <div>John</div>
* <div>Mary</div>
* <div>Sherry</div>
*/
return (
import { Component } from 'react'
import usersTable from './usersTable'
import fetch from 'fetch'
class UserTableContainer extends Component {
componentDidMount() {
/**
* When component is loaded on the page,
* get the user list from api and mutate state.
*/
//Let's say you have a function that accepts a callback, and applies that call back to each element:
forEach(array, callback) {
// loop start at 0 index, until it reaches the end of the array, one at a time
for(var i=0; i < array.length; i++) {
// at the index of that array, have it equal to the result of the callback with "the result of that index of that array" as a parameter
array[i] = callback(array[i])
}
}
@johntran
johntran / orderHistoryPage.js
Last active March 23, 2016 22:14
Pure functions. No ES6 Classes.
import React from 'react';
import { connect } from 'react-redux';
import {
loadOrdersPage,
pageInitialized,
pageFinishedLoading,
updateSyncStatus,
updateFilter,
selectRow,
updateColumnSort,
@johntran
johntran / noLoops.js
Last active March 23, 2016 22:05
No for or while loops.
// pushOne(10,[]) results in [1,2,3,4,5,6,7,8,9,10]
// Imperative Programming
function pushOne(max, indexes) {
while (indexes.length < max) {
indexes.push(indexes.length+1)
}
return indexes
}
// Functional, Declarative Programming
function pushOne(max, indexes) {
// basically it asks to create a function that reverse the whole string without reverse the positions of the words.
// "Three Blind mice"
// "eerhT dnilB ecim"
var stringToArray = function (str) {
return str.split(' ')
}
// ['Three', 'Blind', 'mice']
var reverseElementsInArray = function (arr) {
return arr.map(function(element) {
@johntran
johntran / frog.js
Last active April 11, 2016 07:05
frog.js
/** A frog can jump on an array of lilypads that is dropped into the river in seconds according the index.
* Given [10,5,8]. A lilypad 10cm away from start drops at 0 seconds,
* then a pad 5cm away from start drops 1 second from start,
* then one 8cm away from start drops in 2 seconds from start
* The function takes an array of lilypads, how far the frog can jump, and how wide the river is.
* How much time does it take for the frog to get to the other side of the river?
* If the frog can't cross the river, return -1
* Otherwise, return the seconds it takes for the frog to cross.
*/
// It was basically with a set of numbers in an array
// Give back a count of numbers with the most frequent numbers that are the same
// superoptimized version
var numberSet = function (set) {
var counts = {};
var highestCount = 0;
var numbers = [];
@johntran
johntran / .babelrc
Last active July 6, 2016 22:47
HappyPack and DLL plugin for Relay apps
{
"plugins": ["babel-relay-plugin-loader"],
"presets": ["react", "es2015", "stage-0"],
"passPerPreset": true,
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",