Skip to content

Instantly share code, notes, and snippets.

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]
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]}`)
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);
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);
public UpdateInventoryResponse UpdateInventoryProducts(UpdateInventoryProductsRequest updateRequest) {
var response = productsService.updateInventoryProducts(updateRequest);
return response;
}
function parseJwt (token) {
var payload = token.split('.')[1];
var base64 = payoad.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
};
console.log(parseJwt('jwt_token'))
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
[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);
}
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");
[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.");