Skip to content

Instantly share code, notes, and snippets.

View ChrisMissal's full-sized avatar
💭
set status

Chris Missal ChrisMissal

💭
set status
View GitHub Profile
@ChrisMissal
ChrisMissal / screencapture.ps1
Created September 19, 2013 20:58
How can I do a screen capture in windows powershell?
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
@ChrisMissal
ChrisMissal / About.md
Last active August 30, 2019 17:12
Example of Partial DbContext and interface for mocking/testing.

About

The file WorkifyEntities.Context.cs is what EF generates for us, or in EF Core, you can create yourself on top of the base class.

The Entities.cs file, we create our own partial class, and assign an interface. From here, we will register our own interface while the instance will be the DbContext.

Usage

Just inject the interface and use it. You will have to add properties and methods to the interface to match the DbContext.

#requires -version 2.0
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidatePattern('\.rptproj$')]
[ValidateScript({ Test-Path -PathType Leaf -Path $_ })]
[string]
$Path,
[parameter(
public class ConsistentInterval : IDisposable
{
private readonly TimeSpan delay;
private readonly CancellationToken cancellationToken;
private readonly DateTimeOffset startTime;
public ConsistentInterval(TimeSpan delay, CancellationToken cancellationToken)
{
this.delay = delay;
this.cancellationToken = cancellationToken;
@ChrisMissal
ChrisMissal / FailingTest.cs
Last active September 14, 2017 20:53
Auto property initializers vs Expression-bodied members. Explained here: http://thebillwagner.com/Blog/Item/2015-07-16-AC6gotchaInitializationvsExpressionBodiedMembers
public class Test
{
public class Name
{
public string Text { get; set; }
}
public abstract class Widget
{
public abstract Name Name { get; }
@ChrisMissal
ChrisMissal / ApiController.cs
Last active December 29, 2015 11:59
URLs as JSON to be used on the client
using System.Linq;
using System.Web.Mvc;
using Construction.Core.Features.QuickSearch;
using Construction.Core;
using Construction.Core.Extensions;
using Core.Helpers;
using Newtonsoft.Json.Linq;
public class ApiController : BaseController
{
@ChrisMissal
ChrisMissal / find_references.sql
Created September 19, 2013 15:03
Find all columns that have foreign keys referencing another table.
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'tablename')
order by TableWithForeignKey, FK_PartNo
@ChrisMissal
ChrisMissal / FindDllVersions.cs
Created July 30, 2013 15:32
Search a directory and subdirectories for DLLs by name and list by Version numbers descending.
var path = @"C:\dev\whatever"; var dllFileName = @"something.dll"; var files = from file in new DirectoryInfo(path).GetFiles(dllFileName, SearchOption.AllDirectories) let fvi = FileVersionInfo.GetVersionInfo(file.FullName) select new { File = file.FullName, Version = fvi }; files.OrderByDescending(f => f.Version.FileMajorPart) .ThenByDescending(f => f.Version.FileMinorPart) .ThenByDescending(f => f.Version.FileBuildPart) .Dump();
@ChrisMissal
ChrisMissal / Pixel.cs
Created July 22, 2013 17:55
"Pixel" class that exposes ints for use on a screen, but can use doubles for calculations.
public class Pixel
{
private double _x;
private double _y;
public Pixel(double x, double y)
{
_x = x;
_y = y;
}