Skip to content

Instantly share code, notes, and snippets.

public long CalculateChecksum(long value)
{
long sum = 0;
for (int i = 0; value != 0; i++)
{
for (var j = (value % 10) * (2 - i % 2); j != 0; j /= 10)
{
sum += j % 10;
}
value /= 10;
@tt
tt / Owin.cs
Created December 8, 2010 21:22
public interface IApplication
{
IResponse Respond(IRequest request);
}
public interface IRequest
{
string Method { get; }
string Uri { get; }
@tt
tt / .gitignore
Created February 14, 2011 01:42
[Bb]in
[Oo]bj
*.suo
*.user
@tt
tt / twitter_filtering.md
Created June 12, 2011 07:15
Twitter filtering

Metrics for improving relevance of Twitter stream

  • Retweets/favorites (both amount and by whom)
  • Scores from Klout/PeerIndex
  • Topics
  • Whilelist
  • Tweets/second (the less activity the less strict)
var uri = new Uri("http://example.com/?");
var uriBuilder = new UriBuilder(uri);
for (int i = 0; i < 10; i++)
{
uriBuilder.Query = uriBuilder.Query;
}
// uriBuilder.Uri.AbsoluteUri == "http://example.com/???????????"
@tt
tt / README
Created July 16, 2012 16:33
Self-modifying batch file
You can use this for all sorts of crazy. It seems it will continue at the exact character position where it left, so you can both prepend and append stuff while it's running.
@tt
tt / convert-to-tags.sh
Last active December 22, 2015 07:38
Convert all branches of origin matching `/v[0-9*/` to tags.
branches=`git branch -a | grep 'remotes/origin/v[0-9]*$' | cut -d '/' -f 3`
echo $branches | xargs -I {} git tag {} origin/{}
git push origin --tags
echo $branches | sed 's/^/:refs\/heads\//' | xargs git push origin
git remote prune origin
% chruby 1.9.2
% echo "pid = Process.spawn('sh -c \"exit 0\"'); _, status = Process.wait2(pid); warn status.inspect; warn status == 0; warn status.exitstatus == 0" | ruby
#<Process::Status: pid 50482 exit 0>
true
true
% echo "pid = Process.spawn('sh -c \"exit 0\"'); _, status = Process.wait2(pid); warn status.inspect; warn status == 1; warn status.exitstatus == 1" | ruby
#<Process::Status: pid 50454 exit 0>
false
touch foo
chmod u+x foo
echo 'require "fileutils"; FileUtils.cp("foo", "foo-1.9.2")' | (chruby 1.9.2 && ruby)
echo 'require "fileutils"; FileUtils.cp("foo", "foo-1.9.3")' | (chruby 1.9.3 && ruby)
ls -l
@tt
tt / main.go
Created March 2, 2015 18:45
Server-Sent Events example
package main
import (
"log"
"net/http"
"strconv"
"time"
"gopkg.in/antage/eventsource.v1"
)