Skip to content

Instantly share code, notes, and snippets.

@zeryx
Last active January 10, 2017 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeryx/dc7e799df11beb3d0b57f6efbeda7816 to your computer and use it in GitHub Desktop.
Save zeryx/dc7e799df11beb3d0b57f6efbeda7816 to your computer and use it in GitHub Desktop.
example C# script for interfacing with algorithmia using application/text I/O
using System;
using System.Net;
using System.IO;
public class Program
{
public static void Main()
{
// C# from http://stackoverflow.com/questions/25306570/convert-curl-to-c-sharp
String url = "https://api.algorithmia.com/v1/algo/nlp/Summarizer/0.1.3";
var request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/text";
request.Method = "POST";
request.Headers.Add("Authorization", "Simple <YOUR API KEY HERE>");
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string data = @"A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.
Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending.
We propose a solution to the double-spending problem using a peer-to-peer network. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work,
forming a record that cannot be changed without redoing the proof-of-work. The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power.
As long as a majority of CPU power is controlled by nodes that are not cooperating to attack the network, they'll generate the longest chain and outpace attackers.
The network itself requires minimal structure.
Messages are broadcast on a best effort basis, and nodes can leave and rejoin the network at will, accepting the longest proof-of-work chain as proof of what happened while they were gone.";
streamWriter.Write(data);
}
var response = request.GetResponse();
string text;
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
Console.WriteLine(text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment