Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
🏠
Working from home

Randle csharpforevermore

🏠
Working from home
View GitHub Profile
@csharpforevermore
csharpforevermore / Search All Tables for String.sql
Created December 3, 2017 22:33
Search All Tables for String.sql
USE DATABASE_NAME
DECLARE @SearchStr nvarchar(100) = 'SEARCH_TEXT'
DECLARE @Results TABLE (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
@csharpforevermore
csharpforevermore / debug-knockout.html
Last active December 3, 2017 21:23
How to output the values from KnockOut.js 2.1 (prior to 2.1 use revision 1). Source: http://www.knockmeout.net/2013/06/knockout-debugging-strategies-plugin.html
<pre data-bind="text: ko.toJSON.stringify(ko.toJS($data), null, 2)"></pre>
<pre data-bind="text: ko.toJSON.stringify(ko.toJS($parent), null, 2)"></pre>
<pre data-bind="text: ko.toJSON.stringify(ko.toJS($root), null, 2)"></pre>
<input data-bind="blah: console.log($data), value: description" />
<input data-bind="blah: console.log($parent), value: description" />
<input data-bind="blah: console.log($root), value: description" />
@csharpforevermore
csharpforevermore / IRepository.cs
Created November 23, 2017 13:31
Unit of Work Pattern The Unit of Work pattern is used to group one or more operations (usually database operations) into a single transaction or “unit of work”, so that all operations either pass or fail as one. Repository Pattern The Repository pattern is used to manage CRUD operations through an abstract interface that exposes domain entities…
// A generic repository interface that exposes a standard set of methods for performing CRUD operations on entities within the system.
public interface IRepository<T> where T : IEntity
{
IQueryable<T> GetAll();
T GetById(int id);
void Create(T entity);
void Update(T entity);
void Delete(int id);
}
@csharpforevermore
csharpforevermore / example-redirects.xml
Created November 18, 2017 02:48
Example of URL Redirects using Umbraco config file
<rewrite>
<rules>
<rule name="Route the requests for ETF" stopProcessing="false">
<match url="(.*)" />
<action type="None" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="Redirect from old to new url" stopProcessing="true">
@csharpforevermore
csharpforevermore / centre.css
Created August 21, 2017 00:10
Center anything using CSS3
.centerme {
margin: 0 auto;
display: table;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-o-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
@csharpforevermore
csharpforevermore / index.html
Created August 20, 2017 01:08
Basic HTML5 page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
</html>
@csharpforevermore
csharpforevermore / ETFSecuritiesFluentAuomationTest.cs
Created July 12, 2017 13:35
ETF Securities (www.etfsecurities.com) landing page Fluent Automation unit test
using System;
using System.Diagnostics;
using FluentAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Crantech.ETF.Website.IntegrationTestProject1
{
[TestClass]
public class ETFSecuritiesLandingPageTest : FluentTest
@csharpforevermore
csharpforevermore / FluentAutomationUnitTest.cs
Created July 12, 2017 13:07
Sample of FluentAutomation integration / unit tests
using System;
using FluentAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace xUnit.ETF
{
public class BingSearchPage : PageObject<BingSearchPage>
{
public BingSearchPage(FluentTest test)
@csharpforevermore
csharpforevermore / nullcheck.cs
Last active June 28, 2017 07:18
Null Coalescing Operator. Nullable type check - approaches
/* string - ternary */
string name;
string value;
name = value != null ? value :
/* int */
int? n = null;
...
@csharpforevermore
csharpforevermore / Program.cs
Created May 5, 2017 00:47
Convert integer of pennies into a correctly formatted string. So if the integer of pence is 1999, then the output should be "19.99".
using System;
namespace ConsoleApp2
{
class Program
{
static void Main()
{
var model = new Payment { Price = 1999 };
var modelPriceAsDecimal = ModelPriceAsDecimal(model.Price);