Skip to content

Instantly share code, notes, and snippets.

public class ExceptionRaisingHandler : HttpClientHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
throw new HttpRequestException();
}
}
public class RequestBinClient
{
private readonly HttpClient _httpClient;
public RequestBinClient(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task PostStuff<T>(T stuff)
[TestMethod]
public async Extend_request()
{
var client = new HttpClient(new CustomHttpClientHandler());
var response = await client.PostAsJsonAsync("http://requestb.in/1lcvbtp1", new {foo = "bar"});
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
public class CustomHttpClientHandler : HttpClientHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var bytes = Encoding.ASCII.GetBytes(await request.Content.ReadAsStringAsync());
request.Headers.Add("RequestSignature", Convert.ToBase64String(bytes));
return await base.SendAsync(request, cancellationToken);
}
@jmarmolejos
jmarmolejos / config kong
Last active June 7, 2018 13:34
config kong
-- Add api
$ curl -i -X POST \
--url http://localhost:8001/apis/ \
--data 'name=requestbin' \
--data 'upstream_url=http://requestb.in/' \
--data 'request_host=requestb.in'
-- Update api
docker run -d --name kong-database \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
postgres:9.4
docker run -d --name kong \
--link kong-database:kong-database \
-e "KONG_DATABASE=postgres" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
public class BookmarksResolver : ValueResolver<LeObject, List<BookmarksDto>>
{
protected override List<BookmarksDto> ResolveCore(LeObject source)
{
return source.Bookmarks != null
? JsonConvert.DeserializeObject<List<BookmarksDto>>(source.Bookmarks)
: null;
}
}
var inputText = document.querySelector('#text_input');
var output = document.querySelector('#output');
var encodeBtn = document.querySelector('#encode_btn');
var decodeBtn = document.querySelector('#decode_btn');
encodeBtn.onclick = function() {
output.innerText = btoa(inputText.value);
};
// Some stuff I started prototyping at work but then had to switch to more 'important' things
var child_process = require('child_process');
child_process.exec('git log --decorate --oneline --stat=99999', (err, stdout, stderr) => {
var masterLineStart = "origin/master, origin/HEAD, master";
var lines = stdout.split("\n");
var lineAtMasterIndex = lines.findIndex(function(line){
return line.indexOf(masterLineStart) >= 0
})
cd /usr/local/share/
sudo wget http://phantomjs.googlecode.com/files/phantomjs-x.y.z-linux-x86_64.tar.bz2
sudo tar jxvf phantomjs-x.y.z-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-x.y.z-linux-x86_64/ /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs