Skip to content

Instantly share code, notes, and snippets.

View dolarsrg's full-sized avatar

Santiago Ruiz dolarsrg

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dolarsrg on github.
  • I am dolarsrg (https://keybase.io/dolarsrg) on keybase.
  • I have a public key ASArLGiaCIRcowQJ4w2KmsO-JPN2BO1xmfN2P9LYghr7Jgo

To claim this, I am signing this object:

@dolarsrg
dolarsrg / add_url_vars.rb
Created February 29, 2012 16:12
Takes an url, detects its params and adds to it the vars from the hash
# Takes an url, detects its params and adds to it the vars from the hash
# Example of use:
# > add_url_vars("http://www.example.com/signup?token=HIWORLD", {:s => 'HIAGAIN', :s32 => 'BYE'})
# => "http://www.example.com/signup?token=HIWORLD&s=HIAGAIN&s32=BYE"
def add_url_vars(url, vars={})
uri = URI.parse(url)
pre_vars = get_url_vars(url)
vars_total = []
for var in pre_vars
vars_total << "#{var[0]}=#{var[1][0]}"
@dolarsrg
dolarsrg / get_url_vars.rb
Created February 29, 2012 15:51
Function to extract variables from an URL
# Returns a hash with the name of the vars linked to an array with all the values of it
def get_url_vars(url)
require 'uri'
require 'cgi'
uri = URI.parse(url).query
if uri and (url = CGI.parse(uri))
return url
else
return nil
end