Skip to content

Instantly share code, notes, and snippets.

@azyobuzin
Created September 17, 2012 07:54
Show Gist options
  • Save azyobuzin/3736086 to your computer and use it in GitHub Desktop.
Save azyobuzin/3736086 to your computer and use it in GitHub Desktop.
string ExpandUstreamUri(string uri)
{
const string alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var id = uri.TrimStart("http://ustre.am/".ToArray());
return "http://www.ustream.tv/channel/id/" +
id.Reverse()
.Select((c, i) => Math.Pow(alphabet.Length, i) * alphabet.IndexOf(c))
.Sum();
}
ExpandUstreamUri("http://ustre.am/xGQd")
// "http://www.ustream.tv/channel/id/8029509" が返ってきます
// http://www.ustream.tv/channel/id/******* は http://www.ustream.tv/channel/******* にリダイレクトされるので
// http://www.ustream.tv/channel/azyobuzich にアクセスすることと同じです
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment