Skip to content

Instantly share code, notes, and snippets.

How to compress URL parameters (and any other string) in Ruby

Introduction

Working with web applications and microservices we often have the problem of passing long lists of settings through HTTP requests. While the canonical way of doing this would be to use a POST request and pass the values in the body of the request, this is not always an option for us. (Comment: How come? Maybe the reason we can't do it is interesting/helpful)

In fact there can be cases where we need to generate URLs that can be passed to other users as a link, and reused by them to later trigger an action in the target Rails server.

The only way to achieve this is for us to be able to pass these values as URL parameters in a GET request, but unfortunately these URLs exceed often the maximum length limit allowed by the browsers or web servers. (Comment: Maybe include the byte limit here)

@rgould
rgould / pre-commit.rb
Created August 10, 2017 01:10 — forked from cben/pre-commit.rb
git pre-commit hook that runs rubocop on staged files
#!/usr/bin/env ruby
# make sure you have gem 'rubocop-git' in your Gemfile
require 'readline'
def input(prompt="", newline=false)
prompt += "\n" if newline
Readline.readline(prompt, true).squeeze(" ").strip
end
def welcome
@show_splash = false
if @current_user
redirect_to home_path(@current_brand)
else
@ct_deal = nil
@biz_deal = nil
@kidz_deal = nil
Deal.live_by_brand("gaggleup", @current_region).each do |chkdeal|
if check_for_exclusive_deal_access(chkdeal, @current_user)
@rgould
rgould / gist:3006199
Created June 27, 2012 19:22
oh crap format
# @current_region
def show
if @current_brand == Brand.gaggleup
@deals = Deal.select('distinct deals.*').active.approved.in_region_incl_parents(@current_region).started.order("starts_at desc").limit(15)
@header_title = t('_gup', :default => 'GaggleUp')
@deals = @deals.delete_if do |deal|
true unless check_for_exclusive_deal_access(deal, current_user)
end
@rgould
rgould / about.md
Created August 9, 2011 20:56 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
#!/bin/bash
PASTEL='{
"Ansi 0 Color" = {
"Blue Component" = 0.3097887;
"Green Component" = 0.3097887;
"Red Component" = 0.3097887;
};
"Ansi 1 Color" = {
"Blue Component" = 0.3764706;