Skip to content

Instantly share code, notes, and snippets.

View julien-sarazin's full-sized avatar

Julien Sarazin julien-sarazin

View GitHub Profile
@julien-sarazin
julien-sarazin / amqp-helper.ts
Created October 22, 2021 07:13
RabbitMQ/AMQP Helper - SendToQueue Typescript
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) {
@julien-sarazin
julien-sarazin / demo.js
Created March 14, 2019 11:40
How promises should be used.
return getSomethingAsync()
.then(processData)
.then(doSomethingEvenMoreComplex)
.then(butWithVeryExplicitNaming)
.catch(handlingErrorWithStyle)
function getSomethingAsync() {
return http.request() // basically initiate a promisified call
}
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();
@julien-sarazin
julien-sarazin / tbotb.js
Last active March 10, 2016 01:23
to-beer-ornot-to-beer
function drink(Promise, friend, pints){
var count = 0;
var promises = pints.map(function(pint){
return friend
.drink()
.then(increaseCount)
.catch(reject);
});
function closure(number){
var array = [];
function push(x){
array.push(function(){
return x;
});
}
for (var i = 0 ; i < number ; i++){
@julien-sarazin
julien-sarazin / binary.js
Last active March 10, 2016 01:13
Solution for Binary String.
function countPosBits(input){
return isNaN(input) ? 0 : parseInt(input).toString(2).replace(/0/g, '').length;
};