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
console.log "Hello from Gist!" |
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 asyncFunc1 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 300 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "Second done!"}), 200 ); | |
}); |
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 asyncFunc1 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 300 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "Second done!"}), 200 ); | |
}); |
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
asyncFunc1().then(function( data ) { | |
console.log( data.message ); // Выводим результат первой функции | |
asyncFunc2().then(function( data ) { | |
console.log( data.message ); // Выводим результат второй функции | |
asyncFunc3().then(function( data ) { | |
console.log( data.message ); // Выводим результат третьей функции | |
// Тут делаем наши дела после того, как все функции отработали | |
console.log("Всё!"); | |
}); |
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
async function startAsync() { | |
let data_1 = await asyncFunc1(); // Функция работает как синхронная | |
let data_2 = await asyncFunc2(); // Затем эта функция работает как синхронная | |
let data_3 = await asyncFunc3(); // Наконец эта функция работает как синхронная | |
// Делаем то, что хотели сделать лишь при завершении работы всех трёх функций | |
console.log(data1.message, data2.message, data3.message); | |
}; | |
startAsync(); |
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
asyncFunc1().then(function( data ) { | |
console.log( data.message ); | |
return asyncFunc2(); | |
}).then(function( data_2 ) { | |
console.log( data_2.message ); | |
return asyncFunc3(); | |
}).then(function( data_3 ) { | |
console.log( data_3.message ); | |
// Тут делаем наши дела после того, как все функции отработали |
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 asyncFunc1 () { | |
console.log("Выполняюсь 1"); | |
return new Promise(function(resolve, reject) { | |
setTimeout( () => resolve({message: "First done!"}), 200 ); | |
}); | |
}; | |
function asyncFunc2 () { | |
console.log("Выполняюсь 2"); | |
return new Promise(function(resolve, reject) { |
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
link = "https://www.youtube.com/watch?v=Imeq3GeRttw" | |
link2 = "http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0" | |
link3 = "http://www.youtube.com/watch?v=EqS7oJcBi7w#t=0m10s" | |
youtube_parser = ( url ) -> | |
regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/ | |
match = url.match regExp | |
if match and match[7].length == 11 then match[7] else false | |
console.log youtube_parser( link ), youtube_parser( link2 ), youtube_parser( link3 ) |
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
var passport = require( 'passport' ), | |
FacebookStrategy = require( 'passport-facebook' ).Strategy; | |
passport.use( new FacebookStrategy({ | |
clientID: YOUR_CLIENT_ID, // Получить тут - https://developers.facebook.com/ | |
clientSecret: YOUR_CLIENT_SECRET, // Получить тут - https://developers.facebook.com/ | |
callbackURL: "/auth/callback", // Наш урл коллбэка в контроллере AuthController | |
enableProof: false, | |
profileFields: ['id', 'email', 'name'] // Поля, которые мы хотим получить у пользователя facebook | |
}, |
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
module.exports = { | |
attributes: { | |
name: { | |
type: 'string', | |
minLength: 42 | |
} | |
/* | |
и другие атрибуты и attribute/instance методы... | |
*/ |
OlderNewer