This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleCount | |
def initialize(num) | |
raise unless num.is_a?(Numeric) | |
@i = num | |
end | |
def count | |
if @i % 35==0 | |
@i = "Nama Team" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count(i) | |
if i % 35==0 | |
puts "Nama Team" | |
elsif i % 7==0 | |
puts "Team" | |
elsif i % 5==0 | |
puts "Nama" | |
else | |
puts i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### Retirado de um post do Stack Overflow ########################### | |
Só faz sentido saber o que é REST, já que RESTful é apenas a capacidade de fazer REST, ou seja, é uma questão gramatical. | |
A Representational State Transfer (REST), em português Transferência de Estado Representacional, é uma abstração da arquitetura da World Wide Web, mais precisamente, é um estilo arquitetural que consiste de um conjunto coordenado de restrições arquiteturais aplicadas a componentes, conectores e elementos de dados dentro de um sistema de hipermídia distribuído. | |
O REST ignora os detalhes da implementação de componente e a sintaxe de protocolo com o objetivo de focar nos papéis dos componentes, nas restrições sobre sua interação com outros componentes e na sua interpretação de elementos de dados significantes. | |
Ele foi definido oficialmente pela W3C. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Digite o texto:" | |
text = gets.chomp | |
words = text.split(" ") | |
frequencies = Hash.new(0) | |
words.each { |x| frequencies["#{x}"] += 1} | |
frequencies = frequencies.sort_by do |word, count| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript Document | |
//adiciona mascara ao telefone | |
function MascaraTelefone(tel){ | |
if(mascaraInteiro(tel)==false){ | |
event.returnValue = false; | |
} | |
return formataCampo(tel, '(00) 0000-0000', event); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#como usar o pusher para testar as notificações utilizando a dashboard do pusher.com | |
#1 - criar uma conta gratis | |
#2 - criar uma app | |
#3 - criar um arquivo com o nome que voce quiser (utilizaremos app.rb) | |
#4 - rodar o arquivo no terminal utilizando o comando ruby app.rb | |
#app.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Uma pequena aplicação que utiliza o Action Cable para notificar novos comentarios dentro dela | |
# Criando a mensagem de evento (tirado de um turial do site: https://www.onehub.com/blog/2016/02/18/event-notifications-in-rails-5-with-actioncable/) | |
# rails g model event message:string | |
# rake db:migrate | |
# Criando controller e view para manipular os eventos | |
# rails g controller events index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Faraday customs method: | |
class FaradayHttp | |
def with_openssl | |
system "openssl pkcs12 -in my-certificate-path -out certificate-output-path -nodes -password pass:certificate-password" | |
def cert_object | |
OpenSSL::X509::Certificate.new File.read("certificate-output-path") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A code snippet that helps me to rescue Zip::Error when handling .xlsx files on Rails | |
@file = params.fetch(:file) | |
begin | |
# try to open xlsx with roo gem | |
@spreadsheet = Roo::Excelx.new(@file.path, file_warning: :ignore) | |
rescue Zip::Error # corrupted xlsx file | |
# if got zip error, try to save the content in csv before open it |