Skip to content

Instantly share code, notes, and snippets.

@wcharczuk
wcharczuk / RateLimiter.cs
Created August 14, 2011 21:10
Rate Limiter written in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
namespace YourNamespaceHere
{
[Serializable()]
public class RateLimiter
@wcharczuk
wcharczuk / StreamExtensions.cs
Created August 17, 2011 19:13
Stream Extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace yourNameSpaceHere
{
public static class StreamExtensions
{
@wcharczuk
wcharczuk / gist:1353509
Created November 9, 2011 23:19
C# Exception performance hit example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExceptionsAreBad
{
class Program
{
@wcharczuk
wcharczuk / iclean.py
Created November 18, 2011 19:08
iTunes Media Directory Extra Files Cleaner
from pyItunes import *
import os
import sys
import urllib
extraFiles = []
libraryLocation = None
if len(sys.argv) > 1:
libraryLocation = sys.argv[1]
else:
@wcharczuk
wcharczuk / gist:1678325
Created January 25, 2012 20:01
installing postgres on os x lion w/ brew
#install postgres
brew install postgres
#setup postgres db dir
initdb -D /usr/local/var/postgres #init the database
#set postgres to load automatically && start postgres
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.2/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
@wcharczuk
wcharczuk / gist:1855878
Created February 17, 2012 22:38
sample nginx config
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
upstream myapp {
server www.bing.com weight=2;
@wcharczuk
wcharczuk / RouteParser.cs
Created April 2, 2012 15:07
C# Route Parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;
//TODO: probably want to change this if you're using it your project
namespace ClothesHorse.Core
{
@wcharczuk
wcharczuk / FSGrep.cs
Created April 9, 2012 14:33
C# File System Grep
public class FSGrep
{
public FSGrep()
{
this.Recursive = true;
}
public String RootPath { get; set; }
public Boolean Recursive { get; set; }
public String FileSearchMask { get; set; }
@wcharczuk
wcharczuk / pi.py
Created April 13, 2012 18:57
Pi Spigot Algorithm + Primality Check + Palindrome Check
#naive implementation of a pi spigot algorithm
def gen_pi(n):
q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
for j in range(n):
if 4 * q + r - t < m * t:
yield m
q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))/t - 10*m, x
else:
q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)/(t*x), x+2
@wcharczuk
wcharczuk / Spreadsheet.cs
Created April 19, 2012 20:41
CSV Builder with grouped columns
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using dict = System.Collections.Generic.Dictionary<string, string>;
namespace <YOUR NAMESPACE HERE>
{