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 amqp, { Channel, Connection } from 'amqplib'; | |
export class AMQPHelper { | |
private connection?: Connection; | |
private channel?: Channel; | |
constructor(private readonly url: string) | |
{} | |
public async sendToQueue (queueName: string, data: 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
return getSomethingAsync() | |
.then(processData) | |
.then(doSomethingEvenMoreComplex) | |
.then(butWithVeryExplicitNaming) | |
.catch(handlingErrorWithStyle) | |
function getSomethingAsync() { | |
return http.request() // basically initiate a promisified call | |
} |
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
String.prototype.replaceAt = function(index, character) { | |
return this.substr(0, index) + character + this.substr(index + character.length); | |
}; | |
function Hangman(word){ | |
this.lives = 7; | |
this.word = word; | |
this.try = this.try.bind(this); | |
this.characters = []; | |
this._buildProgress(); |
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 drink(Promise, friend, pints){ | |
var count = 0; | |
var promises = pints.map(function(pint){ | |
return friend | |
.drink() | |
.then(increaseCount) | |
.catch(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
function closure(number){ | |
var array = []; | |
function push(x){ | |
array.push(function(){ | |
return x; | |
}); | |
} | |
for (var i = 0 ; i < number ; i++){ |
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 countPosBits(input){ | |
return isNaN(input) ? 0 : parseInt(input).toString(2).replace(/0/g, '').length; | |
}; |