Skip to content

Instantly share code, notes, and snippets.

View Mk-Etlinger's full-sized avatar

Mike Etlinger Mk-Etlinger

  • Grand Rapids
View GitHub Profile
@Mk-Etlinger
Mk-Etlinger / gist:7f7874ae828ccc1c018de21d615a151a
Last active January 31, 2018 19:50
React Component Example
import React, { Component } from 'react';
class ChatBox extends Component {
constructor() {
super();
this.state = {
maintainState: 'here'
}
}
class Columns extends React.Component {
render() {
return (
<React.Fragment>
<td>Hello</td>
<td>World</td>
</React.Fragment>
);
}
}
render() {
// React does *not* create a new div. It renders the children into `domNode`.
// `domNode` is any valid DOM node, regardless of its location in the DOM.
return ReactDOM.createPortal(
this.props.children,
domNode,
);
}
"<table>
<tr>
<td>Hello</td>
<td>World</td>
</tr>
</table>"
// Input: [ 2, 7, 11, 15 ]
//* Use a nested for loop
//* compare the current num(i) to the next num(k++) and check if they match
//* if they match then return both indices in an array
// Output: [ 0, 1 ]
// edge cases: ??
var twoSum = function(nums, target) {
let indicesArray = [];
for (let i = 0; i < nums.length; i++) {
for (let k = i + 1; k < nums.length; k++) {
if (nums[i] + nums[k] === target) {
indicesArray.push(i, k)
}
}
}
return indicesArray;
var twoSum = function(nums, target) {
let dictionary = {}
let complementValue = 0;
let indicesArray = [];
for (let i = 0; i < nums.length; i++) {
complementValue = target - nums[i];
if (dictionary.hasOwnProperty( complementValue )) {
return indicesArray = [ dictionary[complementValue], i ]
}
@Mk-Etlinger
Mk-Etlinger / gist:1ff14785f30460f9f3fde24149e7c7cd
Created February 8, 2018 04:05
Object.assign syntax usage
const myWorkSchedule = {
monday: '10-5',
tuesday: '10-5',
friday: '11-9'
}
const updatedSchedule = Object.assign({}, myWorkSchedule, { thursday: '8-5' })
updatedSchedule
// {monday: "10-5", tuesday: "10-5", friday: "11-9", thursday: "8-5"}
const myWorkSchedule = {
monday: '10-5',
tuesday: '10-5',
friday: '11-9'
}
const updatedSchedule = { thursday: '11-6', ...myWorkSchedule }
updatedSchedule
// {thursday: "11-6", monday: "10-5", tuesday: "10-5", friday: "11-9"}
def sorcery
controller_name = params['controller']
controller_name.chop!
model_name = controller_name.capitalize
instance_variable_set('@' + controller_name, Object.const_get( model_name ).find_by(id: params[:id]))
end