- http-requests.
- mocked json-data.
- tricks to manage api.
- handlers, dispatchers etc.
This file contains hidden or 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
CREATE DATABASE IF NOT EXISTS mydb; | |
use mydb; |
This file contains hidden or 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
MongoClient.connect('mongodb://admin:pass@localhost:27017/mydb?authSource=admin').then((db) => { | |
return db.command({ | |
grantRolesToUser: 'user', | |
roles: ['dbAdmin', 'readWrite'] | |
}) | |
.then((stat) => { | |
console.log(stat); | |
}); | |
}) | |
.catch(console.log); |
This file contains hidden or 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 User { | |
public name: string; | |
public age: number; | |
public languages: string[]; | |
constructor(name:string); | |
constructor(name:string, age?: number); | |
constructor(name:string, age: number, languages?: string[]) | |
constructor(name?:string, age?: number, languages?: string[]) { |
This file contains hidden or 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
var mainContainer = $("#main"); | |
var loader = $(".load-bar"); | |
mainContainer.imagesLoaded() | |
.always( function( instance ) { | |
console.log('all images loaded'); | |
toggleElements(); | |
}) | |
.done( function( instance ) { | |
console.log('all images successfully loaded'); |
The code below assumes that each item should has two attributes: unique id and value field. Due to boolean comparison operator we can get an appropriate element.
- Check if current index in iteration is not equal to collection.length, otherwise - specify index to 0.
- Increase current index by 1.
- Check if current element has value. If not - do 2nd step, if yes - return it and break loop.
This file contains hidden or 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
let divide = (num: number, divider: number = 10) => { | |
return new Promise<any>((resolve, reject) => { | |
resolve(num / divider); | |
}); | |
}; | |
let collection: number[] = [30, 40, 50]; | |
Promise.all(collection.map((n) => { | |
return divide(n); | |
})).then((res: number[]) => { |
This file contains hidden or 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
let combine = (num: number, combiner: number = num) => { | |
return new Promise<any>((resolve, reject) => { | |
resolve(num + combiner); | |
}); | |
}; | |
let multiple = (num: number, multiplier: number = num) => { | |
return new Promise<any>((resolve, reject) => { | |
resolve(num * multiplier); | |
}); |
This file contains hidden or 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 copySync(src, dest) { | |
if (!fs.existsSync(src)) return false; | |
var data = fs.readFileSync(src, 'utf-8'); | |
fs.writeFileSync(dest, data); | |
} | |
function replaceInFile(src, replaceKey){ | |
fs.readFile(src, 'utf8', function (err, data) { | |
if (err) return console.log(err); | |
console.log(data); |
This file contains hidden or 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 loadDataOrDefault = <T>(response: any, defInstance?: T) => { | |
try { | |
return JSON.parse(response); | |
} catch(e) { | |
return defInstance ? defInstance : null; | |
} | |
}; | |
class Person { | |
constructor(public name: string = "Default", public age: number = 100) {} |
NewerOlder