Skip to content

Instantly share code, notes, and snippets.

@MarioRuiz
MarioRuiz / proxy.rb
Last active December 6, 2016 11:02 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@MarioRuiz
MarioRuiz / fibonacci.rb
Last active September 9, 2018 21:32
Four different Ruby examples creating the Fibonacci sequence and calculating time consuming.
require 'timify'
num=36
t=Timify.new :count, show:false
## Example 1
t.add
f = lambda { |x| x < 2 ? x : f.call(x-1) + f.call(x-2) }
puts f.call(num)
@MarioRuiz
MarioRuiz / get_bearer_token.rb
Last active February 6, 2019 14:50
How to get the OAuth2 token for Microsoft Azure using Ruby and add it to your Http connection header. Install in command line first: gem install nice_http or in case you use linux: sudo gem install nice_http
require 'nice_http'
require "addressable/uri"
# Create on management.azure.com a new directory or
# select the one you want
# Create an application on that directory if you want to
# Be sure api permissions are the ones you need,
# for example Access Azure Service Management
# Get the client_id and the tenant_id
# Create a client secret and get it
@MarioRuiz
MarioRuiz / api.rb
Last active February 23, 2019 16:22
Create your own API so other tools like Postman or other computers in your network can get what they need for the tests or for whatever you need. Run in command line ruby api.rb to fire up this API. Access from any computer inside your network, for example to get 30 random emails, write in your browser: mycomputer:4567/gen?pattern=20-50:@&num=30
# libraries we will use in our api
# documentation: https://github.com/MarioRuiz/string_pattern
# documentation: https://github.com/MarioRuiz/nice_hash
require "sinatra"
require "string_pattern"
require "nice_hash"
set :protection, :except => :frame_options
set :bind, "0.0.0.0"
@MarioRuiz
MarioRuiz / example_registration_test.rb
Last active April 27, 2020 12:23
Creates 1000 good random and unique requests to register a user and test that the validation of the fields is correct by the user was able to be registered. Send 800 requests where just one field is wrong and verify the user was not able to be created.
# nice_http gem: https://github.com/MarioRuiz/nice_http
# nice_hash gem: https://github.com/MarioRuiz/nice_hash
# string_pattern gem: https://github.com/MarioRuiz/string_pattern
require 'nice_http'
url = "https://reqres.in/"
# The valid national chars to be used to generate random values when required
@MarioRuiz
MarioRuiz / smart-lola.rb
Created October 13, 2022 14:48
Learn to write Spanish and English words. Aprende a escribir palabras en Inglés y Español
# Requires an Apple Mac and Ruby
# I created this gist just to help my daughter to learn how words are written in Spanish and English.
# The script will pronounce a random word in the language selected and the child needs to write the word letter by letter.
require 'string_pattern'
require 'open3'
require 'io/console'
ENV['NOMBRE'] ||= 'Pedro'
ENGLISH = ENV['ENGLISH'] == 'true'