Skip to content

Instantly share code, notes, and snippets.

View thiagopintodev's full-sized avatar
🏠
Working mostly from home since 2006

Thiago Almeida thiagopintodev

🏠
Working mostly from home since 2006
View GitHub Profile
require 'socket'
class MyIcmpSocket
ICMP_ECHO_REQUEST_TYPE = 8
ICMP_ECHO_REQUEST_CODE = 0
ICMP_HEADER_SIZE = 8
def initialize
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_RAW, Socket::IPPROTO_ICMP)
end
@thiagopintodev
thiagopintodev / calculator_command.rb
Last active January 22, 2023 22:22
tres exemplos de controllers Command para a landing page
class CalculatorCommand < AppCommand
class Error < StandardError; end
def self.sum(a, b)= a + b
def self.sub(a, b)= a - b
def self.mul(a, b)= a * b
def self.div(a, b)= a / b
def self.call (args)
log "Called #{self}.#{__method__} with args #{args}"
class BookCommand < AppCommand
def self.call args
log :higher, "Called #{self}.#{__method__} with args #{args}"
new(args).call
end
def initialize args
@args = args
end
require 'uri'
require 'json'
require 'net/http'
# https://dog.ceo/dog-api/
class DogCeoAPI
def self.get_random_mocked
{
"message" => "https://images.dog.ceo/breeds/terrier-welsh/lucy.jpg",
"status" => "success"
module CpfJames
module_function
def protect(string)
string.split(' ').map { |s| valid?(s) ? mask(s) : s }.join(' ')
end
def valid?(s)
!!s.match(/\d{3}.\d{3}.\d{3}-\d{2}/)
end
@thiagopintodev
thiagopintodev / install_wifi_on_ubuntu.sh
Created December 21, 2019 01:46
install wifi on ubuntu
sudo apt install firmware-b43-installer
@thiagopintodev
thiagopintodev / faxtures.rb
Created October 12, 2018 21:33
Faxtures (pronounced Facts-tures) are special fixture files that read, write, and COMPARE large outputs
module Faxtures
module_function
class Error < StandardError; end
class ReadFileNotFound < Error; end
# def read(*names, name, &block)
# TODO: read file line by line for RAM optimization
# end
#!/usr/bin/env ruby
class Symbol
def with(*args, &block)
->(caller, *rest) { caller.send(self, *rest, *args, &block) }
end
end
require 'active_support/core_ext/string'
require 'colorize'
inherit_from:
- .rubocop_todo.yml
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
ExtraDetails: true
EnabledByDefault: true
UseCache: true
CacheRootDirectory: ~
@thiagopintodev
thiagopintodev / test_helper.rb
Created June 17, 2017 14:10
Minitest for weekends
#...
n = Time.now
if n.friday? || n.saturday? || n.sunday?
Minitest::Test.class_eval do
def result_code
failure && failure.result_code || '👍 '
end
end