Snippets

Controlling Elgato Key Light under Ubuntu with Ruby 1

Controlling Elgato Key Light under Ubuntu with Ruby

Recently I’ve acquired Elgato Key Light. It is a WiFi controllable LED lighting panel. The panel uses 160 LEDs to provide up to 2800 lumens of brightness and a color range of 2900-7000K. While you can control it from a mobile device, doing it directly from the shell makes the whole experience way more convenient. …

Controlling Elgato Key Light under Ubuntu with Ruby Read More »

Ruby on Rails HTTP Basic authentication with JSON failure message 2

Ruby on Rails HTTP Basic authentication with JSON failure message

A short snippet on how to make Ruby on Rails authenticate_or_request_with_http_basic respond with a JSON valid message upon failure. class ApplicationController < ActionController::API include( ActionController::HttpAuthentication::Basic::ControllerMethods ) before_action :http_authenticate! def http_authenticate! authenticate_or_request_with_http_basic do |key, secret| return if Resource.find_by( key: key, secret: secret ) end render( json: 'Invalid credentials'.to_json, status: 401 ) end end Cover photo by …

Ruby on Rails HTTP Basic authentication with JSON failure message Read More »