Skip to content

Instantly share code, notes, and snippets.

@artem1
artem1 / Twitter oauth header
Last active Aug 29, 2015
Tested version of twitter oauth authorization header algorithm, at 2014-02-05. Used for only 2 methods: get request token and exchange request token to access token
View Twitter oauth header
private string MakeAuthHeader(string state = null, string token = null, string verifier = null)
{
//kvp for each possible parameter, participating in header or signing
var oauthNonce = new Kvp("oauth_nonce", Convert.ToBase64String(Guid.NewGuid().ToByteArray()));
var oauthCallbackUrl = state != null ? new Kvp("oauth_callback", redirectUrl + "?state=" + state) : null;
var oauthConsumerKey = new Kvp("oauth_consumer_key", consumerKey);
var oauthTimestamp = new Kvp("oauth_timestamp", UnixTimestampUTC().ToString(CultureInfo.InvariantCulture));
var oauthSignatureMethod = new Kvp("oauth_signature_method", "HMAC-SHA1");
var oauthVersion = new Kvp("oauth_version", "1.0");
var oauthToken = token != null ? new Kvp("oauth_token", token) : null;
@artem1
artem1 / Throttle
Created Jan 29, 2014
Sample of throttling when async pool datasource by event stream from redis, with unit test, c#, atomic, interlocked, lock-free
View Throttle
public class WorkQueueWatchService: IDisposable
{
private readonly INotificationService notifications;
private readonly IWorkQueue queue;
private readonly Timer pullTimer;
private readonly int throttle;
private long changes;
private DateTime lastRun;
public WorkQueueWatchService(INotificationService ns, IWorkQueue wq, int throttleDelay = 2000)