Skip to content

Instantly share code, notes, and snippets.

@litera
litera / Parameter checking VS code snippets.md
Last active August 29, 2015 14:05
Method parameter checking Visual Studio code snippets

Parameter checking using Code snippets

Don't write the same code over and over again and rather save these two code snippets to simplify your coding. YOu will still have the same code in your methods, but will gain two main things:

  1. You will be faster doing this as code snippet template will do majority of typing for you
  2. You won't misspell parameter name when providing its testual name to exception constructor

So until we get Visual Studio 2014 with new C# ?. operator this is the simplest way without additional code in the form of either extension methods or other things.

There are two snippets

@litera
litera / IRangeChecker.cs
Created November 22, 2011 06:52
Range data lookups using foreach loops and LINQ expressions
namespace RangeTester
{
/// <summary>
/// Defines range related members to implementing classes.
/// </summary>
/// <typeparam name="TPoint">The type of the range point.</typeparam>
public interface IRangeChecker<TPoint>
{
/// <summary>
/// Gets the range starting point.
@litera
litera / Program.cs
Created November 29, 2011 02:50
Console application conparimg Lambda implementation performance
public class Program
{
private static Random rnd = new Random();
private const int RangeLength = 365;
private const int RangeCount = 1;
private const int MaxRangeLength = 100;
private const int IterationCount = 1000000;
private const int RepeatCount = 5;
private static readonly DateTime RangeStart = new DateTime(2012, 1, 1);
@litera
litera / SQL code versioning.md
Last active March 28, 2017 15:41
SQL Database development automated scripts

Version following TSQL files

  • 00 Backup Data.sql - automated
  • 01 Drop Model.sql - automated
  • 02 Create Model.sql
  • 03 Functions.sql
  • 04 Procedures.sql
  • 05 Static Data.sql
  • 06 Test Data.sql
  • 07 Restore Data.sql - automated
@litera
litera / Augment.js
Created April 4, 2017 20:09
Slack common keyboard shortcuts
$(function() {
alert("Initializing additional Slack keyboard shortcuts.\n\nCTRL+B = bold\nCTRL+I = italic\nCTRL+S = strike through\nCTRL+P = preformatted\nCTRL+< = code");
var keys = {
b: "*",
i: "_",
"<": "`",
p: "\n```\n",
s : "~"
@litera
litera / Angular.Filter.Format.js
Created March 19, 2014 03:25
string.Format for AngularJS
/* AngularJS string.Format filter
*
* This filter provides string variable replacement similar to C# string.Format("{0}", "something");
*
* Usage: {{ "From model: {0}; and a constant: {1};" | format:model.property:"constant":...:... }}
*/
(function (angular) {
angular
@litera
litera / Mixins.scss
Created January 29, 2012 12:11
SCSS common mixins with cross browser style definitions
// Global reusable mixins
/*
* Version: 2.0 (2 Feb 2012)
*
* Copyright (c) 2011 Robert Koritnik
* Licensed under the terms of the MIT license
* http://www.opensource.org/licenses/mit-license.php
*/
@litera
litera / react.useEffectSpy.ts
Created November 25, 2022 19:41
`useEffect` that also logs which dependency change triggered it
const usePrevious = (value, initialValue) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
};
export const useEffectDebugger = (effectHook, dependencies, dependencyNames = []) => {
const previousDeps = usePrevious(dependencies, []);
@litera
litera / NPoco strong typed Stored Procedures calls T4.md
Last active June 27, 2023 11:37
NPoco/PetaPoco strong typed and named stored procedures T4 generator

NPoco/PetaPoco stored procedures with named strong type parameters

StoredProcedures.tt file automatically generates a C# code file with calsses and methods corresponding to your database stored procedure definitions. This is then used to simply call stored procedures within NPoco/PetaPoco and avoid magic strings and parameter type guessing. It also supports output parameters.

Stored procedures naming conventions

In order to have your stored procedure calls well structured there are particular yet simple naming conventions you should follow when creating your stored procedures:

  1. Name your stored procedures as ClassName_Method
  2. If a particular stored procedure shouldn't be parsed you should omit underscore character in its name; this will make it private from the perspective of your C# as it will only be accessible to other stored procedures but won't be parsed.
@litera
litera / utilityTypes.d.ts
Last active September 21, 2023 16:47
Typescript useful utility types
type Prefix<TModel extends {}, P extends string> = {
[Key in string & keyof TModel as `${P}${Capitalize<Key>}`]: TModel[Key];
}
type Suffix<TModel extends {}, S extends string> = {
[Key in string & keyof TModel as `${Key}${Capitalize<S>}`]: TMOdel[Key];
}
// EnsureProps<{}> = never
// EnsureProps<Person> = Person