Skip to content

Instantly share code, notes, and snippets.

@jittuu
jittuu / CaptchaBreaker.cs
Created December 18, 2014 15:01
CaptchaBreaker using tesseract
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Set up

Download and install ResEx at http://resex.codeplex.com/.

Adding additional language

  1. Open resx file with ResEx. You would see as below. In this example, we have two additional languages (Indonesia and Simplified Chinese). image
@jittuu
jittuu / nCr.go
Created July 7, 2015 13:58
Binomial coefficient
package main
import "fmt"
func main() {
//nCr
n := 7
r := 2
c := BinCoeff(n, r)
public static string ToSlug(this string target)
{
var pattern = @"[^0-9a-zA-Z]+";
return Regex.Replace(target, pattern, "-")
.Trim('-')
.ToLowerInvariant();
}
if (user.IsGoldPartner()) 
{
// do something
}
public class User
{
public int PostedPostCount { get; set; }
public DateTime LastActivityDate { get; set; }
public bool IsGoldPartner()
[TestClass]
public class DateTimeExtensionTest
{
[TestMethod]
public void FiveMinAgoShouldBeBeforeCurrent()
{
var current = DateTime.Now;
var fiveMinAgo = current.AddMinutes(-5);
Assert.IsTrue(fiveMinAgo.IsBefore(current));
[TestMethod]
public void ToSlugShouldReturnJustSlug()
{
var value = "^&*#$Slug testing ?? @3 with--- some-tokens!.";
var expected = "slug-testing-3-with-some-tokens";
var actual = value.ToSlug();
Assert.AreEqual(expected, actual);
}
if (user.PostedPostCount > 1000
&& user.LastActivityDate >= DateTime.Today.AddMonths(-3))
{
// do something
}
// Is it Gold Partner?
if (user.PostedPostCount > 1000 
&& user.LastActivityDate >= DateTime.Today.AddMonths(-3)) 
{
// do something
}
public static class DateTimeExtensions
{
public static bool IsAfter(this DateTime current, DateTime value)
{
return current > value;
}
public static bool IsBefore(this DateTime current, DateTime value)
{
return current < value;