Skip to content

Instantly share code, notes, and snippets.

View jaygraygray's full-sized avatar

Jeremy Gray jaygraygray

View GitHub Profile
function removeDuplicateObjects(arrayOfObjects) {
let newObj = new Set();
arrayOfObjects.forEach(item => newObj.add(JSON.stringify(item)))
return Array.from(newObj).map(item => JSON.parse(item))
}
function getUniqueProps(arrayOfObjects, propToCheck) {
let newObj = new Set();
arrayOfObjects.forEach(item => {
newObj.add(JSON.stringify(item[propToCheck]))
})
let result = Array.from(newObj).map(item => {
return { [propToCheck]: JSON.parse(item) }
@jaygraygray
jaygraygray / draftCtrl.js
Last active April 25, 2017 22:55
Function in an AngularJS controller for displaying author notifications
//
// Declare function
//
$scope.getNotifcations = headerSvc.getNotifications().then(function(resp){
$scope.notifications = resp.data
for (var i = 0; i < $scope.notifications.length; i++) {
$scope.notifications[i].title = ''
@jaygraygray
jaygraygray / article.js
Last active April 25, 2017 22:54
Back end controller for handling all requests related to articles.
GetBookmarks : function(req, res) {
var results = []
//
// Get array of IDs for specific user
//
db.query("SELECT bookmarks_list FROM users WHERE id="+req.params.user_id, function(err, resp) {
if (err) {console.log(err)} else {
var bookmarks = resp[0].bookmarks_list.split(',')
@jaygraygray
jaygraygray / Room.js
Created April 25, 2017 22:29
Template for a single room inside an apartment
import React, { Component } from 'react';
import Bed from './Bed';
import "../../styles/dndbed.scss";
import { removeStudentFromApt } from '../../actions/action_student'
import { connect } from "react-redux"
class Room extends Component {
render() {
@jaygraygray
jaygraygray / Container.js
Created April 25, 2017 21:28
Primary component that renders child components for Apartments view
import React, { Component } from 'react';
import Room from './Room';
import Bed from './Bed'
import Student from './Student';
import ApartmentListFilter from "../ApartmentListFilter";
import "../../styles/dndbed.scss";
import "../../styles/housingcontainer.scss";
import { connect } from "react-redux"
import { getStudents } from "../../actions/action_student"
import { getApartments, getRooms } from "../../actions/action_apartments"
@jaygraygray
jaygraygray / 0_reuse_code.js
Created March 14, 2017 05:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console