Skip to content

Instantly share code, notes, and snippets.

View dengjonathan's full-sized avatar

Jon Deng dengjonathan

View GitHub Profile
@dengjonathan
dengjonathan / callToMap.js
Created September 10, 2016 18:32
callToMap
names2 = ['kendra', 'kim', 'kampbell'];
var capitalize = function(word) {
return word[0].toUpperCase() + word.slice(1);
};
map(names, capitalize); // ['Kendra', 'Kim', 'Kampbell']
@dengjonathan
dengjonathan / add.js
Created September 10, 2016 19:07
pure function
var d = 'not modified';
// add is a pure function that doesn't modify anything out of its scope
function add(x, y) {
return x + y;
}
add(2, 3) // 5
add(2, 3) // always gonna be 5
console.log(d) // 'not modified'
@dengjonathan
dengjonathan / Example2_Solution.js
Created September 10, 2016 21:54
map function
names2 = ['kendra', 'kim', 'kampbell'];
// use this as your callback function in map
var capitalize = function(word) {
return word[0].toUpperCase() + word.slice(1);
};
// we need each implemented for map to work
var each = function(array, callback) {
for (var i = 0; i < array.length; i++) {
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
@dengjonathan
dengjonathan / puke.js
Last active September 12, 2016 03:40
Puke function in lines 3-5 allows you to see props passed to a React component without actually having to create the UI
var React = require('react');
var PropTypes = React.PropTypes;
var styles = require('../styles');
var Link = require('react-router').Link
var UserDetails = require('../components/UserDetails');
var UserDetailsWrapper = require('../components/UserDetailsWrapper');
function puke(object) {
return <pre>{JSON.stringify(object, null, ' ')}</pre>;
}
@dengjonathan
dengjonathan / puke.js
Created September 12, 2016 15:12
puke function that creates a React node displaying results of an object (usually an api call)
function puke(object) {
return <pre>{JSON.stringify(object, null, ' ')}</pre>;
}
@dengjonathan
dengjonathan / Bee.js
Created September 19, 2016 18:50
superclass to subclass inheritance
var Bee = function () {
Grub.call(this);
this.age = 5;
this.color = 'yellow';
this.job = 'keep on growing';
};
Bee.prototype = Object.create(Grub.prototype);
Bee.prototype.constructor = Bee;
@dengjonathan
dengjonathan / hashTable.js
Last active September 23, 2016 14:14
a hashTable
"use strict"
var LimitedArray = function (limit) {
var storage = [];
var limitedArray = {};
limitedArray.get = function (index) {
checkLimit(index);
return storage[index];
};
@dengjonathan
dengjonathan / hashTable.js
Last active September 23, 2016 13:57
hashtable for MVP
"use strict"
var LimitedArray = function (limit) {
var storage = [];
var limitedArray = {};
limitedArray.get = function (index) {
checkLimit(index);
return storage[index];
};
@dengjonathan
dengjonathan / static_server.js
Created September 24, 2016 03:59 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);