Skip to content

Instantly share code, notes, and snippets.

(ns tron.neil.bots
(:require [tron.core :as tron]))
(def directions {:right [1 0]
:down [0 1]
:left [-1 0]
:up [0 -1]})
(def pos [3 4])
@NeilRobbins
NeilRobbins / Hunt in files for things.sh
Last active December 16, 2015 20:49
Change the regex to match requirements Example 1 (line 1) Search in packages.xml files for those that reference a given package. Example 2 (line 3) Search in csproj files for references
find . -name packages.config -exec grep -H -n '^.*System.Windows.*' {} \;
find . -name *.csproj -exec grep -H -n '^.*<Reference Include="System.Windows.Controls.Toolkit.Internals, Version=4.0.5.0, Culture=neutral, PublicKeyToken=2c5c654d367bf4a7, processorArchitecture=MSIL">' {} \;
@NeilRobbins
NeilRobbins / Alt.Fizzbuzz.hs
Last active December 15, 2015 02:49
Fizzbuzz in Haskell - just because
import System.Environment
main = do (countTo:_) <- getArgs
let numbers = fizzbuzz [0..(read countTo)]
mapM_ putStr $ map (\n -> n ++ ", ") $ init numbers
putStrLn $ last numbers
divides d n = rem n d == 0
fb x = if (divides 15 x) then "Fizzbuzz" else if (divides 3 x) then "Fizz" else if (divides 5 x) then "Buzz" else show x
@NeilRobbins
NeilRobbins / gist:5098828
Created March 6, 2013 11:56
Regular Expression for a 4 part version number
^([0-9]+[.]){3}[0-9]+$
@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 / 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 / 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 / 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 / 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 / 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