Skip to content

Instantly share code, notes, and snippets.

View ArmandoAssuncao's full-sized avatar

Armando Assunção ArmandoAssuncao

View GitHub Profile
@ArmandoAssuncao
ArmandoAssuncao / ruby_selenium_with_proxy.rb
Last active November 26, 2023 14:29
Ruby Selenium with Proxy
# Obs: Work only in Firefox 66.x or prior, because the function "driver.switch_to.alert.send_keys" not work in new versions.
# tested in selenium-webdriver (3.142.7), webdrivers (4.6.0) and firefox (66.0.5)
# Download firefox to folder
# config/initializers/selenium.rb
Selenium::WebDriver::Firefox::Binary.path = 'path/to/firefox/66.x'
# -----------------------------------------------------------------------------------------------------
# Code
@ArmandoAssuncao
ArmandoAssuncao / validate_ip.rb
Created May 5, 2020 12:31
validates ip by format and blacklists
def ip_valid?(ip_str)
begin
ip = IPAddr.new(ip_str).to_i
rescue
return false
end
blacklist_ranges = [
['0.0.0.0', '0.255.255.255'],
['10.0.0.0', '10.255.255.255'],
@ArmandoAssuncao
ArmandoAssuncao / calc_time_all_databases.rb
Last active May 4, 2020 23:23
Calculates time between updated_at and created_at from all databases
Mongo::Logger.logger.level = Logger::FATAL
mongo_client = Mongo::Client.new(['127.0.0.1'])
ignore_dbs = [
'admin',
'config',
].freeze
dbs_data = mongo_client.list_mongo_databases.reject { |db| ignore_dbs.include?(db.name) }.map do |mongo_database|
puts mongo_database.name
@ArmandoAssuncao
ArmandoAssuncao / test
Last active February 9, 2021 13:48
Sets read only to field non nil in MongoId
> user = User.new
> user.username
=> nil
> user.username = 'kira'
=> "kira"
> user.username = 'kira'
=> "kira"
> user.username = 'Light'
Mongoid::Errors::Validations:
message:
@ArmandoAssuncao
ArmandoAssuncao / InsertManyWithValidations.rb
Last active March 14, 2020 18:08
validates model when uses function mongo insert_many
class InsertManyWithValidations
user = User.first
games = [
{ game_id: '1', name: 'Halo' },
{ game_id: '2', name: 'GoW' },
{ game_id: '2', name: 'KF' },
]
games = games.map do |game|
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
require('dotenv-flow').config()
const url = process.env.MONGO_URL || 'mongodb://localhost:27017/DATABASE_NAME'
const MongoClient = require('mongodb').MongoClient
const index = (key, options = null) => ({ key: key, options: options })
const indexesCollections = [
{
import JSZip from 'jszip';
import JSZipUtils from 'jszip-utils';
import saveAs from 'file-saver';
function urlToPromise(url) {
return new Promise(function(resolve, reject) {
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
reject(err);
} else {
@ArmandoAssuncao
ArmandoAssuncao / en.yml
Last active June 21, 2017 20:44 — forked from adamico/en.yml
Rails 4 with I18n working interpolations
en:
errors: &errors
messages:
bad_uri: is an invalid url
bad_protocol: must start with %{protocols}
activemodel:
errors:
<<: *errors
activerecord:
errors: