Skip to content

Instantly share code, notes, and snippets.

require "selenium-webdriver"
require "test/unit"
class SeleniumRubyTest < Test::Unit::TestCase
@@driver
def setup
# create Driver object for Chrome
@@driver = Selenium::WebDriver.for :chrome
# Navigate to URL
@GiovaniFSO
GiovaniFSO / main.py
Last active February 24, 2023 12:17
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
navegador = webdriver.Firefox()
navegador.get("https://asesweb.governoeletronico.gov.br")
navegador.find_element(By.ID,'url').send_keys('tjro.jus.br/')
navegador.find_element(By.XPATH,'//*[@id="input_tab_1"]').click()
time.sleep(10)
@GiovaniFSO
GiovaniFSO / gist:0da4b0e2d3e471256c963494c2421736
Created April 6, 2021 21:42
add video to youtube player
window.open((document.getElementsByTagName('iframe')[0].attributes.src.value).replace('controls=0', 'controls=1'))
@GiovaniFSO
GiovaniFSO / encrypt_decrypt.rb
Last active September 25, 2020 05:31
Encrypt and Decrypt using Openssl Ruby
require 'openssl'
class CryptoService
def encrypt(data,key)
digest = Digest::SHA256.new
digest.update(key)
key = digest.digest
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
cipher.encrypt

Whenever gem

schedule.rb

every '0 2 20 * *' do
  command "echo 'you can use raw cron syntax too'"
end

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@GiovaniFSO
GiovaniFSO / reconnect db
Created August 26, 2019 16:36
Reconnect to a lost database connection using an exception block trick (ruby, rails, mysql, activerecord)
def my_task
loop do
begin
database_access_here
rescue Exception => ex
begin
ActiveRecord::Base.connection.reconnect!
rescue
sleep 60
# Rubysec
gem install bundler-audit #security gems
bundle audit check --update
bundle audit
bundle audit update
gem install rubycritic
group :development do
gem 'brakeman' #security gems
@GiovaniFSO
GiovaniFSO / scope.rb
Last active November 27, 2018 04:11
Model Level Validations, some scope definitions
class User < ApplicationRecord
validates :name, :email, :age, presence: true #attributes can't be empty to save
validates :email, :age, absence: true #need to be empty to save
validates :email, uniqueness: true #uniqueness attributes
validates :age, numericality: true #only where attribute value is numeric
@GiovaniFSO
GiovaniFSO / ldap_service.rb
Last active August 26, 2019 16:46
Connection with Active Directory to get a list of users where has name and last name and a search of user from sAMAccountName
require 'net/ldap'
class LdapService
def con
@ldap = Net::LDAP.new
@ldap.host = host
@ldap.port = 389
@ldap.auth "CN=USERNAME,OU=FOLDER,OU=Users,OU=FOLDER,OU=FOLDER,OU=FOLDER,DC=example,DC=com", "password"
end