Skip to content

Instantly share code, notes, and snippets.

Matt Huggins mhuggins

Block or report user

Report or block mhuggins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am mhuggins on github.
  • I am mhuggins (https://keybase.io/mhuggins) on keybase.
  • I have a public key ASB5Ik9jd0OumS7a7sFoZLpqMY9Z4BjASzSxcz7QvNrt1Qo

To claim this, I am signing this object:

View withGraphQuery.jsx
import _ from "lodash";
import { graphql } from "react-apollo";
import { compose, setDisplayName, wrapDisplayName } from "recompose";
const isServer = typeof window !== "object";
const DEFAULT_OPTIONS = {
fetchPolicy: isServer ? "network-first" : "cache-and-network"
};
@mhuggins
mhuggins / app.js
Last active Oct 25, 2019
Higher-order component for rendering server-side status codes with react-router v4
View app.js
import express from "express";
import { renderToString } from "react-dom/server";
import { StaticRouter } from "react-router-dom";
import routes from "./routes";
const app = express();
app.use((req, res) => {
const context = {};
View README.md

Simple snake game in JS.

Unfinished features & unaddressed issues:

  • No collision detection (no win/loss)
  • Pressing two directions in quick succession allows the snake to reverse direction on itself. (This is an issue with the FPS limiting vs. event-driven key handling.)
  • Food can spawn on top of the snake.
@mhuggins
mhuggins / bin.rb
Last active May 27, 2017
Bitcoin concepts in Ruby
View bin.rb
# Taken from: https://blockexplorer.com/api/status?q=getDifficulty
DIFFICULTY = 595921917085.416
digest = Bitcoin::Digest.new
proof = Bitcoin::ProofOfWork.new(digest)
input = "Hello, world!"
nonce = proof.prove(input, DIFFICULTY) # => some int
hash = digest.hexdigest(input, nonce) # => some hash string
@mhuggins
mhuggins / controller_helpers.rb
Last active Dec 30, 2016
Fix ActionController::UrlGenerationError for controller tests in Rails engines
View controller_helpers.rb
# spec/support/helpers/controller_helpers.rb
module ControllerHelpers
extend ActiveSupport::Concern
included do
routes { ProfileApi::Engine.routes }
end
end
View gist:7c3a4e971229b4f3fcf0
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
Note: I am not using the Heroku Zerigo DNS add-on, instead I have a separate Zerigo account for my DNS needs. I do this because Zerigo offers 30 hosts on free direct accounts, versus only 10 hosts on the free Heroku add-on.
@mhuggins
mhuggins / gist:d33bf7042d4b447bc22b
Created Aug 15, 2014
How can I do this in Mocha?
View gist:d33bf7042d4b447bc22b
/** @jsx React.DOM */
var React = require('react');
var Loader = require('../../lib/react-loader');
var expect = require('chai').expect;
var loader, loaded;
describe('Loader', function () {
beforeEach(function () {
@mhuggins
mhuggins / application_controller.rb
Last active Jul 28, 2017
Devise authentication via Authentication token header (untested)
View application_controller.rb
class ApplicationController < ActionController::Base
before_filter :authenticate_user_from_token!
private
def authenticate_user_from_token!
authenticate_or_request_with_http_token do |token, options|
user = User.find_by_authentication_token(token)
if user && Devise.secure_compare(user.authentication_token, token)
@mhuggins
mhuggins / multiparameter_attribute_assignment.rb
Last active Jan 16, 2019
MultiparameterAttributeAssignment
View multiparameter_attribute_assignment.rb
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
assign_attributes(params)
end
def assign_attributes(new_attributes)
You can’t perform that action at this time.