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
import 'dart:io'; | |
void main() { | |
// Read some text from console | |
var password = stdin.readLineSync(); | |
// Check if password is correct | |
if (password == 'abc') { | |
print('Access granted'); | |
} else if (password == 'xyz') { |
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
const defaultValueHandler = { | |
get: (obj, property) => | |
property in obj ? obj[property] : 'general kenobi' | |
} | |
const objectWithDefaultValue = new Proxy({}, defaultValueHandler); | |
objectWithDefaultValue.a = 'b'; | |
console.log(objectWithDefaultValue.a); // b |
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
// Importing standart math library | |
// Note that with deferred imports we have to specify its name | |
// using _is_ keyword | |
import 'dart:math' deferred as math; | |
void main() { | |
greet(); | |
} | |
// This is a function that is async. I will talk about |
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
expect.extend({ | |
toBeISODate(received) { | |
// This regexp checks for formatting | |
if ( | |
!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(received) | |
) { | |
return { | |
pass: false, | |
message: `Expected ${received} to be a valid ISO date string`, | |
}; |
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
function executeWithFetch(request) { | |
// EXERCISE FOR THE READER | |
} | |
function executeWithAxios(request) { | |
// EXERCISE FOR THE READER | |
} | |
function ClientBuilder() { | |
return { |
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
expect.extend({ | |
toBePowerOf(received, power) { | |
if (typeof power !== 'number') { | |
throw new Error('expected power to be a number'); | |
} | |
if (typeof received !== 'number') { | |
throw new Error('expected value to be a number'); | |
} | |
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
expect(1).toBe(1); // Checking for value and reference equality | |
expect({a: 'b'}).toEqual({a: 'b'}); //Checking for deep value equality | |
expect('abacaba').toMatch(/bac/); // Checking if a string matches a regexp | |
expect({a: 'b', b: 'c'}).toMatchObject({a: 'b'}); // Checking for a partial object match | |
expect([1, 2, 3]).toContainEqual(2); // Checking if an array contains an element | |
expect(2).not.toEqual(3); // using not to negate any matcher | |
expect({a: 'b'}).toMatchObject({ | |
a: expect.any(String) | |
}); // Type checking |
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 Car { | |
constructor(make, model) { | |
this.make = make; | |
this.model = model; | |
} | |
start() { | |
console.log('vroom'); | |
} | |
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" declaration | |
function Car(make, model) { | |
this.make = make; | |
this.model = model; | |
} | |
// the start method | |
Car.prototype.start = function() { | |
console.log('vroom'); | |
} |
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
const client = ClientBuilder() | |
.forBaseUrl('https://some-api.com/api/') | |
.withHeaders({Authorization: 'Bearer ABACABA'}) | |
.usingAxios() | |
.build(); | |
client.post('UpdateData', {data: 'new data'}); |
NewerOlder