Skip to content

Instantly share code, notes, and snippets.

Avatar

Mario Ruiz MarioRuiz

View GitHub Profile
@MarioRuiz
MarioRuiz / api.rb
Last active Feb 23, 2019
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
View api.rb
# 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 / get_bearer_token.rb
Last active Feb 6, 2019
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
View get_bearer_token.rb
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 / example_registration_test.rb
Last active Apr 27, 2020
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.
View example_registration_test.rb
# 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 / fibonacci.rb
Last active Sep 9, 2018
Four different Ruby examples creating the Fibonacci sequence and calculating time consuming.
View fibonacci.rb
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 / proxy.rb
Last active Dec 6, 2016 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
View proxy.rb
#!/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,