Skip to content

Instantly share code, notes, and snippets.

@noblethrasher
noblethrasher / DuplicatesFiles.cs
Created November 16, 2012 21:57
Finds duplicate files on a Windows system and generates a simple report.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Diagnostics;
namespace DuplicateFileFinder
{
@noblethrasher
noblethrasher / StringBuilderEx
Created December 13, 2012 20:00
A lazier StringBuilder...
sealed class StringBuilderEx
{
readonly List<Func<string>> parts;
Func<string, string> replace = null;
public int Capacity
{
get
{
abstract class ListPair<T>
where T : IComparable<T>
{
static IEnumerable<T> empty = new T[0];
public abstract IEnumerable<T> Merge();
protected virtual LeftList Left { get; private set; }
protected virtual RightList Right { get; private set; }
@noblethrasher
noblethrasher / gist:5383649
Last active December 16, 2015 05:19
A small AJAX library
function $xhr(url, success, fail) {
var _url = url;
var me = this;
var seperator = 'sdfsdfsdfdsweriweournClkjwa'; //TODO: Replace with a real pseudo random string generator
me.data = {};
function request_success(x) {
return (x.status == 200) || (x.status == 304);
}
@noblethrasher
noblethrasher / ArcReaction.js
Last active December 27, 2015 10:39
Yet another JavaScript library...
window.addHandler = window.addEventListener || window.attachEvent;
window.removeHandler = window.removeEventListener || window.detachEvent;
Object.prototype.isArray = function ()
{
return this.hasOwnProperty('length') && this.pop != null && this.push != null && this.join != null;
}
var Random = new (function ()
var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
function is_leap_year(y)
{
if((y % 4) != 0)
return false;
if((y % 100) == 0 && ((y % 400) != 0))
return false;
static IEnumerable<T> QuickSort<T>(IList<T> xs)
where T : IComparable<T>, IEquatable<T>
{
var stack = new Stack<Stack<T>>(new[] {new Stack<T>(xs)});
while (stack.Any())
{
var qs = stack.Pop();
var head = from q in qs where q.CompareTo(qs.Peek()) == 0 select q;
@noblethrasher
noblethrasher / IsSubstring
Last active August 29, 2015 13:57
IsSubstring
class SubstringRecognition
{
readonly string s;
int state = 0;
int pos = 0;
Func<char, SubstringRecognition>[] accept;
public bool Found
{
@noblethrasher
noblethrasher / gist:ba37ed6176ebeb679dd2
Created November 14, 2014 18:10
Exceptions as return filters
void Main()
{
try
{
SomeUnreliableOperation();
}
catch (SomeUnreliableOperationException.NotFound ex)
{
//do stuff
}
@noblethrasher
noblethrasher / F# and IL
Created December 1, 2014 01:01
F# and IL
type Foo =
| Bar of int * string
| Baz of bool * string
| Biz of string * string
let f foo =
match foo with
| Bar (x, s) -> s
| Baz (b, s) -> s