Skip to content

Instantly share code, notes, and snippets.

View StevenMDixon's full-sized avatar
🌲
いつもの通りに森に

Steven M. Dixon StevenMDixon

🌲
いつもの通りに森に
  • Rev.io
  • United States
View GitHub Profile
// A simplified way to get the siblings of an element
//This function returns an array of sibling elements that does not include the passed element.
function getSiblings(htmlElement) { // gets the siblings of the passed element
return Array.prototype.filter
.call(htmlElement.parentElement.children, child => child.nodeType == 1 && child != htmlElement);
}
//functionally the same as
// make array, there are many way, 頑張って!
var example_ = new Array(5); // outputs: [] this creates an array with a length of the parameters size.
var example_ = Array(1,2,3,5); // outputs: [1,2,3,5] this initializes the elements in the array and makes them accessible.
var example_ = [1,2,3,4]; // outputs: [1,2,3,4] //safest example for creating an array as all elements are accessible. Does not call array constructor.
var example_ = Array.of(1,2,4); // // outputs: [1,2,4] //calls the Array constructor on a list of provided elements.
/* Problem: We need a function that will take a string containing any number of alpha numeric characters excluding white spaces
* and return an object with key pair values detailing how many times each character shows up in the string. Then we need another function
* that accepts the array and returns a function that when a number is passed to it, the function returns a color.
*
* @function ('hello');
* this should return an object like this
* @Object = {h: 1, e: 1, l: 2, o:1}
*
* @function(object)
* this should return a function that when we pass a value to it returns a color the color can be any format accepted by css properties
//todo - not be lazy :-)
<script src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.5.0/marked.min.js'>
<body>
<div id='target'></div>
</body>
<script>
const myMarkDown = `# Hello World`;
const target = document.getElementById('target');
target.innerHTML = Marked(myMarkDown);
@StevenMDixon
StevenMDixon / CMS.md
Last active September 26, 2018 19:25

CMS

I am currently woking through an IDEA for a stupidly simple CMS, No logins, No HTML.

Back-end

A Node js server that serves a react app and Static content via routes.

Settings are saved as (json)? data in a NoSQL data base?

@StevenMDixon
StevenMDixon / FactoryFunctions.js
Created October 5, 2018 02:57
Factory functions and what they do!
/* What is a factory method? A factory method is any function that creates an object
example 1:
function userFactory =(username, bio)=> ({user: username, about: bio});
this factory function takes in a a username and a bio and creates a new object with user and about keys. this is great if you want to
create a bunch of users.
const beth = userFactory("Beth", "Hi im Beth");

Redux

State management.

Models applications state as a single JS object

npm install --save redux

Action

store = Redux.createStore(reducer, initialstate, enhancer);
manages what the state lookslike. centralized location for state.
function rootReducer(state= initialState, action){
return state
}
var initialState = {
count: 0
we start with two alike arrays that need to be combined, the output should combine items that are exactly the same.
let array_one = [{name: "cats", count: 1},{name: "dogs", count: 2}];
let array_two = [{name: "cats", count: 5}, ,{name: "chickesn", count: 4}];
// expected output [{name: "cats", count: 6},{name: "dogs", count: 2} ,{name: "chickesn", count: 4}}]