Skip to content

Instantly share code, notes, and snippets.

View derekgates's full-sized avatar

Derek Gates derekgates

View GitHub Profile
@derekgates
derekgates / program.cs
Created April 17, 2013 18:01
Binding assembly loading to assemblies packed in resources files. Does NOT work with strong named assemblies due to .NET security!
[STAThread]
static int Main(string[] args)
{
//load assembly via the resources (such as using Costura advanced):
AttachResolverForLocalPaths();
}
public static void AttachResolverForLocalPaths()
{
var currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += OnCurrentDomainOnAssemblyResolve;
@derekgates
derekgates / gist:5313170
Last active December 15, 2015 19:39
Replace non-disposed SQLiteCommands to wrapped commands in using statements (covers .ExecuteNonQuery)
^[^\S\r\n]*[^using](?<sql>new SQLiteCommand\((.*), (.*)\))\.ExecuteNonQuery\(\);
replace with:
using (var c = ${sql})\nc.ExecuteNonQuery();
Finding any SQLiteCommand that is wrapped in a using statement:
@derekgates
derekgates / BootstrapHtmlExtensions.cs
Last active December 14, 2015 11:19
Pieces required to enable MVC client side validation with Bootstrap themes. Assumes you are using the 'control-group' and other elements from the Form examples in the Bootstrap tutorials (form-horizontal only for now).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace System.Web.Mvc.Html
{
public static class TwitterBootstrapHelperExtensions
@derekgates
derekgates / tomato_install.bat
Created January 31, 2013 08:46
"Installer" for tomato firmware. Put tomato.trx (can be official or a mod) in same directory. Script takes care of the rest with prompts. This is from polarcloud (official Tomato creator).
@echo off
echo ===========================================================================
echo This batch file will upload tomato.trx in the current directory to
echo 192.168.11.1 during the router's bootup.
echo.
echo * Set your ethernet card's settings to:
echo IP: 192.168.1.2
echo Mask: 255.255.255.0
echo Gateway: 192.168.1.1.
echo * Unplug the router's power cable.
@derekgates
derekgates / SetAssemblyInfoToVersion.ps1
Last active April 14, 2021 20:07
Changes version information in AssemblyInfo.cs files recursively from a given path. I use this with TeamCity to control the version number as the built in Build Feature runs before my psake script can obtain the version (clearing out the version!).
# SetAssemblyVersion.ps1
#
# http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html
# http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/21/powershell-script-to-batch-update-assemblyinfo-cs-with-new-version.aspx
# http://jake.murzy.com/post/3099699807/how-to-update-assembly-version-numbers-with-teamcity
# https://github.com/ferventcoder/this.Log/blob/master/build.ps1#L6-L19
Param(
[string]$path=$pwd
)
@derekgates
derekgates / assemblyinfo_buildnumber.ps1
Last active December 11, 2015 23:18 — forked from drlongnecker/psake task for getting assembly version for TeamCity
TeamCity psake script that sets BuildNumber from an existing AssemblyInfo in source. This is useful as it allows devs to control the version number without needing to change parameters in TeamCity for the project configuration. https://github.com/psake/psake/wiki/How-can-I-integrate-psake-with-Team-City%3F
task default -depends GetBuildNumber
task GetBuildNumber {
Assert ($base_directory -ne $null) '$base_directory should not be null. Try %system.teamcity.build.checkoutDir%'
Assert ($solution_name -ne $null) '$solution_name should not be null'
$version = gc $base_directory\$solution_name\Properties\AssemblyInfo.cs | select-string -pattern "AssemblyVersion" | Out-String
$version | Foreach-Object { Write-Host $_ }
$version -imatch '\[assembly: Assembly(File)?Version\("(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<revision>[0-9]+)\.(?<build>[0-9]+)"\)\]' | Out-Null
Assert ($matches -ne $null) 'Unable to find AssemblyVersion string!'
@derekgates
derekgates / global.asax
Created December 20, 2012 04:25
Disable Razor engine in MVC
public class Global : HttpApplication
{
public void Application_Start()
{
// Clears all previously registered view engines.
ViewEngines.Engines.Clear();
// Registers our Razor C# specific view engine.
// This can also be registered using dependency injection through the new IDependencyResolver interface.
ViewEngines.Engines.Add(new RazorViewEngine());