Skip to content

Instantly share code, notes, and snippets.

View irridescentrambler's full-sized avatar
🤓
Exploring

Nikhil Mohadikar irridescentrambler

🤓
Exploring
View GitHub Profile
// Just a normal function, not an async function.
function firstFunction(){
return new Promise((resolve, reject)=> {
var randomNumber = (Math.floor(Math.random() * 100) % 2);
if(randomNumber === 0){
setTimeout(() => {
resolve("Number is even");
}, 3000);
}else {
setTimeout(() => {
async function getData(url){
const response = await fetch(url);
console.log(response);
}
getData('https://dog.ceo/api/breeds/image/random');
getData('https://dog.ceo/api/breed/Husky/images/random');
function callDogApi(url){
const promise = fetch(url);
promise.then((response)=> {
if(response.status === 200){
console.log('Api call successful');
console.log(response);
}else{
throw new Error(response.status);
}
}).catch((error)=> {
async function myFirstAsyncFunction(){
return "Hello"
}
myFirstAsyncFunction().then((result) => {
console.log(result);
});
// Output
// Hello
function main(){
console.log("I'll have my breakfast");
setTimeout(() => {
console.log("I'll have my lunch");
}, 0);
console.log("I'll have my dinner");
}
main();
# == Schema Information
#
# Table name: accounts
#
# id :bigint not null, primary key
# balance :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Game
def play(matches)
matches.each do |match|
result = match.split(";")
first_team = Team.find_or_initialize(result[0])
second_team = Team.find_or_initialize(result[1])
outcome = result[2]
case outcome
when "win"
first_team.wins!
module SuperPowers
def powers
puts "I can run at 80 mph and lift 200 lbs weight"
end
end
class Human
def introduce
puts "Hi i am a #{self.class.name}"
end
class Human
def introduce
puts "Hello I am a #{self.class.name}"
end
end
class SuperHuman < Human
include SuperPowers
include Enemies
end
class A
end
class B < A
end
class C < B
end
A.descendants