Skip to content

Instantly share code, notes, and snippets.

View beccasaurus's full-sized avatar

Rebecca Taylor beccasaurus

View GitHub Profile
@beccasaurus
beccasaurus / NUnit_BeforeAndAfterHooks.cs
Created February 19, 2011 01:41
Before() and After() hooks for NUnit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using NUnit.Framework;
namespace BeforeAndAfterHooks {
public delegate void Before(Spec spec);
@beccasaurus
beccasaurus / MyCompany.MyApp.Entities.Dog.cs
Created March 7, 2011 04:25
Trying to create Model Metadata for classes referenced from other assemblies in ASP.NET MVC (for validations)
namespace MyCompany.MyApp {
public class Dog {
public string Name;
// There are lots of other classes, each with lots of properties
// It would be a huge pain to write wrappers for each and every class.
//
// NOTE - it shouldn't matter (?) but the external assembly that I'm trying
// to use defines its classes with fields instead of properties. Dunno why.
@beccasaurus
beccasaurus / BeforeFilterAttribute.cs
Created March 11, 2011 11:54
Rails-like before filter
public class BeforeAttribute : ActionFilterAttribute {
public BeforeAttribute() {
Methods = string.Empty;
Except = string.Empty;
Only = string.Empty;
}
public BeforeAttribute(params string[] methodNames) : this() {
Methods = string.Join(" ", methodNames);
}
@beccasaurus
beccasaurus / README.markdown
Created March 21, 2011 22:17
MSBuild equivalent of Visual Studio "Publish"

Publish via MSBuild

Note: the publish-via-msbuild.bat shown here simply builds the site and drops it into a directory, transforming the Web.configs

It does NOT sync the directory in any meaningful way.

To do that, I recommend using a tool like Rsync or MSDeploy

MSDeploy example:

@beccasaurus
beccasaurus / assembly-info.cs
Created March 24, 2011 03:33
Little script for spitting out .NET Assembly info ... putting it here incase I forget about it ...
// Note - one day, I'll make this into something more and release it as a package ...
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Text.RegularExpressions;
// TODO add some built in 'grep'
@beccasaurus
beccasaurus / ValidationExtensions.cs
Created March 31, 2011 11:15
For validating models in MVC ...
using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Reflection;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MyApp.Models {
@beccasaurus
beccasaurus / MoreRandom.cs
Created April 1, 2011 21:41
I keep copy/pasting this around ... it gives you a System.Random that's seeded with a Cryptographically stong value
using System;
using System.Security.Cryptography;
namespace System {
/// <summary>Returns a System.Random that has been seeded with a cryptographically string random number</summary>
public class MoreRandom : Random {
/// <summary>Initializes a MoreRandom (which initializes a seeded Random)</summary>
public MoreRandom() : base(MoreRandom.Seed) {}
@beccasaurus
beccasaurus / CryptographyExtensions.cs
Created April 1, 2011 21:43
I constantly forget how to convert to/from Base64 and stuff like that ...
using System;
using System.Text;
// Choose whatever namespace you want people to use to opt-in ...
namespace System {
public static class CryptographyExtensions {
public static Encoding DefaultEncoding = Encoding.UTF8;
@beccasaurus
beccasaurus / Factories.cs
Created April 1, 2011 21:45
Pretty good example of using FactoryMan, IMHO ...
using System;
using FactoryMan.Generic;
using FactoryMan.Sequences;
namespace MyApp.Specs {
public class Factories {
public Factories() {
FactoryMan.Factory.CreateMethod = "Save";
@beccasaurus
beccasaurus / record-using-x11.sh
Created April 9, 2011 22:27
example that specifies a specific resolution and offset
ffmpeg -f alsa -i hw:1,0 -f x11grab -r 30 -s 200x200 -i :0.0+1280,0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y firstx11grabtest.mkv