Skip to content

Instantly share code, notes, and snippets.

@artem1
artem1 / Twitter oauth header
Last active August 29, 2015 13:56
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
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 January 29, 2014 16:37
Sample of throttling when async pool datasource by event stream from redis, with unit test, c#, atomic, interlocked, lock-free
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)