Skip to content

Instantly share code, notes, and snippets.

@mars
mars / foo.rb
Created June 27, 2018 23:09 — forked from mtsmfm/foo.rb
convert from json hyper schema to swagger spec
require 'yaml'
require 'pathname'
require 'active_support/all'
def convert(f)
filename = Pathname.new(f)
yaml = YAML.load_file(filename)
name = filename.basename('.yml').to_s
File.write(filename, {
@mars
mars / await-url-response.bash
Created January 3, 2022 22:34
Await a URL returning a specific response status, like 200
#!/bin/bash
set -u
echo "Checking for response status ${1} from URL: ${2}"
try_count=0
while true
do
((try_count++))
response_status="$(curl -s -o /dev/null -w "%{http_code}" "${2}")"
if [ "$response_status" == "${1}" ]
@mars
mars / set_default_host.rb
Created August 17, 2023 20:10
Rails unified host override for use with apps behind a CDN (Rack middleware, supports OmniAuth)
# Rack middleware that reads environment variable HOST (value such as: app.example.com)
# to override request Host headers, forcing the app to use this value for URLs & redirects.
#
# If env var HOST is unset, then this middleware does nothing.
#
# Useful for when a Rails app is the origin behind a CDN/proxy, so that all generated
# URLs point to the canonical hostname of the CDN, and not the origin itself.
#
# For a Rails app,
# - save this file in config/initializers/set_default_host.rb