Skip to content

Instantly share code, notes, and snippets.

@mhuggins
mhuggins / elasticsearch-setup-apple-macbook-pro-m1.md
Created September 4, 2024 03:53 — forked from todgru/elasticsearch-setup-apple-macbook-pro-m1.md
Install Elasticsearch 7.x on Apple Macbook Pro M1 Ventura 13.2

Elasticsearch Setup Apple MacBook Pro M1

Apple MacBook Pro M1, 32 GB, Ventura 13.2

Documentation based on comments in this Github Elasticsearch issue.

Install Homebrew

@mhuggins
mhuggins / README.md
Last active June 11, 2021 09:59
Snake.js

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 / multiparameter_attribute_assignment.rb
Last active September 5, 2020 19:41
MultiparameterAttributeAssignment
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
assign_attributes(params)
end
def assign_attributes(new_attributes)
@mhuggins
mhuggins / app.js
Last active October 25, 2019 10:10
Higher-order component for rendering server-side status codes with react-router v4
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 = {};
@mhuggins
mhuggins / keybase.md
Created June 19, 2019 16:00
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:

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 / application_controller.rb
Last active July 28, 2017 02:13
Devise authentication via Authentication token header (untested)
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 / bin.rb
Last active May 27, 2017 19:00
Bitcoin concepts in Ruby
# 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 December 30, 2016 07:16
Fix ActionController::UrlGenerationError for controller tests in Rails engines
# spec/support/helpers/controller_helpers.rb
module ControllerHelpers
extend ActiveSupport::Concern
included do
routes { ProfileApi::Engine.routes }
end
end
@mhuggins
mhuggins / Gemfile
Last active December 31, 2015 04:49
Generate graphs in PDFs
source 'https://rubygems.org'
gem 'prawn'
gem 'gruff'