Skip to content

Instantly share code, notes, and snippets.

@NeilRobbins
NeilRobbins / Curious Powershell Behaviour
Created December 12, 2010 01:06
Changing the number of arrays held in an array seems to change the way in which it behaves when parsed. Given an array which contains 1 item which is an array containing a single string item: $buzz = @(@("FooBar")) When the first item is requested: $b
cls
&{
$buzz = @(@("FooBar"))
Write-Host ("Length of parent array is: {0}" -f $buzz.Length)
Write-Host ("Type of parent array is: {0}" -f $buzz.GetType())
Write-Host ("Length of child array is: {0}" -f $buzz[0].Length)
Write-Host ("Type of child array is: {0}" -f $buzz[0].GetType())
}
Write-Host ""
@NeilRobbins
NeilRobbins / Radiant CMS error
Created January 29, 2011 17:43
Brand new radiant instance pushed to Heroku - any ideas?
Admin::WelcomeController#login (ActionView::TemplateError) "Permission denied - /disk1/home/slugs/4381d839-f0eb-4c10-897c-f5338a9513f3/mnt/public/javascripts/admin/all.js"
On line #9 of /home/slugs/4381d839-f0eb-4c10-897c-f5338a9513f3/mnt/.gems/gems/radiant-0.9.1/app/views/layouts/application.html.haml
6: - @stylesheets.uniq.each do |stylesheet|
7: = stylesheet_link_tag stylesheet
8: %script{:type=>"text/javascript"}="var relative_url_root = '#{ActionController::Base.relative_url_root}';"
9: = javascript_include_tag %w(admin/prototype admin/effects admin/lowpro admin/dateinput admin/pagestatus admin/cookie admin/popup admin/status admin/utility admin/codearea admin/tabcontrol admin/ruledtable admin/sitemap admin/shortcuts admin/toggle admin/validationerror admin/application), :cache => 'admin/all'
10: - @javascripts.uniq.each do |javascript|
11: = javascript_include_tag javascript
@NeilRobbins
NeilRobbins / How many parameters can a C# method take?
Created April 17, 2011 18:22
How many parameters can a C# method take?
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace LangTests
{
class Program
{
static void Main(string[] args)
@NeilRobbins
NeilRobbins / CountOfBufferedRows
Created March 22, 2012 13:58
Show how many rows of database objects are held in SQL Server buffer
SELECT
DB_NAME(osbd.database_id)AS [Database Name],
OBJECT_NAME(p.[object_id]) AS [ObjectName],
sum(osbd.row_count) AS [Count of Rows],
au.[type_desc] AS [Allocation Unit Type],
osbd.page_type
FROM sys.allocation_units au
inner join sys.dm_os_buffer_descriptors osbd on au.allocation_unit_id = osbd.allocation_unit_id
inner join sys.partitions p on au.container_id = p.hobt_id
WHERE p.[object_id] > 100
@NeilRobbins
NeilRobbins / gist:2226646
Created March 28, 2012 14:31
Backup, Restore, then delete a Database
Import-Module “sqlps” -DisableNameChecking
Set-Location SQLSERVER:\SQL\<MachineName>\<InstanceName>
Backup-SqlDatabase -ServerInstance <MachineName> -Database <NameOfDatabaseToCopy> -BackupFile <PathOfDirToStoreBak>\<BackupName>.bak
$RelocateData = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile(<NameOfDataFile>, "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\<NameOfDataFile>_COPY.mdf")
$RelocateLog = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("<NameOfDataFile>_log", "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\<NameOfDataFile>_COPY.ldf")
Restore-SqlDatabase -ServerInstance <MachineName>\<InstanceName> -Database <NameOfDatabaseToCopy> -BackupFile <PathOfDirToStoreBak>\<BackupName>.bak -RelocateFile @($RelocateData,$RelocateLog)
Invoke-Sqlcmd -Query "ALTER DATABASE <NameOfDatabaseToCopy> SET SINGLE_USER WITH ROLLBACK IMMEDIATE" -QueryTimeout 65534
Invoke-Sqlcmd -Query "DROP DATABASE <NameOfDatabaseToCopy>" -QueryTimeout 65534
@NeilRobbins
NeilRobbins / Type_aliasing_in_csharp.cs
Created October 12, 2012 17:06
Type aliasing in C#
/// <summary>
/// Effectively an alias of string, but with a stronger semantic
/// </summary>
/// <remarks>
/// Can still pass it to something (eg a screen element, or a db, that expects a string), but get to call it
/// by a semantically richer type name everywhere, especially where it may be returned (returned things not
/// being named, except indirectly by the method name)
/// </remarks>
public class FooId
{
@NeilRobbins
NeilRobbins / containerfree.cs
Created October 15, 2012 16:11
Example of container free DI with ASP.NET MVC
public class MvcApplication : System.Web.HttpApplication
{
// Everthing else...
protected void Application_Start()
{
// Everthing else...
ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory(new BuildControllers()));
}
@NeilRobbins
NeilRobbins / PascalsTriangle.fs
Created October 31, 2012 23:56
Pascals Triangle
module Program
open System
let rec factor (n : int64) =
match n with
| 0L -> 1L
| _ -> n * (factor (n - 1L))
let rec combinations r n =
@NeilRobbins
NeilRobbins / gist:4126083
Created November 21, 2012 17:06
Enable Remote PS-Sessions

Log on as the local system admin (must be the local system administrator account, no other admin account works)

Then run:

  • winrm quickconfig -quiet
  • winrm set winrm/config/client @{TrustedHosts="*"}

Optional (lets chunky stuff be passed around):

  • Powershell Set-PSSessionConfiguration -name ` microsoft.powershell -MaximumReceivedObjectSizeMB 1000 -Force
@NeilRobbins
NeilRobbins / gist:5098828
Created March 6, 2013 11:56
Regular Expression for a 4 part version number
^([0-9]+[.]){3}[0-9]+$