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 a = [1,2,3] | |
const b = [2,3,4,5,6] | |
const intersection = a.filter(e => b.includes(e)) | |
console.log(intersection) // [2,3] |
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 buildUrl = function(url, params) { | |
let _url = url | |
if (url.indexOf('?') === -1) { | |
_url = url + '?' | |
} | |
let queries = [] | |
Object.keys(params).forEach(function(key) { | |
queries.push(`${key}=${params[key]}`) |
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 connectionString = "<your connectionstring that you won't be hardcoding like this>"; | |
var queueName = "ProductsUpdate"; | |
var deadLetterQueueName = QueueClient.FormatDeadLetterPath(queueName); // We'll get back to this in a bit | |
var client = QueueClient.CreateFromConnectionString(connectionString, queueName); | |
client.OnMessage(message => | |
{ | |
var updateRequest = message.GetBody<UpdateProductsRequest>(); | |
productsService.updateInventoryProducts(updateRequest); |
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
public UpdateInventoryResponse UpdateInventoryProducts(UpdateInventoryProductsRequest updateRequest) { | |
var connectionString = "<your connectionstring that should not be stored like this>"; | |
var queueName = "ProductUpdates"; | |
var client = QueueClient.CreateFromConnectionString(connectionString, queueName); | |
var jsonContent = JsonConvert.SerializeObject(updateRequest); | |
var message = new BrokeredMessage(jsonContent); |
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
public UpdateInventoryResponse UpdateInventoryProducts(UpdateInventoryProductsRequest updateRequest) { | |
var response = productsService.updateInventoryProducts(updateRequest); | |
return response; | |
} |
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 parseJwt (token) { | |
var payload = token.split('.')[1]; | |
var base64 = payoad.replace('-', '+').replace('_', '/'); | |
return JSON.parse(window.atob(base64)); | |
}; | |
console.log(parseJwt('jwt_token')) |
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 findJaccardIndex(collection1, collection2) { | |
return _.intersection(collection1, collection2).length / _.union(collection1, collection2).length | |
} | |
console.log(findJaccardIndex("Foo".split(''), 'Bar'.split(''))); // 0 | |
console.log(findJaccardIndex("Foo".split(''), 'Far'.split(''))); // 0.2 | |
console.log(findJaccardIndex("Foo".split(''), 'For'.split(''))); // 0.66 | |
console.log(findJaccardIndex("Foo".split(''), 'Foo'.split(''))); // 1 |
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
[TestMethod] | |
public async Task Request_auth_through_kong() | |
{ | |
var client = new HttpClient(new KongAuthHttpClientHandler()); | |
var response = await client.PostAsJsonAsync("http://requestb.in/1lcvbtp1", new {foo = "bar"}); | |
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); | |
} |
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
public class KongAuthHttpClientHandler : HttpClientHandler | |
{ | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
var kongUrl = "http://localhost:8000/"; | |
request.RequestUri = new Uri(kongUrl + request.RequestUri.PathAndQuery); | |
request.Headers.Add("ApiKey", "Rm9vYmFy"); |
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
[TestMethod] | |
[ExpectedException(typeof(HttpRequestException))] | |
public async Task Should_raise_exception() | |
{ | |
var httpClient = new HttpClient(new ExceptionRaisingHandler()); | |
var requestBinClient = new RequestBinClient(httpClient); | |
await requestBinClient.PostStuff(new {foo = "bar"}); | |
Assert.Fail("Should not reach this part."); |
NewerOlder