Skip to content

Instantly share code, notes, and snippets.

View jdmorlan's full-sized avatar

Jay Morlan jdmorlan

  • Freelance Web Developer
  • Houston, TX
View GitHub Profile
def get_prerequisites(requirement_type, course, requirement_collection)
course.send(requirement_type).each do |pre|
requirement_collection << pre.prerequisites
get_prerequisites(requirement_type, pre, requirement_collection)
end
end
def requirement_graph(requirement_type)
course_map = [self.send(requirement_type)]
get_prerequisites(requirement_type, self, course_map)
@jdmorlan
jdmorlan / who_commited.rb
Last active October 20, 2015 01:38
Figure out who has commited code to a Github repo
# Make sure you gem install http
require 'http'
class Committer
attr_reader :name, :email
def initialize(params)
@name = params["name"]
@email = params["email"]
@jdmorlan
jdmorlan / application_controller.rb
Last active March 26, 2016 00:57
Setup Json Web Token Authentication in Rails API app
# Located at app/controllers/application_controller.rb
class ApplicationController < ActionController::API
before_action do
@token = Token.new(request.env['auth.token'])
end
def require_token!
error_json = {message: 'No token in HTTP_AUTHORIZATION header'}
render json: error_json, status: 401 unless @token.present?
@jdmorlan
jdmorlan / DrawerSelector.js
Created August 10, 2016 23:53
Slide in from right drawer, higher order Component
import React from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import Drawer from 'drawer/components/drawer'
const DrawerSelector = (Display, Content) => React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired
},
@jdmorlan
jdmorlan / _grid.scss
Created August 21, 2016 20:03
Inline Block Grid (Margo CSS)
.container {
font-size: 0;
> * {
display: inline-block;
font-size: medium;
vertical-align: top;
width: 100%;
}
@jdmorlan
jdmorlan / reducer.js
Created August 21, 2016 22:36
Remove the switch statement from Redux reducers!
const updateLocation = (state, action) => {
return Object.assign({}, state, ...)
}
const actionHandlers = {
'UPDATE_LOCATION': updateLocation
}
const reducer = (state = initialState, action) => {
const handler = actionHandlers[action.type]
@jdmorlan
jdmorlan / index.js
Created August 21, 2016 23:25
Use Redux in Rails
import { createStore, combineReducers } from 'redux'
import { reducer as education } from 'reducers/education'
import { reducer as skills } from 'reducers/skills'
const buildResumeBuilderStore = () => {
return createStore(combineReducers({ education, skills })
}
document.addEventListener('DOMContentLoaded', () => {
@jdmorlan
jdmorlan / hash.js
Created August 23, 2016 17:51
Naive Hash Table Implementation
const hashFunc = (str) => {
let hash = 0;
if (str.length === 0) return hash
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = ((hash<<5)-hash)+char
hash = hash & hash
}
return hash
}
@jdmorlan
jdmorlan / compose.js
Last active August 28, 2016 23:43
The Compose Function
const compose = (...funcs) => {
if (funcs.length === 0) {
return (arg) => arg
}
if (funcs.length === 1) {
return funcs[0]
}
const last = funcs[funcs.length - 1]
const compose = (...funcs) => {
if (funcs.length === 0) {
return (arg) => arg
}
if (funcs.length === 1) {
return funcs[0]
}
}