Skip to content

Instantly share code, notes, and snippets.

@adrianobarroso
Last active March 28, 2018 14:05
Show Gist options
  • Save adrianobarroso/892f9df21f9083ab6104833e2d9a9f0b to your computer and use it in GitHub Desktop.
Save adrianobarroso/892f9df21f9083ab6104833e2d9a9f0b to your computer and use it in GitHub Desktop.
Questions for Jurema
class Fish
attr_accessor :array
attr_reader :id, :origin, :color
@@array = []
def initialize(attr = {})
@name = attr[:name]
@id = @@array.empty? ? 0 : @@array.size
@@array << self
end
def self.find(id)
@@array.select {|fish| fish.id == id}
end
def self.method_missing(m, *args, &block)
@@array.select {|f| f.send(m.to_s.split('find_by_').last) == args.first}
end
end
class Tuna < Fish
def initialize(attr = {})
super(attr)
@origin = attr[:origin]
end
end
class Shark < Fish
def initialize(attr = {})
super(attr)
@color = attr[:color]
end
end
#
# Testes
#
tuna = Tuna.new(name: 'yellow fin', origin: 'SouthPacific')
tuna2 = Tuna.new(name: 'blue fin', origin: 'NorthPacific')
shark = Shark.new(name: 'white shark', color: 'blue')
shark2 = Shark.new(name: 'whale shark', color: 'brown')
p Tuna.find_by_origin('NorthPacific')
p Shark.find_by_color('brown')
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://api.exemplo.com.br/estados", false);
xhr.send();
var data = xhr.responseText;
console.log(JSON.stringify(JSON.parse(data), null, 2));
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<a href="#" id="mostrar-estados">Mostrar estados</a><br/>
<div id="estado">
<ul></ul>
</div>
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://api.exemplo.com.br/estados", false);
xhr.send();
var data = JSON.parse(xhr.responseText);
console.log(JSON.stringify(data, null, 2));
data.estados.forEach((element) =>
$('#estado ul').append("<li>" + element.nome + " -" + element.uf + "</li>")
)
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--[if IE]>
<style>
body {
background-color: green !important;
}
</style>
<![endif]-->
<style>
body {
background-color: blue;
}
@media screen and (min-width:0\0) {
body {
background-color: black !important;
}
}
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet">
<title>Document</title>
<style>
body {
font-family: 'Press Start 2P', cursive;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<h1>Adriano Wiermann Barroso</h1>
</body>
</html>
for (i = 0; i <= 100; i++) {
var fizz = i % 3 == 0
var buzz = i % 5 == 0;
var word = ""
if (fizz) {
word += buzz ? "FizzBuzz" : "Fizz"
} else if (buzz) {
word += "Buzz"
} else {
word += i
}
console.log(word);
}
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Parallax</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
</head>
<body>
<div class="parallax-container">
<div class="parallax"><img src="https://picsum.photos/1200/900"></div>
</div>
<div class="section white">
<div class="row container">
<h2 class="header">Parallax</h2>
<p class="grey-text text-darken-3 lighten-3">Parallax is an effect where the background content or image in this case, is moved at a different speed than the foreground content while scrolling.</p>
</div>
</div>
<div class="parallax-container">
<div class="parallax"><img src="https://picsum.photos/1200/900/?random"></div>
</div>
<div class="section white">
<div class="row container">
<h2 class="header">Parallax</h2>
<p class="grey-text text-darken-3 lighten-3">Parallax is an effect where the background content or image in this case, is moved at a different speed than the foreground content while scrolling.</p>
</div>
</div>
<div class="parallax-container">
<div class="parallax"><img src="https://picsum.photos/g/1200/900"></div>
</div>
<script>
var elem = document.querySelectorAll('.parallax');
var instance = M.Parallax.init(elem);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment